forked from SushmitaY/mca101_2017
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9.MinimumOfSublist.py
More file actions
34 lines (26 loc) · 1.55 KB
/
9.MinimumOfSublist.py
File metadata and controls
34 lines (26 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def findMinimumIndex(lst, i, upper, i_min = none ):
'''
objective: to find the index of minimum element of the given list
parameters: lst -> the list in which the the index of the minimum element is to be found according to lower and upper bound
upper -> stores the index of the upper bound
i -> i is an iterative value that is used to traverse the list from lower bound to upper bound
i_min -> stores the index of the minimum element of the sublist
return value: the index of the minimum element of the sublist
'''
# Approach : comparing the element at index i against the element at index i_min. If lst[i] < lst[i_min] is encountered, i_min is updated with value of i.
if i_min == none:
i_min = lower
if i == upper + 1:
return i_min
if lst[i] < lst[i_min] :
i_min = i
i = i + 1
return findMinimumIndex(lst, i, upper, i_min)
#--------------------------------TEST CASES---------------------------------------------------------------------------------------
lst1 = [10, 20, 5, 40, 27, 30, 45, 80, 43, 12, 9]
print(lst1)
print( "Minimum index of sublist ",lst1[4:10]," is = ", findMinimum(lst1, 4, 9) )
print( "Minimum index of sublist ",lst1[0:11]," is = ", findMinimum(lst1, 0, 10) )
print( "Minimum index of sublist ",lst1[3:8]," is = ", findMinimum(lst1, 3, 7) )
print( "Minimum index of sublist ",lst1[2:10]," is = ", findMinimum(lst1, 2, 9) )
print( "Minimum index of sublist ",lst1[7:9]," is = ", findMinimum(lst1, 7, 8) )