From f3305bc4c55f02c69e1d03f50be0472bb30f6d89 Mon Sep 17 00:00:00 2001 From: Prabhu Pant Date: Mon, 1 Apr 2024 19:33:02 +0530 Subject: [PATCH 1/5] Fix infinite array search --- data_structures/array/binary_search_infinite_array.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/array/binary_search_infinite_array.py b/data_structures/array/binary_search_infinite_array.py index 6eff9207..1db83e07 100644 --- a/data_structures/array/binary_search_infinite_array.py +++ b/data_structures/array/binary_search_infinite_array.py @@ -23,7 +23,7 @@ def search(arr, val): high = 1 while temp < val: - low = 0 + low = high high = 2 * high temp = arr[high] From f17ce1b59f23feb58778491151b095c4c52e6013 Mon Sep 17 00:00:00 2001 From: Prabhu Pant Date: Tue, 2 Apr 2024 11:06:54 +0530 Subject: [PATCH 2/5] Some fixes --- data_structures/array/duplicate.py | 12 ++++++------ data_structures/array/find_given_sum_in_array.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/data_structures/array/duplicate.py b/data_structures/array/duplicate.py index 1e4f6291..4838b1aa 100644 --- a/data_structures/array/duplicate.py +++ b/data_structures/array/duplicate.py @@ -17,13 +17,13 @@ def duplicate(arr): if tortoise == hare: break - ptr1 = arr[0] - ptr2 = tortoise - while ptr1 != ptr2: - ptr1 = arr[ptr1] - ptr2 = arr[ptr2] + tortoise = arr[0] + + while tortoise != hare: + tortoise = arr[tortoise] + hare = arr[hare] - return ptr1 + return hare arr = [3,5,1,2,4,5] diff --git a/data_structures/array/find_given_sum_in_array.py b/data_structures/array/find_given_sum_in_array.py index 0aacc5b4..e3adcfcb 100644 --- a/data_structures/array/find_given_sum_in_array.py +++ b/data_structures/array/find_given_sum_in_array.py @@ -24,4 +24,4 @@ def find_sum(arr, s): arr = [15, 2, 4, 8, 9, 5, 10, 23] -print(find_sum(arr, 6)) +print(find_sum(arr, 6)) \ No newline at end of file From ef23195057a1721eea41d39e0bdbd4c52b5640ea Mon Sep 17 00:00:00 2001 From: Prabhu Pant Date: Tue, 2 Apr 2024 15:49:12 +0530 Subject: [PATCH 3/5] Small fixes --- data_structures/array/peak_element.py | 3 +-- data_structures/array/square_of_sorted_array.py | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/data_structures/array/peak_element.py b/data_structures/array/peak_element.py index 29d8b1f2..ded661b0 100644 --- a/data_structures/array/peak_element.py +++ b/data_structures/array/peak_element.py @@ -6,8 +6,7 @@ def peak(arr, low, high): n = len(arr) while low <= high: - mid = low + (high - low) / 2 - mid = int(mid) + mid = (high - low) // 2 if (mid == 0 or arr[mid-1] <= arr[mid]) and (mid == n-1 or arr[mid+1] <= arr[mid]): return(arr[mid]) diff --git a/data_structures/array/square_of_sorted_array.py b/data_structures/array/square_of_sorted_array.py index 1bebb758..68f196b9 100644 --- a/data_structures/array/square_of_sorted_array.py +++ b/data_structures/array/square_of_sorted_array.py @@ -1,3 +1,8 @@ +""" +Find the square of all the numbers of a sorted array such that after finding the square of the sorted array, the +resultant array containing the squared numbers remains sorted +""" + def square(arr): n = len(arr) j = 0 From 27124b9b77a18a2d3e89c262311286a1d9c2910c Mon Sep 17 00:00:00 2001 From: Prabhu Pant Date: Fri, 5 Apr 2024 15:51:52 +0530 Subject: [PATCH 4/5] Convert camelCase to snake_case --- data_structures/deque/deque.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data_structures/deque/deque.py b/data_structures/deque/deque.py index d578c8e2..85c7dd2c 100644 --- a/data_structures/deque/deque.py +++ b/data_structures/deque/deque.py @@ -47,7 +47,7 @@ def get_last(self): def size(self): return len(self.data) - def isEmpty(self): + def is_empty(self): if len(self.data) == 0: return True return False @@ -59,7 +59,7 @@ def contains(self, elem): return False - def printElems(self): + def print_elements(self): result = "" for i in self.data: From 35d3556a992ceccc5b925afa892fae3ba01a0e81 Mon Sep 17 00:00:00 2001 From: Prabhu Pant Date: Sat, 6 Apr 2024 13:13:16 +0530 Subject: [PATCH 5/5] Add comments --- data_structures/linked_list/delete_last_occurrence.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/data_structures/linked_list/delete_last_occurrence.py b/data_structures/linked_list/delete_last_occurrence.py index e76f1d9a..80951ab0 100644 --- a/data_structures/linked_list/delete_last_occurrence.py +++ b/data_structures/linked_list/delete_last_occurrence.py @@ -1,3 +1,7 @@ +""" +Delete last occurence of a number in linked list. +""" + class Node(): def __init__(self, val):