This repository contains a collection of common programming problems and data structure implementations in Python.
- Arrays
- Linked Lists
- Stacks
- Queues
- Deque
- Recursion
- Trees
- Sorting
- Graph Algorithms
- Error Handling
- Acknowledgments
Checks if two strings are anagrams of each other.
- Files:
Arrays/Anagram_Check_Sorted_Sol.py,Arrays/Anagram_Check_manual_Sol.py
Given an integer array, output all unique pairs that sum up to a specific value k.
- File:
Arrays/ArrayPairSumSol.py
Find the missing element in a shuffled second array.
- Files:
Arrays/ArrayFindTheMissingElement_XOR_sol.py,Arrays/ArrayFindTheMissingElement_brute_force_sol.py,Arrays/ArrayFindTheMissingElement_hash_table_sol.py,Arrays/ArrayFindTheMissingElement_takingSumandSubtract_sol.py
Basic skeleton for a Singly Linked List.
- File:
LinkedLists/SingleLinkedListImple.py
Basic skeleton for a Doubly Linked List.
- File:
LinkedLists/DoublyLinkedListImple.py
Check if a singly linked list contains a cycle using the "two runners" (slow and fast pointers) strategy.
- File:
LinkedLists/SinglyLinkedListCycleCheckImple.py
Reverse a linked list in-place.
- File:
LinkedLists/LinkedListReversal.py
Find the nth to last node in a linked list.
- File:
LinkedLists/LinkedListNthToLastNode.py
Basic stack operations (LIFO): push, pop, peek, isEmpty, size.
- File:
Stacks/StackImple.py
Check if a string of opening and closing parentheses is balanced.
- File:
Stacks/BalanceParenthlessCheckImple.py
Basic queue operations (FIFO): enqueue, dequeue, isEmpty, size.
- File:
Queues/QueueImple.py
Implement a queue using two stacks.
- File:
Queues/QueueWith2StacksImple.py
Double-ended queue operations: addFront, addRear, removeFront, removeRear, isEmpty, size.
- File:
deque/DequeImple.py
Compute the cumulative sum from 0 to n.
- File:
Recursion/RecursionCumulativeSum.py
Returns the sum of all individual digits in an integer.
- File:
Recursion/RecursionSumOfDigits.py
Determine if a string can be split into words found in a given list.
- File:
Recursion/RecursionWordSplit.py
Recursive implementation to reverse a string.
- File:
Recursion/RecursionReverseStr.py
Output all possible permutations of a string.
- File:
Recursion/RecursionStrPermutation.py
Implementations using iteration, recursion, and dynamic programming (memoization).
- Files:
Recursion/FibonacciSeqIterative.py,Recursion/FibonacciSeqRecursion.py,Recursion/FibonacciSeqDynamic.py
Find the fewest coins needed to make a change amount.
- Files:
Recursion/CoinChangeProblemRecursion.py,Recursion/CoinChangeProblemDynamic.py
- File:
Trees/BinarySearchTreesImple.py
- File:
Trees/BinaryHeapImple.py
Recursive and iterative implementations.
- Files:
Trees/BinarySearchImple.py,Trees/BinarySearchRecursiveImple.py
Check if a binary tree is a valid Binary Search Tree.
- Files:
Trees/BinarySearchTreeCheckImpleSol1.py,Trees/BinarySearchTreeCheckImpleSol2.py
Trim a BST so all nodes are within a given range [min, max].
- File:
Trees/TrimBinarySearchTreeImple.py
Implementing a tree using classes and references.
- File:
Trees/TreeRepresentationWithNodesReferences.py
Print a binary tree in level order.
- File:
Trees/TreeLevelOrderPrintImple.py
-
File:
Sorting/BubbleSortImple.py -
Complexity:
$O(n^2)$ worst and average case,$O(n)$ best case.
-
File:
Sorting/SelectionSortImple.py -
Complexity:
$O(n^2)$ for all cases.
-
File:
Sorting/InsertionSortImple.py -
Complexity:
$O(n^2)$ worst and average case,$O(n)$ best case.
-
File:
Sorting/MergeSortImple.py -
Complexity:
$O(n \log n)$ for all cases.
-
File:
Sorting/QuickSortImple.py -
Complexity:
$O(n^2)$ worst case,$O(n \log n)$ average/best case.
-
File:
Sorting/ShellSortImple.py -
Complexity: Between
$O(n)$ and$O(n^2)$ depending on increment sequence.
- File:
GraphAlgorithms/AdjacencyListGraphImple.py
- Files:
GraphAlgorithms/BFS.py,GraphAlgorithms/WordLadderProblem.py
- Files:
GraphAlgorithms/DFSImpleTheKnightsTourProblem.py,GraphAlgorithms/TheKnightsTourProblem.py
A more general implementation of Depth First Search.
- File:
GraphAlgorithms/DFSGeneral.py
Demonstrates try-except-else-finally blocks and user input validation.
- File:
Error-debug/ErrorExceptions.py