diff --git a/Arrays/README.md b/Arrays/README.md new file mode 100644 index 0000000..a83cf29 --- /dev/null +++ b/Arrays/README.md @@ -0,0 +1,21 @@ +# Arrays + +This directory contains Python implementations of common array-related algorithms and problems. + +## Contents + +### Anagram Check +Checks if two strings are anagrams of each other. +- [Anagram_Check_Sorted_Sol.py](Anagram_Check_Sorted_Sol.py) +- [Anagram_Check_manual_Sol.py](Anagram_Check_manual_Sol.py) + +### Find Missing Element +Find the missing element in a shuffled second array. +- [ArrayFindTheMissingElement_XOR_sol.py](ArrayFindTheMissingElement_XOR_sol.py) +- [ArrayFindTheMissingElement_brute_force_sol.py](ArrayFindTheMissingElement_brute_force_sol.py) +- [ArrayFindTheMissingElement_hash_table_sol.py](ArrayFindTheMissingElement_hash_table_sol.py) +- [ArrayFindTheMissingElement_takingSumandSubtract_sol.py](ArrayFindTheMissingElement_takingSumandSubtract_sol.py) + +### Array Pair Sum +Given an integer array, output all unique pairs that sum up to a specific value `k`. +- [ArrayPairSumSol.py](ArrayPairSumSol.py) diff --git a/Error-debug/README.md b/Error-debug/README.md new file mode 100644 index 0000000..b38e29d --- /dev/null +++ b/Error-debug/README.md @@ -0,0 +1,9 @@ +# Error Handling and Debugging + +This directory contains examples of error handling and debugging in Python. + +## Contents + +### Basic Exception Handling +Demonstrates the use of `try-except-else-finally` blocks and user input validation. +- [ErrorExceptions.py](ErrorExceptions.py) diff --git a/GraphAlgorithms/README.md b/GraphAlgorithms/README.md new file mode 100644 index 0000000..1d41adf --- /dev/null +++ b/GraphAlgorithms/README.md @@ -0,0 +1,17 @@ +# Graph Algorithms + +This directory contains implementations of various graph-related algorithms and problems. + +## Contents + +### Graph Implementation +- [AdjacencyListGraphImple.py](AdjacencyListGraphImple.py): Basic Adjacency List implementation. + +### Breadth First Search (BFS) +- [BFS.py](BFS.py): Implementation of Breadth First Search. +- [WordLadderProblem.py](WordLadderProblem.py): Solving the Word Ladder problem using BFS. + +### Depth First Search (DFS) +- [DFSGeneral.py](DFSGeneral.py): A general implementation of Depth First Search. +- [DFSImpleTheKnightsTourProblem.py](DFSImpleTheKnightsTourProblem.py): Implementation of the Knight's Tour problem using DFS. +- [TheKnightsTourProblem.py](TheKnightsTourProblem.py): Another implementation/part of the Knight's Tour problem. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..cecd15e --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Pradeep K. Pant + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/LinkedLists/README.md b/LinkedLists/README.md new file mode 100644 index 0000000..cc088f1 --- /dev/null +++ b/LinkedLists/README.md @@ -0,0 +1,16 @@ +# Linked Lists + +This directory contains implementations of linked list data structures and related algorithms. + +## Contents + +### Singly Linked List +- [SingleLinkedListImple.py](SingleLinkedListImple.py): Basic Singly Linked List implementation. +- [SinglyLinkedListCycleCheckImple.py](SinglyLinkedListCycleCheckImple.py): Check if a singly linked list contains a cycle. + +### Doubly Linked List +- [DoublyLinkedListImple.py](DoublyLinkedListImple.py): Basic Doubly Linked List implementation. + +### Operations +- [LinkedListReversal.py](LinkedListReversal.py): In-place reversal of a linked list. +- [LinkedListNthToLastNode.py](LinkedListNthToLastNode.py): Find the nth to last node in a linked list. diff --git a/Queues/README.md b/Queues/README.md new file mode 100644 index 0000000..eaadad0 --- /dev/null +++ b/Queues/README.md @@ -0,0 +1,13 @@ +# Queues + +This directory contains implementations of queue data structures. + +## Contents + +### Basic Queue Implementation +Basic queue operations (FIFO): `enqueue`, `dequeue`, `isEmpty`, `size`. +- [QueueImple.py](QueueImple.py) + +### Queue with Two Stacks +Implement a queue using two stacks. +- [QueueWith2StacksImple.py](QueueWith2StacksImple.py) diff --git a/README.md b/README.md index 790acf4..432794c 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ This repository contains a collection of common programming problems and data st - [Sorting](#sorting) - [Graph Algorithms](#graph-algorithms) - [Error Handling](#error-handling) +- [Usage](#usage) +- [License](#license) - [Acknowledgments](#acknowledgments) --- @@ -204,6 +206,20 @@ Demonstrates `try-except-else-finally` blocks and user input validation. --- +## Usage +Most of these scripts can be executed directly using the Python 3 interpreter. For example: +```bash +python3 Arrays/Anagram_Check_Sorted_Sol.py +``` +Some scripts may have dependencies or require specific setup as described in their respective subdirectory READMEs. + +--- + +## License +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. + +--- + ## Acknowledgments - [Python for Data Structures, Algorithms, and Interviews on Udemy](https://www.udemy.com) - [Problem Solving with Algorithms and Data Structures using Python](http://interactivepython.org/runestone/static/pythonds/index.html) diff --git a/Recursion/README.md b/Recursion/README.md new file mode 100644 index 0000000..94b46ae --- /dev/null +++ b/Recursion/README.md @@ -0,0 +1,27 @@ +# Recursion + +This directory contains recursive implementations of various algorithms and problems. + +## Contents + +### Basic Recursion +- [RecursionCumulativeSum.py](RecursionCumulativeSum.py): Compute the cumulative sum from 0 to `n`. +- [RecursionSumOfDigits.py](RecursionSumOfDigits.py): Returns the sum of all individual digits in an integer. + +### String Manipulation +- [RecursionReverseStr.py](RecursionReverseStr.py): Recursive implementation to reverse a string. +- [RecursionStrPermutation.py](RecursionStrPermutation.py): Output all possible permutations of a string. + +### Word Problems +- [RecursionWordSplit.py](RecursionWordSplit.py): Determine if a string can be split into words found in a given list. + +### Fibonacci Sequence +Implementations using iteration, recursion, and dynamic programming (memoization). +- [FibonacciSeqIterative.py](FibonacciSeqIterative.py) +- [FibonacciSeqRecursion.py](FibonacciSeqRecursion.py) +- [FibonacciSeqDynamic.py](FibonacciSeqDynamic.py) + +### Coin Change Problem +Find the fewest coins needed to make a change amount. +- [CoinChangeProblemRecursion.py](CoinChangeProblemRecursion.py) +- [CoinChangeProblemDynamic.py](CoinChangeProblemDynamic.py) diff --git a/Sorting/README.md b/Sorting/README.md new file mode 100644 index 0000000..6195bdf --- /dev/null +++ b/Sorting/README.md @@ -0,0 +1,23 @@ +# Sorting + +This directory contains Python implementations of common sorting algorithms. + +## Contents + +### Bubble Sort +- [BubbleSortImple.py](BubbleSortImple.py): $O(n^2)$ worst and average case, $O(n)$ best case. + +### Selection Sort +- [SelectionSortImple.py](SelectionSortImple.py): $O(n^2)$ for all cases. + +### Insertion Sort +- [InsertionSortImple.py](InsertionSortImple.py): $O(n^2)$ worst and average case, $O(n)$ best case. + +### Merge Sort +- [MergeSortImple.py](MergeSortImple.py): $O(n \log n)$ for all cases. + +### Quick Sort +- [QuickSortImple.py](QuickSortImple.py): $O(n^2)$ worst case, $O(n \log n)$ average/best case. + +### Shell Sort +- [ShellSortImple.py](ShellSortImple.py): Complexity between $O(n)$ and $O(n^2)$ depending on increment sequence. diff --git a/Stacks/README.md b/Stacks/README.md new file mode 100644 index 0000000..0a453be --- /dev/null +++ b/Stacks/README.md @@ -0,0 +1,13 @@ +# Stacks + +This directory contains implementations of stack data structures and related problems. + +## Contents + +### Basic Stack Implementation +Basic stack operations (LIFO): `push`, `pop`, `peek`, `isEmpty`, `size`. +- [StackImple.py](StackImple.py) + +### Balanced Parentheses Check +Check if a string of opening and closing parentheses is balanced. +- [BalanceParenthlessCheckImple.py](BalanceParenthlessCheckImple.py) diff --git a/Trees/README.md b/Trees/README.md new file mode 100644 index 0000000..d14ac67 --- /dev/null +++ b/Trees/README.md @@ -0,0 +1,23 @@ +# Trees + +This directory contains Python implementations of tree data structures and related algorithms. + +## Contents + +### Binary Search Trees +- [BinarySearchTreesImple.py](BinarySearchTreesImple.py): Implementation of Binary Search Trees. +- [BinarySearchTreeCheckImpleSol1.py](BinarySearchTreeCheckImpleSol1.py): Validate BST Solution 1. +- [BinarySearchTreeCheckImpleSol2.py](BinarySearchTreeCheckImpleSol2.py): Validate BST Solution 2. +- [TrimBinarySearchTreeImple.py](TrimBinarySearchTreeImple.py): Trim a BST so all nodes are within a given range `[min, max]`. + +### Binary Heaps +- [BinaryHeapImple.py](BinaryHeapImple.py): Implementation of Binary Heap. + +### Binary Search +- [BinarySearchImple.py](BinarySearchImple.py): Iterative Binary Search implementation. +- [BinarySearchRecursiveImple.py](BinarySearchRecursiveImple.py): Recursive Binary Search implementation. + +### Tree Traversal and Representation +- [TreeLevelOrderPrintImple.py](TreeLevelOrderPrintImple.py): Print a binary tree in level order. +- [TreeRepresentationWithNodesReferences.py](TreeRepresentationWithNodesReferences.py): Tree representation using classes and references. +- [buildTreeTest.py](buildTreeTest.py): Tree representation using a list-of-lists approach. diff --git a/deque/README.md b/deque/README.md new file mode 100644 index 0000000..5262a86 --- /dev/null +++ b/deque/README.md @@ -0,0 +1,9 @@ +# Deque + +This directory contains implementations of double-ended queues. + +## Contents + +### Basic Deque Implementation +Double-ended queue operations: `addFront`, `addRear`, `removeFront`, `removeRear`, `isEmpty`, `size`. +- [DequeImple.py](DequeImple.py)