From 746851991b0393ce22d5ded3ae206f16540adb62 Mon Sep 17 00:00:00 2001 From: Hariharan Ragothaman Date: Thu, 18 Jan 2024 22:57:28 -0500 Subject: [PATCH] Updating DataStructures Recipe --- .../accumulate.py => array_accumulate.py} | 0 ..._combos.py => array_consecutive_combos.py} | 0 .../{array/flatten.py => array_flatten.py} | 0 ...r.py => array_split_based_on_delimiter.py} | 0 .../array_take_in_increasing_groups.py | 0 .../difference_array.py | 0 .../difference_array/darray_zero_idx.py | 50 ------------------- .../{dsu/dsu_template.py => dsu.py} | 1 + ..._using_dsu.py => dsu_number_of_islands.py} | 0 datastructures/{linkedlist => }/linkedlist.py | 0 .../{sortedList => }/sorted_list.py | 0 .../{sortedList => }/sorted_list_update.py | 0 datastructures/{trie => }/trie.py | 0 datastructures/{trie => }/trie2.py | 0 14 files changed, 1 insertion(+), 50 deletions(-) rename datastructures/{array/accumulate.py => array_accumulate.py} (100%) rename datastructures/{array/consecutive_combos.py => array_consecutive_combos.py} (100%) rename datastructures/{array/flatten.py => array_flatten.py} (100%) rename datastructures/{array/split_based_on_delimiter.py => array_split_based_on_delimiter.py} (100%) rename datastructures/{array => }/array_take_in_increasing_groups.py (100%) rename datastructures/{difference_array => }/difference_array.py (100%) delete mode 100644 datastructures/difference_array/darray_zero_idx.py rename datastructures/{dsu/dsu_template.py => dsu.py} (99%) rename datastructures/{dsu/number_of_islands_using_dsu.py => dsu_number_of_islands.py} (100%) rename datastructures/{linkedlist => }/linkedlist.py (100%) rename datastructures/{sortedList => }/sorted_list.py (100%) rename datastructures/{sortedList => }/sorted_list_update.py (100%) rename datastructures/{trie => }/trie.py (100%) rename datastructures/{trie => }/trie2.py (100%) diff --git a/datastructures/array/accumulate.py b/datastructures/array_accumulate.py similarity index 100% rename from datastructures/array/accumulate.py rename to datastructures/array_accumulate.py diff --git a/datastructures/array/consecutive_combos.py b/datastructures/array_consecutive_combos.py similarity index 100% rename from datastructures/array/consecutive_combos.py rename to datastructures/array_consecutive_combos.py diff --git a/datastructures/array/flatten.py b/datastructures/array_flatten.py similarity index 100% rename from datastructures/array/flatten.py rename to datastructures/array_flatten.py diff --git a/datastructures/array/split_based_on_delimiter.py b/datastructures/array_split_based_on_delimiter.py similarity index 100% rename from datastructures/array/split_based_on_delimiter.py rename to datastructures/array_split_based_on_delimiter.py diff --git a/datastructures/array/array_take_in_increasing_groups.py b/datastructures/array_take_in_increasing_groups.py similarity index 100% rename from datastructures/array/array_take_in_increasing_groups.py rename to datastructures/array_take_in_increasing_groups.py diff --git a/datastructures/difference_array/difference_array.py b/datastructures/difference_array.py similarity index 100% rename from datastructures/difference_array/difference_array.py rename to datastructures/difference_array.py diff --git a/datastructures/difference_array/darray_zero_idx.py b/datastructures/difference_array/darray_zero_idx.py deleted file mode 100644 index e13e81b..0000000 --- a/datastructures/difference_array/darray_zero_idx.py +++ /dev/null @@ -1,50 +0,0 @@ - -A = [5, 4, 1, 2, 3] -print(A) -n = len(A) - -# Creating a difference array -diff = [0] * (n+2) -print(diff) - -for i in range(n): - if i == 0: - diff[i] = A[i] - else: - diff[i] = A[i] - A[i-1] - -print("The difference aray is:") -print(diff) - - -# Now let's say I want to add "X" on all elements between index L & R -""" -for i in range(L, R+1): - A[i] += X -""" - -""" -Let's assume there is only 1 query -Let's assume L = 1 and R = 3 -""" -L = 1 -R = 3 -X = 5 - -diff[L] += X -diff[R+1] -= X - -print("The updated difference array is:") -print(diff) - -""" -Finally update the the original array based on diff -""" -for i in range(n): - if i == 0: - A[i] = diff[i] - else: - A[i] = diff[i] + A[i-1] - -print("The updated array after querying is:") -print(A) \ No newline at end of file diff --git a/datastructures/dsu/dsu_template.py b/datastructures/dsu.py similarity index 99% rename from datastructures/dsu/dsu_template.py rename to datastructures/dsu.py index 387400e..ee430fa 100644 --- a/datastructures/dsu/dsu_template.py +++ b/datastructures/dsu.py @@ -11,6 +11,7 @@ """ +from typing import List class DisJointSets: def __init__(self, size: int) -> None: diff --git a/datastructures/dsu/number_of_islands_using_dsu.py b/datastructures/dsu_number_of_islands.py similarity index 100% rename from datastructures/dsu/number_of_islands_using_dsu.py rename to datastructures/dsu_number_of_islands.py diff --git a/datastructures/linkedlist/linkedlist.py b/datastructures/linkedlist.py similarity index 100% rename from datastructures/linkedlist/linkedlist.py rename to datastructures/linkedlist.py diff --git a/datastructures/sortedList/sorted_list.py b/datastructures/sorted_list.py similarity index 100% rename from datastructures/sortedList/sorted_list.py rename to datastructures/sorted_list.py diff --git a/datastructures/sortedList/sorted_list_update.py b/datastructures/sorted_list_update.py similarity index 100% rename from datastructures/sortedList/sorted_list_update.py rename to datastructures/sorted_list_update.py diff --git a/datastructures/trie/trie.py b/datastructures/trie.py similarity index 100% rename from datastructures/trie/trie.py rename to datastructures/trie.py diff --git a/datastructures/trie/trie2.py b/datastructures/trie2.py similarity index 100% rename from datastructures/trie/trie2.py rename to datastructures/trie2.py