Skip to content

Commit 2c14344

Browse files
Aniket965jainaman224
authored andcommitted
* issue solved jainaman224#400 * solving issue#400 * solving jainaman224#400 * solved issue jainaman224#400 * issue solved jainaman224#400
1 parent 36e0996 commit 2c14344

File tree

18 files changed

+239
-239
lines changed

18 files changed

+239
-239
lines changed

Binary_Search/Binary_Search.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
# Function for Binary Search
2-
def Binary_Search(array, desired):
2+
def Binary_Search(list, desired):
33
left = 0
4-
right = len(array) - 1
4+
right = len(list) - 1
55

66
while left <= right:
77
# Return positon if found
88
middle = left + int((right - left) / 2)
99

10-
if array[middle] == desired:
10+
if list[middle] == desired:
1111
return middle
12-
elif desired < array[middle]:
12+
elif desired < list[middle]:
1313
right = middle - 1
14-
elif desired > array[middle]:
14+
elif desired > list[middle]:
1515
left = middle + 1
1616

1717
return -1
1818

19-
array = [1, 2, 3, 4, 5, 6, 7]
19+
list = [1, 2, 3, 4, 5, 6, 7]
2020

2121
# Element to be searched is 4
22-
print ("Found") if Binary_Search(array, 4) != -1 else ("Not Found")
22+
print ("Found") if Binary_Search(list, 4) != -1 else ("Not Found")
2323

2424
# Element to be searched is 9
25-
print ("Found") if Binary_Search(array, 9) != -1 else ("Not Found")
25+
print ("Found") if Binary_Search(list, 9) != -1 else ("Not Found")
2626

2727

2828
''' Output

Bubble_Sort/Bubble_Sort.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
# function for bubble sort
2-
def Bubble_Sort(array):
3-
for i in range(0, len(array) - 1):
4-
for j in range(0, len(array) - i - 1):
2+
def Bubble_Sort(list):
3+
for i in range(0, len(list) - 1):
4+
for j in range(0, len(list) - i - 1):
55
# do swapping
6-
if array[j] > array[j + 1]:
7-
array[j], array[j + 1] = array[j + 1], array[j]
6+
if list[j] > list[j + 1]:
7+
list[j], list[j + 1] = list[j + 1], list[j]
88

9-
# function to print array
10-
def Print_Array(array):
11-
for i in range(0, len(array)):
12-
print(array[i], end = " ")
9+
# function to print list
10+
def Print_list(list):
11+
for i in range(0, len(list)):
12+
print(list[i], end = " ")
1313

1414
print()
1515

16-
array = [2, 4, 3, 1, 6, 8, 4]
16+
list = [2, 4, 3, 1, 6, 8, 4]
1717

18-
Bubble_Sort(array)
18+
Bubble_Sort(list)
1919

20-
Print_Array(array)
20+
Print_list(list)
2121

2222
# Output
2323
# 1 2 3 4 4 6 8

Counting_Sort/Counting_Sort.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ def counting_sort(input):
1111

1212
k = max - min + 1
1313

14-
count_array = [0] * k
14+
count_list = [0] * k
1515

1616
for i in range(0, len(input)):
17-
count_array[input[i] - min] += 1
17+
count_list[input[i] - min] += 1
1818

1919
for i in range(1, k):
20-
count_array[i] += count_array[i - 1]
20+
count_list[i] += count_list[i - 1]
2121

2222
for i in range(0, len(input)):
23-
output[count_array[input[i] - min] - 1] = input[i]
24-
count_array[input[i] - min] -= 1
23+
output[count_list[input[i] - min] - 1] = input[i]
24+
count_list[input[i] - min] -= 1
2525

2626
for i in range(0, len(input)):
2727
input[i] = output[i]
@@ -31,13 +31,13 @@ def counting_sort(input):
3131

3232
counting_sort(input)
3333

34-
print("Sorted array :", end = " ")
34+
print("Sorted list :", end = " ")
3535
for i in range(0, len(input)):
3636
print(input[i], end = " ")
3737

3838

3939
''' Output
4040
41-
Sorted Array : 1 1 2 3 4 4 5 5 7
41+
Sorted list : 1 1 2 3 4 4 5 5 7
4242
4343
'''

Heap_Sort/Heap_Sort.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
def Heapify(array, root, size):
1+
def Heapify(list, root, size):
22
left = 2 * root + 1
33
right = left + 1
4-
if left < size and array[left] > array[root]:
4+
if left < size and list[left] > list[root]:
55
largest = left
66
else:
77
largest = root
88

9-
if right < size and array[right] > array[largest]:
9+
if right < size and list[right] > list[largest]:
1010
largest = right
1111

1212
if largest != root:
13-
array[root], array[largest] = array[largest], array[root]
14-
Heapify(array, largest, size)
13+
list[root], list[largest] = list[largest], list[root]
14+
Heapify(list, largest, size)
1515

1616

17-
def Build_Heap(array):
18-
for i in range(int((len(array) - 1) / 2), -1, -1):
19-
Heapify(array, i, len(array))
17+
def Build_Heap(list):
18+
for i in range(int((len(list) - 1) / 2), -1, -1):
19+
Heapify(list, i, len(list))
2020

21-
def Heap_Sort(array):
22-
Build_Heap(array)
21+
def Heap_Sort(list):
22+
Build_Heap(list)
2323

24-
for i in range(len(array) - 1, 0, -1):
25-
array[0], array[i] = array[i], array[0]
26-
Heapify(array, 0, i)
24+
for i in range(len(list) - 1, 0, -1):
25+
list[0], list[i] = list[i], list[0]
26+
Heapify(list, 0, i)
2727

28-
# function to print array
29-
def Print_Array(array):
30-
for i in range(0, len(array)):
31-
print(array[i],end=" ")
28+
# function to print list
29+
def Print_list(list):
30+
for i in range(0, len(list)):
31+
print(list[i],end=" ")
3232

3333
print()
3434

35-
array = [2, 4, 3, 1, 6, 8, 4]
35+
list = [2, 4, 3, 1, 6, 8, 4]
3636

37-
Heap_Sort(array)
37+
Heap_Sort(list)
3838

39-
Print_Array(array)
39+
Print_list(list)
4040

4141
# Output
4242
# 1 2 3 4 4 6 8

Insertion_Sort/Insertion_Sort.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
# function for insertion sort
2-
def Insertion_Sort(array):
3-
for i in range(1, len(array)):
4-
temp = array[i]
2+
def Insertion_Sort(list):
3+
for i in range(1, len(list)):
4+
temp = list[i]
55
j = i - 1
66

7-
while j >= 0 and array[j] > temp:
8-
array[j + 1] = array[j]
7+
while j >= 0 and list[j] > temp:
8+
list[j + 1] = list[j]
99
j -= 1
1010

11-
array[j + 1] = temp
11+
list[j + 1] = temp
1212

13-
# function to print array
14-
def Print_Array(array):
15-
for i in range(0, len(array)):
16-
print(array[i],end=" ")
13+
# function to print list
14+
def Print_list(list):
15+
for i in range(0, len(list)):
16+
print(list[i],end=" ")
1717

1818
print()
1919

20-
array = [2, 4, 3, 1, 6, 8, 4]
20+
list = [2, 4, 3, 1, 6, 8, 4]
2121

22-
Insertion_Sort(array)
22+
Insertion_Sort(list)
2323

24-
Print_Array(array)
24+
Print_list(list)
2525

2626
# Output
2727
# 1 2 3 4 4 6 8

Interpolation_Search/Interpolation_Search.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
def interpolation(array, search_item):
2-
high = len(array) - 1
1+
def interpolation(list, search_item):
2+
high = len(list) - 1
33
low = 0
44

5-
while low <= high and search_item >= array[low] and search_item <= array[high]:
5+
while low <= high and search_item >= list[low] and search_item <= list[high]:
66
rise = high - low
7-
run = array[high] - array[low]
8-
x = search_item - array[low]
7+
run = list[high] - list[low]
8+
x = search_item - list[low]
99
pos = low + int(rise / run) * x;
1010

11-
if array[pos] == search_item:
11+
if list[pos] == search_item:
1212
return pos
13-
elif search_item < array[pos]:
13+
elif search_item < list[pos]:
1414
high = pos - 1
1515
else:
1616
low = pos + 1
1717

1818
return -1
1919

20-
array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
20+
list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
2121
search_item = 8
22-
index = interpolation(array, search_item)
22+
index = interpolation(list, search_item)
2323

2424
if index == -1:
2525
print("Element not found")

Kadane_Algorithm/Kadane_Algorithm.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ def kadane(input):
2525
largest_in_negative = input[i]
2626

2727
if flag == 1:
28-
max_subarray_sum = kadane(input)
28+
max_sublist_sum = kadane(input)
2929
else:
30-
max_subarray_sum = largest_in_negative
30+
max_sublist_sum = largest_in_negative
3131

32-
print("Maximum Subarray Sum is " + str(max_subarray_sum))
32+
print("Maximum Sublist Sum is " + str(max_sublist_sum))
3333

3434

3535
''' Output
3636
37-
Maximum Subarray Sum is 6
37+
Maximum Sublist Sum is 6
3838
3939
'''

Linear_Search/Linear_Search.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# Function for Linear Search
2-
def Linear_Search(array, desired):
3-
for i in range(0, len(array)):
2+
def Linear_Search(list, desired):
3+
for i in range(0, len(list)):
44
# return positon if found
5-
if(array[i] == desired):
5+
if(list[i] == desired):
66
return i
77

88
return -1
99

10-
array = [2, 4, 6, 7, 3, 1, 5]
10+
list = [2, 4, 6, 7, 3, 1, 5]
1111

1212
# Element to be searched is 4
13-
if(Linear_Search(array,4) != -1):
13+
if(Linear_Search(list,4) != -1):
1414
print("Found")
1515
else:
1616
print("Not Found")
1717

1818
# Element to be searched is 9
19-
if(Linear_Search(array,9) != -1):
19+
if(Linear_Search(list,9) != -1):
2020
print("Found")
2121
else:
2222
print("Not Found")

Merge_Sort/Merge_Sort.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
11
# Conquer
2-
def conquer_merge(array, left, right, mid):
3-
#temp = [None] * len(array)
2+
def conquer_merge(list, left, right, mid):
3+
#temp = [None] * len(list)
44
i = left
55
j = mid + 1
66
k = left
77

88
while i <= mid and j <= right:
9-
if array[i] <= array[j]:
10-
temp[k] = array[i]
9+
if list[i] <= list[j]:
10+
temp[k] = list[i]
1111
i += 1
1212
else:
13-
temp[k] = array[j]
13+
temp[k] = list[j]
1414
j += 1
1515

1616
k += 1
1717

1818
while i <= mid:
19-
temp[k] = array[i]
19+
temp[k] = list[i]
2020
i += 1
2121
k += 1
2222

2323
while j <= right:
24-
temp[k] = array[j]
24+
temp[k] = list[j]
2525
j += 1
2626
k += 1
2727

2828
while left <= right:
29-
array[left] = temp[left]
29+
list[left] = temp[left]
3030
left += 1
3131

32-
# Divide array into halves
33-
def divide(array, left, right):
32+
# Divide list into halves
33+
def divide(list, left, right):
3434
if left < right:
3535
mid = left + (right - left) / 2;
3636
mid = int(mid)
3737

38-
divide(array, left, mid)
39-
divide(array, mid + 1, right)
38+
divide(list, left, mid)
39+
divide(list, mid + 1, right)
4040

41-
conquer_merge(array, left, right, mid)
41+
conquer_merge(list, left, right, mid)
4242

43-
def Merge_Sort(array):
43+
def Merge_Sort(list):
4444
global temp
45-
temp = [0] * len(array)
46-
divide(array, 0, len(array) - 1)
45+
temp = [0] * len(list)
46+
divide(list, 0, len(list) - 1)
4747
del temp
4848

49-
# function to print array
50-
def Print_Array(array):
51-
for i in range(0, len(array)):
52-
print(array[i],end=" ")
49+
# function to print list
50+
def Print_list(list):
51+
for i in range(0, len(list)):
52+
print(list[i],end=" ")
5353

5454
print()
5555

56-
array = [2, 4, 3, 1, 6, 8, 4]
56+
list = [2, 4, 3, 1, 6, 8, 4]
5757

58-
Merge_Sort(array)
58+
Merge_Sort(list)
5959

60-
Print_Array(array)
60+
Print_list(list)
6161

6262
# Output
6363
# 1 2 3 4 4 6 8

0 commit comments

Comments
 (0)