Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Searching/BFS/bfs in python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# BREADTH FIRST SEARCH

def bfs(self,vertex):
visited = [vertex] # O(1)
queue = [vertex]
while queue: # O(V) ,,,v is num of vertices
deVertex = queue.pop(0)
print(deVertex)
for adjacentVertex in self.gdict[deVertex]: #O(E) ,,,E is num of edges
if adjacentVertex not in visited:
visited.append(adjacentVertex)
queue.append(adjacentVertex)
43 changes: 43 additions & 0 deletions Sorting/Bucket-Sort/BucketSort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# BOCKET SORT WITH THE HELP OF INSERTION SORT


# INSERTION SORT
def insertionSort(customList):
for i in range(1,len(customList)):
key=customList[i]
j=i-1
while j>=0 and key < customList[j]:
customList[j+1] = customList[j]
j -= 1
customList[j+1] = key
return customList


# BUCKET SORT
import math
def bucketSort(customList):
numberofBuckets = round(math.sqrt(len(customList)))
maxValue = max(customList)
arr =[]

for i in range(numberofBuckets):
arr.append([])
for j in customList:
index_b = math.ceil(j*numberofBuckets/maxValue)
arr[index_b-1].append(j)

for i in range(numberofBuckets):
arr[i] = insertionSort(arr[i])

k = 0
for i in range(numberofBuckets):
for j in range(len(arr[i])):
customList[k] = arr[i][j]
k+=1
return customList



cList=[2,1,3,6,9,7,4,8,5]
print(bucketSort(cList))