-
Notifications
You must be signed in to change notification settings - Fork 2
/
find_min_index.py
36 lines (30 loc) · 1021 Bytes
/
find_min_index.py
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
35
36
def minOfList(lst, start=0, end=1):
'''
objective: to find index of minimum element in the list passed to this function
parameters: -> lst: list whose minimum has to be found
-> start: starting index from where min has to be calculated
-> end: last index upto which min has to be calculated
return value: index of smallest element of the list
'''
'approach: updating min_element using comparision in recursion and returning its index after traversing completely'
'''
if i == 0:
i = start
j = start
if i == (end+1):
return j
else:
if lst[i] < lst[j]:
min_element = lst[i]
j = i
i = i+1
return minOfList(lst,start, end, i, j)
'''
if end == len(lst)-1:
return start
elif lst[end] > lst[start]:
return minOfList(lst, start, end+1)
else:
return minOfList(lst, end, end+1)
lst = [50,10,30,40,100,0,90]
print(minOfList(lst))