Skip to content

Commit db5b84e

Browse files
committed
Major Re-Structuring Phase - 1 (Part - B)
* Organizes all the files into categories and updates the index in the root readme files * need to create a contributing file and docker container for any testing of these algorithms
1 parent 46f41ba commit db5b84e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+194
-270
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Binary Search
2+
def bina(l,low,high,a) :
3+
mid=(low+high)//2
4+
if low>high :
5+
return False
6+
elif a<l[mid] :
7+
return(bina(l,low,mid-1,a))
8+
elif a>l[mid] :
9+
return(bina(l,low+1,high,a))
10+
elif a==l[mid] :
11+
return True
12+
n=int(input())
13+
l=[]
14+
for i in range(n) :
15+
l.append(int(input()))
16+
l.sort()
17+
b=int(input())
18+
print(bina(l,0,len(l)-1,b))
File renamed without changes.
File renamed without changes.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#%%
2+
3+
# Version 1 :
4+
5+
6+
def heapify(arr, n, i) :
7+
l = 2*i + 1
8+
r = 2*i + 2
9+
largest = i
10+
11+
if l<n and arr[largest]<arr[l] :
12+
largest = l
13+
if r<n and arr[largest]<arr[r] :
14+
largest = r
15+
16+
if largest!=i :
17+
arr[largest], arr[i] = arr[i], arr[largest]
18+
heapify(arr, n, largest)
19+
20+
21+
def heap_sort(arr) :
22+
n = len(arr)
23+
24+
for i in range(n, -1, -1) :
25+
heapify(arr, n, i)
26+
27+
for i in range(n-1, 0, -1) :
28+
arr[0], arr[i] = arr[i], arr[0]
29+
heapify(arr, i, 0)
30+
31+
s = input()
32+
s = s.split(' ')
33+
arr = [int(i) for i in s]
34+
heap_sort(arr)
35+
print(arr)
36+
37+
38+
39+
#%%
40+
41+
# Version 2
42+
43+
44+
def heapify(arr, i) :
45+
n = len(arr)
46+
l = 2*i + 1
47+
r = 2*i + 2
48+
largest = i
49+
50+
if l<n and arr[largest]<arr[l] :
51+
largest = l
52+
if r<n and arr[largest]<arr[r] :
53+
largest = r
54+
55+
if largest!=i :
56+
arr[largest], arr[i] = arr[i], arr[largest]
57+
heapify(arr, largest)
58+
59+
60+
def heap_sort(arr) :
61+
n = len(arr)
62+
63+
for i in range(n, -1, -1) :
64+
heapify(arr, i)
65+
66+
arr1 = arr[:]
67+
arr = []
68+
69+
for i in range(n-1, 0, -1) :
70+
arr1[0], arr1[i] = arr1[i], arr1[0]
71+
arr.append(arr1[i])
72+
arr1 = arr1[:i]
73+
heapify(arr1, 0)
74+
75+
arr = arr + arr1
76+
arr.reverse()
77+
return(arr)
78+
79+
s = input()
80+
s = s.split(' ')
81+
arr = [int(i) for i in s]
82+
arr = heap_sort(arr)
83+
print(arr)
File renamed without changes.

0 commit comments

Comments
 (0)