From 24bd0fc58be12cf64923de2a31cde55181019292 Mon Sep 17 00:00:00 2001 From: divyaa1511 <102688183+divyaa1511@users.noreply.github.com> Date: Sun, 16 Oct 2022 16:04:36 +0530 Subject: [PATCH 1/2] BucketSort in python --- Sorting/Bucket-Sort/BucketSort.py | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Sorting/Bucket-Sort/BucketSort.py diff --git a/Sorting/Bucket-Sort/BucketSort.py b/Sorting/Bucket-Sort/BucketSort.py new file mode 100644 index 0000000..3be461f --- /dev/null +++ b/Sorting/Bucket-Sort/BucketSort.py @@ -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)) + From 58857d70c62395c70523cc28c18704cb6c9d2e05 Mon Sep 17 00:00:00 2001 From: divyaa1511 <102688183+divyaa1511@users.noreply.github.com> Date: Sun, 16 Oct 2022 16:10:52 +0530 Subject: [PATCH 2/2] bfs in python --- Searching/BFS/bfs in python.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Searching/BFS/bfs in python.py diff --git a/Searching/BFS/bfs in python.py b/Searching/BFS/bfs in python.py new file mode 100644 index 0000000..5caf044 --- /dev/null +++ b/Searching/BFS/bfs in python.py @@ -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) \ No newline at end of file