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
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions Arrays/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ This directory contains Python implementations of common array-based algorithms

## Contents

- [Anagram Check (Sorted Solution)](Anagram_Check_Sorted_Sol.py): Checks if two strings are anagrams by comparing their sorted versions.
- [Anagram Check (Manual Solution)](Anagram_Check_manual_Sol.py): Checks if two strings are anagrams using a hash table (dictionary) to count character frequencies.
- [Array Find Missing Element (XOR Solution)](ArrayFindTheMissingElement_XOR_sol.py): Efficiently finds a missing element in a shuffled array using bitwise XOR.
- [Array Find Missing Element (Brute Force Solution)](ArrayFindTheMissingElement_brute_force_sol.py): Finds a missing element by sorting both arrays and comparing them.
- [Array Find Missing Element (Hash Table Solution)](ArrayFindTheMissingElement_hash_table_sol.py): Finds a missing element using a hash table (dictionary) to track element counts.
- [Array Find Missing Element (Sum/Subtract Solution)](ArrayFindTheMissingElement_takingSumandSubtract_sol.py): Finds a missing element by calculating the difference between the sums of the two arrays.
- [Anagram Check (Sorted Solution)](AnagramCheckSortedSol.py): Checks if two strings are anagrams by comparing their sorted versions. $O(n \log n)$
- [Anagram Check (Manual Solution)](AnagramCheckManualSol.py): Checks if two strings are anagrams using a hash table (dictionary) to count character frequencies. $O(n)$
- [Array Find Missing Element (XOR Solution)](ArrayFindTheMissingElementXORSol.py): Efficiently finds a missing element in a shuffled array using bitwise XOR. $O(n)$ time, $O(1)$ space.
- [Array Find Missing Element (Brute Force Solution)](ArrayFindTheMissingElementBruteForceSol.py): Finds a missing element by sorting both arrays and comparing them. $O(n \log n)$
- [Array Find Missing Element (Hash Table Solution)](ArrayFindTheMissingElementHashTableSol.py): Finds a missing element using a hash table (dictionary) to track element counts. $O(n)$
- [Array Find Missing Element (Sum/Subtract Solution)](ArrayFindTheMissingElementSumSol.py): Finds a missing element by calculating the difference between the sums of the two arrays. $O(n)$
- [Array Pair Sum Solution](ArrayPairSumSol.py): Finds all unique pairs in an array that sum up to a specific value $k$ using a set for $O(n)$ complexity.
File renamed without changes.
2 changes: 1 addition & 1 deletion deque/README.md → Deque/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ This directory contains Python implementations of the Deque (Double-Ended Queue)

## Contents

- [Deque Implementation](DequeImple.py): Basic implementation of a Deque using a Python list. Includes operations like `addFront`, `addRear`, `removeFront`, `removeRear`, `isEmpty`, and `size`.
- [Deque Implementation](DequeImple.py): Basic implementation of a Deque using a Python list. Includes operations like `addFront`, `addRear`, `removeFront`, `removeRear`, `isEmpty`, and `size`. Time complexity: `addFront`/`removeFront` $O(1)$, `addRear`/`removeRear` $O(n)$ due to list shifting.
7 changes: 0 additions & 7 deletions Error-debug/README.md

This file was deleted.

File renamed without changes.
7 changes: 7 additions & 0 deletions ErrorHandling/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Error Handling

This directory contains examples demonstrating error handling and debugging in Python.

## Contents

- [Error and Exceptions](ErrorExceptions.py): Demonstrates `try`, `except`, `else`, and `finally` blocks for robust error handling.
14 changes: 7 additions & 7 deletions GraphAlgorithms/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Graph Algorithms

This directory contains Python implementations of common graph-based algorithms and data structures.
This directory contains Python implementations of common graph algorithms.

## Contents

- [Adjacency List Implementation](AdjacencyListGraphImple.py): Implements the Graph Abstract Data Type (ADT) using an adjacency list (dictionaries in Python). Includes `Vertex` and `Graph` classes.
- [Breadth First Search (BFS)](BFS.py): Implements BFS to solve the Word Ladder problem, finding the shortest transformation path between words.
- [General Depth First Search (DFS)](DFSGeneral.py): Provides a general implementation of DFS, including discovery and finish times for vertices.
- [DFS - Knight's Tour Problem](DFSImpleTheKnightsTourProblem.py): Another implementation of DFS specifically tailored to the Knight's Tour puzzle.
- [The Knight's Tour Problem](TheKnightsTourProblem.py): Focuses on generating the knight's move graph and solving the tour using DFS and backtracking.
- [Word Ladder Problem](WordLadderProblem.py): Specifically focuses on building the word ladder graph where edges connect words that differ by only one letter.
- [Adjacency List Graph Implementation](AdjacencyListGraphImple.py): Implementation of the Graph Abstract Data Type using an adjacency list.
- [Breadth First Search (BFS)](BFS.py): Implementation of BFS, applied to the Word Ladder problem. $O(V+E)$
- [Depth First Search (DFS)](DFSGeneral.py): General implementation of Depth First Search. $O(V+E)$
- [The Knight's Tour Problem (Graph Generation)](TheKnightsTourProblem.py): Building a graph representing all possible legal moves on a chessboard.
- [The Knight's Tour Problem (DFS Solution)](DFSImpleTheKnightsTourProblem.py): Solving the Knight's Tour problem using DFS. $O(k^N)$
- [Word Ladder Problem](WordLadderProblem.py): Implementation of the Word Ladder problem using graphs.
12 changes: 6 additions & 6 deletions LinkedLists/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Linked Lists

This directory contains Python implementations of various types of linked lists and related algorithms.
This directory contains Python implementations of linked list data structures and related problems.

## Contents

- [Singly Linked List Implementation](SingleLinkedListImple.py): Basic implementation of a singly linked list node and basic linkage.
- [Doubly Linked List Implementation](DoublyLinkedListImple.py): Basic implementation of a doubly linked list node with `prev` and `next` pointers.
- [Singly Linked List Cycle Check](SinglyLinkedListCycleCheckImple.py): Implements Floyd's Cycle-Finding Algorithm (two pointers) to detect cycles in a linked list.
- [Linked List Reversal](LinkedListReversal.py): Reverses a singly linked list in-place in $O(n)$ time.
- [Nth to Last Node](LinkedListNthToLastNode.py): Finds the $n$-th to last node in a singly linked list using two pointers.
- [Singly Linked List Implementation](SinglyLinkedListImple.py): Basic implementation of a singly linked list. $O(1)$ for insertion/deletion at the head.
- [Doubly Linked List Implementation](DoublyLinkedListImple.py): Basic implementation of a doubly linked list. $O(1)$ for insertion/deletion at both ends.
- [Singly Linked List Cycle Check](SinglyLinkedListCycleCheckImple.py): Implementation of Floyd's cycle-finding algorithm to detect cycles in a linked list. $O(n)$
- [Linked List Reversal](LinkedListReversal.py): In-place reversal of a singly linked list. $O(n)$
- [Linked List Nth to Last Node](LinkedListNthToLastNode.py): Finding the $n$-th to last node in a singly linked list. $O(n)$
21 changes: 9 additions & 12 deletions LinkedLists/SinglyLinkedListCycleCheckImple.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def __init__(self, value):
self.value = value
self.nextnode = None

def cycle_check(node):
# Set two pointers initialize to passed node
pt1 = node
pt2 = node
def cycle_check(self):
# Set two pointers initialize to self
pt1 = self
pt2 = self
# loop through end of the list
while pt2 != None and pt2.nextnode != None:
pt1 = pt1.nextnode
Expand All @@ -46,12 +46,9 @@ def cycle_check(node):
print (b.value)
print (c.value)

# Since cycle_check is a method but it doesn't use self and is defined inside class
# it should be called on an instance or changed to static method.
# In its current definition it behaves like a regular method but is missing 'self'.
# Actually it is defined as def cycle_check(node): which means it takes one arg.
# If called as LinkedListNode.cycle_check(a) it should work if it was just a function.

print(a.cycle_check())

# Test with cycle
print(f"Cycle detected (expected True): {a.cycle_check()}")

# Test without cycle
c.nextnode = None
print(f"Cycle detected (expected False): {a.cycle_check()}")
6 changes: 3 additions & 3 deletions Queues/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Queues

This directory contains Python implementations of the Queue data structure.
This directory contains Python implementations of the Queue (First-In-First-Out) data structure.

## Contents

- [Queue Implementation](QueueImple.py): Basic implementation of a FIFO (First-In-First-Out) queue using a Python list. Includes `enqueue`, `dequeue`, `isEmpty`, and `size` methods.
- [Queue with Two Stacks](QueueWith2StacksImple.py): Implements a queue using two stacks (represented by Python lists) to achieve FIFO behavior.
- [Queue Implementation](QueueImple.py): Basic implementation of a Queue using a Python list. `enqueue` $O(n)$, `dequeue` $O(1)$.
- [Queue with 2 Stacks](QueueWith2StacksImple.py): Implementation of a Queue using two stacks. $O(1)$ amortized for both `enqueue` and `dequeue`.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Most scripts in this repository are standalone and can be executed directly:

```bash
# Run any Python script
python3 Arrays/Anagram_Check_Sorted_Sol.py
python3 Arrays/AnagramCheckSortedSol.py

# Or run from the repo root
python3 Sorting/BubbleSortImple.py
Expand All @@ -80,15 +80,15 @@ python3 Sorting/BubbleSortImple.py
```
.
├── Arrays/ # 🔤 Array-based problems and algorithms
├── Error-debug/ # ⚠️ Error handling and debugging examples
├── Deque/ # 🔄 Double-ended queue
├── ErrorHandling/ # ⚠️ Error handling and debugging examples
├── GraphAlgorithms/ # 🗺️ Graph traversal (BFS, DFS) and pathfinding
├── LinkedLists/ # 🔗 Singly and Doubly Linked Lists
├── Queues/ # 📦 Queue implementations (FIFO)
├── Recursion/ # 🔀 Recursive problems and Dynamic Programming
├── Sorting/ # 📊 Common sorting algorithms
├── Stacks/ # 📚 Stack implementations and applications
├── Trees/ # 🌳 Binary Trees, BSTs, Heaps, and Traversals
├── deque/ # 🔄 Double-ended queue
├── CONTRIBUTING.md # 🤝 Contribution guidelines
├── LICENSE # 📄 MIT License
└── README.md # 📖 This file
Expand All @@ -100,21 +100,21 @@ python3 Sorting/BubbleSortImple.py

### Arrays 🔤
Common array-based algorithms and manipulations.
- [Anagram Check](Arrays/): [Sorted](Arrays/Anagram_Check_Sorted_Sol.py) & [Manual](Arrays/Anagram_Check_manual_Sol.py) solutions
- [Anagram Check](Arrays/): [Sorted](Arrays/AnagramCheckSortedSol.py) & [Manual](Arrays/AnagramCheckManualSol.py) solutions
- [Array Pair Sum](Arrays/ArrayPairSumSol.py): Find pairs that sum to $k$
- [Find Missing Element](Arrays/): [XOR](Arrays/ArrayFindTheMissingElement_XOR_sol.py), [Brute Force](Arrays/ArrayFindTheMissingElement_brute_force_sol.py), [Hash Table](Arrays/ArrayFindTheMissingElement_hash_table_sol.py), & [Sum](Arrays/ArrayFindTheMissingElement_takingSumandSubtract_sol.py) approaches
- [Find Missing Element](Arrays/): [XOR](Arrays/ArrayFindTheMissingElementXORSol.py), [Brute Force](Arrays/ArrayFindTheMissingElementBruteForceSol.py), [Hash Table](Arrays/ArrayFindTheMissingElementHashTableSol.py), & [Sum](Arrays/ArrayFindTheMissingElementSumSol.py) approaches

### Linked Lists 🔗
Implementations and problems involving linked structures.
- [Singly Linked List](LinkedLists/SingleLinkedListImple.py) & [Doubly Linked List](LinkedLists/DoublyLinkedListImple.py)
- [Singly Linked List](LinkedLists/SinglyLinkedListImple.py) & [Doubly Linked List](LinkedLists/DoublyLinkedListImple.py)
- [Cycle Detection](LinkedLists/SinglyLinkedListCycleCheckImple.py): Detect cycles using two pointers (Floyd's algorithm)
- [Reverse Linked List](LinkedLists/LinkedListReversal.py): In-place reversal
- [Nth to Last Node](LinkedLists/LinkedListNthToLastNode.py): Find the $n$-th node from the end

### Stacks 📚
LIFO (Last-In-First-Out) data structures.
- [Stack Implementation](Stacks/StackImple.py): Basic operations (push, pop, peek)
- [Balanced Parentheses](Stacks/BalanceParenthlessCheckImple.py): Check for balanced brackets using a stack
- [Balanced Parentheses](Stacks/BalanceParenthesesCheckImple.py): Check for balanced brackets using a stack

### Queues 📦
FIFO (First-In-First-Out) data structures.
Expand All @@ -123,7 +123,7 @@ FIFO (First-In-First-Out) data structures.

### Deque 🔄
Double-ended queue operations.
- [Deque Implementation](deque/DequeImple.py): Operations at both ends
- [Deque Implementation](Deque/DequeImple.py): Operations at both ends

### Trees 🌳
Hierarchical data structures.
Expand All @@ -133,7 +133,7 @@ Hierarchical data structures.
- [Binary Heap](Trees/BinaryHeapImple.py): Min-heap implementation
- [Tree Traversals](Trees/TreeLevelOrderPrintImple.py): Level order (BFS) printing
- [Trim BST](Trees/TrimBinarySearchTreeImple.py): Keep nodes within a range
- [Tree Representations](Trees/): [Nodes & References](Trees/TreeRepresentationWithNodesReferences.py) & [List of Lists](Trees/buildTreeTest.py)
- [Tree Representations](Trees/): [Nodes & References](Trees/TreeRepresentationWithNodesReferences.py) & [List of Lists](Trees/BuildTreeTest.py)

---

Expand All @@ -144,7 +144,7 @@ Algorithms for arranging elements in order.
- [Bubble Sort](Sorting/BubbleSortImple.py) - $O(n^2)$
- [Selection Sort](Sorting/SelectionSortImple.py) - $O(n^2)$
- [Insertion Sort](Sorting/InsertionSortImple.py) - $O(n^2)$
- [Shell Sort](Sorting/ShellSortImple.py) - $O(n \log n)$
- [Shell Sort](Sorting/ShellSortImple.py) - $O(n^2)$
- [Merge Sort](Sorting/MergeSortImple.py) - $O(n \log n)$
- [Quick Sort](Sorting/QuickSortImple.py) - $O(n \log n)$ average

Expand All @@ -168,7 +168,7 @@ Algorithms for graph traversal and pathfinding.

## ⚠️ Error Handling & Debugging

- [Error and Exceptions](Error-debug/ErrorExceptions.py): Demonstrates `try`, `except`, `else`, and `finally` blocks for robust error handling.
- [Error and Exceptions](ErrorHandling/ErrorExceptions.py): Demonstrates `try`, `except`, `else`, and `finally` blocks for robust error handling.

---

Expand Down Expand Up @@ -215,7 +215,7 @@ New to DSA? Follow this recommended order:
## 🔮 Roadmap

- [ ] Add more graph algorithms (Dijkstra, Bellman-Ford)
- [ ] Include complexity analysis for each solution
- [x] Include complexity analysis for each solution
- [ ] Add interactive examples/visualizations
- [ ] Create a difficulty level classification
- [ ] Add more test cases
Expand Down
25 changes: 10 additions & 15 deletions Recursion/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@ This directory contains Python implementations of problems solved using recursio

## Contents

### Fibonacci Sequence
- [Fibonacci (Iterative)](FibonacciSeqIterative.py): Iterative implementation of the Fibonacci sequence.
- [Fibonacci (Recursive)](FibonacciSeqRecursion.py): Simple recursive implementation of the Fibonacci sequence.
- [Fibonacci (Dynamic Programming)](FibonacciSeqDynamic.py): Optimized Fibonacci sequence using memoization.

### Coin Change Problem
- [Coin Change (Recursive)](CoinChangeProblemRecursion.py): Basic recursive solution to find the minimum number of coins for change.
- [Coin Change (Dynamic Programming)](CoinChangeProblemDynamic.py): Optimized solution to the coin change problem using dynamic programming.

### Other Recursive Problems
- [Cumulative Sum](RecursionCumulativeSum.py): Computes the cumulative sum from 0 to $n$ recursively.
- [Reverse a String](RecursionReverseStr.py): Reverses a string using recursive calls.
- [String Permutations](RecursionStrPermutation.py): Generates all possible permutations of a given string.
- [Sum of Digits](RecursionSumOfDigits.py): Calculates the sum of all individual digits in an integer recursively.
- [Word Split](RecursionWordSplit.py): Determines if a string can be split into words from a given list.
- [Coin Change Problem (Recursive)](CoinChangeProblemRecursion.py): Solving the coin change problem using pure recursion. Exponential complexity.
- [Coin Change Problem (Dynamic Programming)](CoinChangeProblemDynamic.py): Solving the coin change problem using dynamic programming (memoization). $O(n \cdot m)$ where $n$ is target and $m$ is number of coins.
- [Fibonacci Sequence (Recursive)](FibonacciSeqRecursion.py): Generating Fibonacci numbers using recursion. $O(2^n)$
- [Fibonacci Sequence (Iterative)](FibonacciSeqIterative.py): Generating Fibonacci numbers using iteration. $O(n)$
- [Fibonacci Sequence (Dynamic Programming)](FibonacciSeqDynamic.py): Generating Fibonacci numbers using dynamic programming. $O(n)$
- [Recursion Cumulative Sum](RecursionCumulativeSum.py): Calculating cumulative sum using recursion. $O(n)$
- [Recursion Reverse String](RecursionReverseStr.py): Reversing a string using recursion. $O(n)$
- [Recursion String Permutation](RecursionStrPermutation.py): Generating all permutations of a string using recursion. $O(n!)$
- [Recursion Sum of Digits](RecursionSumOfDigits.py): Calculating the sum of digits using recursion. $O(\log_{10} n)$
- [Recursion Word Split](RecursionWordSplit.py): Splitting a string into words based on a dictionary using recursion.
8 changes: 4 additions & 4 deletions Sorting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ This directory contains Python implementations of various sorting algorithms wit
## Contents

- [Bubble Sort](BubbleSortImple.py): Implementation of Bubble Sort with $O(n^2)$ complexity.
- [Selection Sort](SelectionSortImple.py): Implementation of Selection Sort, improving on Bubble Sort by making only one exchange per pass.
- [Insertion Sort](InsertionSortImple.py): Implementation of Insertion Sort, maintaining a sorted sublist.
- [Shell Sort](ShellSortImple.py): Implementation of Shell Sort (diminishing increment sort), improving on Insertion Sort.
- [Selection Sort](SelectionSortImple.py): Implementation of Selection Sort, improving on Bubble Sort by making only one exchange per pass. $O(n^2)$
- [Insertion Sort](InsertionSortImple.py): Implementation of Insertion Sort, maintaining a sorted sublist. $O(n^2)$
- [Shell Sort](ShellSortImple.py): Implementation of Shell Sort (diminishing increment sort), improving on Insertion Sort. $O(n^2)$ worst-case.
- [Merge Sort](MergeSortImple.py): A recursive "divide and conquer" algorithm with $O(n \log n)$ complexity.
- [Quick Sort](QuickSortImple.py): Implementation of Quick Sort (partition exchange sort), using divide and conquer in-place.
- [Quick Sort](QuickSortImple.py): Implementation of Quick Sort (partition exchange sort), using divide and conquer in-place. $O(n \log n)$ average.
6 changes: 3 additions & 3 deletions Stacks/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Stacks

This directory contains Python implementations of the Stack data structure and its applications.
This directory contains Python implementations of the Stack (Last-In-First-Out) data structure.

## Contents

- [Stack Implementation](StackImple.py): Basic implementation of a LIFO (Last-In-First-Out) stack using a Python list. Includes `push`, `pop`, `peek`, `isEmpty`, and `size` methods.
- [Balanced Parentheses Check](BalanceParenthlessCheckImple.py): Uses a stack to check if a string of opening and closing parentheses (round, square, and curly) is balanced.
- [Stack Implementation](StackImple.py): Basic implementation of a Stack with push, pop, peek, isEmpty, and size operations. $O(1)$
- [Balanced Parentheses Check](BalanceParenthesesCheckImple.py): Using a stack to check if a string of parentheses is balanced. $O(n)$
File renamed without changes.
Loading