Skip to content

Commit 6f62b92

Browse files
committed
bulk pending commits pushed
1 parent 3bf4eee commit 6f62b92

35 files changed

+540
-246
lines changed

algorithm_and_datastructure/graphs/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
g.add_edge(2, 3)
1010
# g.display()
1111

12-
print(g.bfs(g,0))
12+
print("bfs traverse", g.bfs(g,0))
1313
#####################
1414

1515
g = gf.Graph(7)

algorithm_and_datastructure/hashing/data_loader.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import random
22
import uuid
3-
# import algorithm.hashing.my_hash_table.MyHashTable as mh
4-
import my_hash_table as mh
3+
import algorithm_and_datastructure.hashing.my_hash_table as mh
54

65
days = ["Monday", "Tuesday", "Wednesday", "Sunday"]
76
domains = ["gmail.com", "yahoo.com", "sexy.com"]
@@ -32,7 +31,7 @@ def read_and_load(f):
3231
for line in lines:
3332
k,v = line.split(":")
3433
print("setting kv", k,v)
35-
o.set_value(k,v)
34+
o.set_value(k,v,"abc","xyz")
3635
print(o.get_value("prem@gmail.com"))
3736

3837

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# hashing with resizing
2+
3+
4+
5+
class HashTable:
6+
def __init__(self,size):
7+
self.buckets = []

algorithm_and_datastructure/hashing/my_hash_table.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ def delete_value(self, key):
5656
print(o.get_value("prem@gmail.com"))
5757
print(o.delete_value("prem@gmail.com"))
5858
print("get after delete")
59-
print(o.get_value("prem@gmail.com"))
59+
print(o.get_value("sony@gmail.com"))

algorithm/recursion/reverse_string.py algorithm_and_datastructure/recursion/reverse_string.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
def recure(var):
2-
if len(var == 0):
2+
if len(var) == 0:
33
return ""
44
return var[-1] + recure(var[:-1])
55

algorithm_and_datastructure/search/binary_search_iter.py

-27
This file was deleted.

algorithm_and_datastructure/search/binary_search_rec.py

-35
This file was deleted.

algorithm_and_datastructure/sorting/bubble_sort1.py

-18
This file was deleted.

algorithm_and_datastructure/sorting/bubble_sort2.py

-18
This file was deleted.

algorithm_and_datastructure/sorting/insertion_sort.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
Like Selection Sort, this algorithm segments the list into sorted and unsorted parts.
3+
It iterates over the unsorted segment, and inserts the element being viewed into the correct position of the sorted list.
4+
"""
5+
16
def insertion_sort(nums):
27
# Start on the second element as we assume the first element is sorted
38
for i in range(1, len(nums)):

algorithm_and_datastructure/sorting/insertion_sort1.py

-19
This file was deleted.

algorithm_and_datastructure/sorting/insertion_sort2.py

-11
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
Returns sorted list of integers using Quicksort
3+
Input: Unsorted list of integers
4+
Note: This is not an in-place implementation
5+
"""
6+
7+
l = [10, 9, 4, 7, 2, 4]
8+
# l = [1,2,3,4,5]
9+
e = [2, 4, 4, 7, 9, 10]
10+
11+
12+
def quick_sort(array):
13+
"""Sort the array by using quicksort."""
14+
15+
less = []
16+
equal = []
17+
greater = []
18+
19+
if len(array) > 1:
20+
pivot = array[0]
21+
for x in array:
22+
if x < pivot:
23+
less.append(x)
24+
elif x == pivot:
25+
equal.append(x)
26+
elif x > pivot:
27+
greater.append(x)
28+
# Don't forget to return something!
29+
return quick_sort(less)+equal+quick_sort(greater) # Just use the + operator to join lists
30+
# Note that you want equal ^^^^^ not pivot
31+
else: # You need to handle the part at the end of the recursion - when you only have one element in your array, just return the array.
32+
return array
33+
34+
l = quick_sort(l)
35+
print("Is sorted properly", e == l)

algorithm_and_datastructure/sorting/quick_sort1.py

-27
This file was deleted.

algorithm_and_datastructure/sorting/selection_sort1.py

-12
This file was deleted.

algorithm_and_datastructure/sorting/selection_sort2.py

-17
This file was deleted.

challenge/array/merge_sorted_lists.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
def merge_lists(l1,l2):
5-
sl = [0]
5+
sl = []
66
while l1 and l2:
77
if l1[0] <= l2[0]:
88
sl.append(l1.pop(0))
@@ -12,7 +12,7 @@ def merge_lists(l1,l2):
1212
sl.extend(l1)
1313
if l2:
1414
sl.extend(l2)
15-
return sl[1:]
15+
return sl
1616

1717

1818
l1 = [2,4,6,8]
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Implement a function that merges two sorted lists of m and n elements respectively, into another sorted list. Name it merge_lists(lst1, lst2).
2+
3+
4+
def merge_lists(l1, l2):
5+
sl = []
6+
while l1 and l2:
7+
l1e = min(l1)
8+
l2e = min(l2)
9+
10+
if l1e < l2e :
11+
sl.append(l1e)
12+
l1.remove(l1e)
13+
else:
14+
sl.append(l2e)
15+
l2.remove(l2e)
16+
17+
if l1:
18+
sl.extend(l1)
19+
if l2:
20+
sl.extend(l2)
21+
return sl
22+
23+
24+
25+
26+
l1 = [10,76,100,2,4,6,8]
27+
l2 = [3,5,7,8,9]
28+
print(merge_lists(l1,l2))
29+
30+
###################
31+
# In place merge list
32+
def divide(l):
33+
if len(l) <= 1 :
34+
return l[:]
35+
m = len(l) // 2
36+
37+
l1 = divide(l[:m])
38+
l2 = divide(l[m:])
39+
40+
return merge_lists(l1,l2)
41+
42+
print(divide([4,2,6,8,1,90,54,23]))
43+
# merge - divide in l and r
44+
45+
46+
l1 = [2,4,6,8]
47+
l2 = [3,5,7,8,9]
48+
# print(merge_lists_inplace(l1,l2))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
t = 300
2+
3+
def sqr(n):
4+
l = 1
5+
h = 25
6+
while l<h:
7+
print(l,h)
8+
mid = (l + h) // 2
9+
sqr = mid * mid
10+
if sqr <= n:
11+
l += 1
12+
else:
13+
h -= 1
14+
return l - 1
15+
16+
k = 300
17+
print(sqr(k))
18+
19+
20+
21+
22+
23+

0 commit comments

Comments
 (0)