diff --git a/Arrays/README.md b/Arrays/README.md new file mode 100644 index 0000000..b710af1 --- /dev/null +++ b/Arrays/README.md @@ -0,0 +1,16 @@ +# Arrays + +This directory contains Python implementations for common array-related problems and algorithms. + +## Contents + +- **Anagram Check**: Checks if two strings are anagrams of each other. + - `Anagram_Check_Sorted_Sol.py` + - `Anagram_Check_manual_Sol.py` +- **Array Pair Sum**: Given an integer array, output all unique pairs that sum up to a specific value `k`. + - `ArrayPairSumSol.py` +- **Find Missing Element**: Find the missing element in a shuffled second array. + - `ArrayFindTheMissingElement_XOR_sol.py` + - `ArrayFindTheMissingElement_brute_force_sol.py` + - `ArrayFindTheMissingElement_hash_table_sol.py` + - `ArrayFindTheMissingElement_takingSumandSubtract_sol.py` diff --git a/Error-debug/README.md b/Error-debug/README.md new file mode 100644 index 0000000..bf00e28 --- /dev/null +++ b/Error-debug/README.md @@ -0,0 +1,8 @@ +# Error Handling and Debugging + +This directory demonstrates common Python exception handling patterns and debugging practices. + +## Contents + +- **Basic Exception Handling**: Demonstrates `try-except-else-finally` blocks and user input validation. + - `ErrorExceptions.py` diff --git a/GraphAlgorithms/README.md b/GraphAlgorithms/README.md new file mode 100644 index 0000000..62480f1 --- /dev/null +++ b/GraphAlgorithms/README.md @@ -0,0 +1,15 @@ +# Graph Algorithms + +This directory contains implementations of fundamental graph algorithms and their applications to classic computer science problems. + +## Contents + +- **Adjacency List Graph Implementation**: A common way to represent a graph in Python. + - `AdjacencyListGraphImple.py` +- **Breadth First Search (BFS)**: Implementation of BFS and its application to the Word Ladder problem. + - `BFS.py` + - `WordLadderProblem.py` +- **Depth First Search (DFS)**: General DFS implementation and its application to the Knight's Tour problem. + - `DFSGeneral.py` + - `DFSImpleTheKnightsTourProblem.py` + - `TheKnightsTourProblem.py` diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6d16b25 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 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..0a64868 --- /dev/null +++ b/LinkedLists/README.md @@ -0,0 +1,15 @@ +# Linked Lists + +This directory contains implementations of singly and doubly linked list data structures and their related algorithms. + +## Contents + +- **Singly Linked List**: Basic implementation and cycle detection. + - `SingleLinkedListImple.py` + - `SinglyLinkedListCycleCheckImple.py` +- **Doubly Linked List**: Basic implementation of a doubly linked list. + - `DoublyLinkedListImple.py` +- **Reversal**: In-place reversal of a linked list. + - `LinkedListReversal.py` +- **Nth to Last Node**: Find the nth element from the end of a linked list. + - `LinkedListNthToLastNode.py` diff --git a/Queues/README.md b/Queues/README.md new file mode 100644 index 0000000..2375bc7 --- /dev/null +++ b/Queues/README.md @@ -0,0 +1,10 @@ +# Queues + +This directory contains implementations of queue data structures using various approaches. + +## Contents + +- **Basic Queue**: Implementation of a standard queue (FIFO) with standard operations. + - `QueueImple.py` +- **Queue with Two Stacks**: Implementation of a queue using two stacks as its internal data structure. + - `QueueWith2StacksImple.py` diff --git a/README.md b/README.md index 790acf4..7e7d33d 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) --- @@ -149,6 +151,10 @@ Implementing a tree using classes and references. Print a binary tree in level order. - **File**: `Trees/TreeLevelOrderPrintImple.py` +### Tree Representation (List of Lists) +Implementing a tree using list of lists. +- **File**: `Trees/buildTreeTest.py` + --- ## Sorting @@ -204,6 +210,28 @@ Demonstrates `try-except-else-finally` blocks and user input validation. --- +## Usage + +Most scripts in this repository are standalone and can be executed directly using the Python 3 interpreter. To run a script, navigate to the repository's root directory and use the following command: + +```bash +python3 path/to/script.py +``` + +For example, to run the Array Pair Sum solution: + +```bash +python3 Arrays/ArrayPairSumSol.py +``` + +--- + +## License + +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more 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..62d93d7 --- /dev/null +++ b/Recursion/README.md @@ -0,0 +1,23 @@ +# Recursion + +This directory contains implementations of recursive algorithms and their applications to various programming problems. + +## Contents + +- **Cumulative Sum**: Compute the cumulative sum from 0 to `n`. + - `RecursionCumulativeSum.py` +- **Sum of Digits**: Compute the sum of all individual digits in an integer. + - `RecursionSumOfDigits.py` +- **Word Split**: Determine if a string can be split into words from a given list. + - `RecursionWordSplit.py` +- **Reverse a String**: Recursive implementation of string reversal. + - `RecursionReverseStr.py` +- **String Permutations**: Output all possible permutations of a string. + - `RecursionStrPermutation.py` +- **Fibonacci Sequence**: Recursive, iterative, and dynamic programming implementations. + - `FibonacciSeqRecursion.py` + - `FibonacciSeqIterative.py` + - `FibonacciSeqDynamic.py` +- **Coin Change Problem**: Minimum number of coins needed to make change. + - `CoinChangeProblemRecursion.py` + - `CoinChangeProblemDynamic.py` diff --git a/Sorting/README.md b/Sorting/README.md new file mode 100644 index 0000000..c9a09b4 --- /dev/null +++ b/Sorting/README.md @@ -0,0 +1,18 @@ +# Sorting + +This directory contains implementations of various sorting algorithms and their complexity analysis. + +## Contents + +- **Bubble Sort**: Simple sorting algorithm that repeatedly swaps adjacent elements. + - `BubbleSortImple.py` +- **Selection Sort**: Sorting algorithm that selects the smallest element in each pass. + - `SelectionSortImple.py` +- **Insertion Sort**: Sorting algorithm that builds the final sorted array one element at a time. + - `InsertionSortImple.py` +- **Merge Sort**: Divide-and-conquer sorting algorithm. + - `MergeSortImple.py` +- **Quick Sort**: Divide-and-conquer sorting algorithm using a pivot element. + - `QuickSortImple.py` +- **Shell Sort**: Generalization of insertion sort that allows for swapping distant elements. + - `ShellSortImple.py` diff --git a/Stacks/README.md b/Stacks/README.md new file mode 100644 index 0000000..eaf9389 --- /dev/null +++ b/Stacks/README.md @@ -0,0 +1,10 @@ +# Stacks + +This directory contains implementations of stack data structures and their related algorithms. + +## Contents + +- **Stack Implementation**: Basic stack operations (LIFO): `push`, `pop`, `peek`, `isEmpty`, `size`. + - `StackImple.py` +- **Balanced Parentheses Check**: Algorithm to check if a string of opening and closing parentheses is balanced. + - `BalanceParenthlessCheckImple.py` diff --git a/Trees/README.md b/Trees/README.md new file mode 100644 index 0000000..b6c601e --- /dev/null +++ b/Trees/README.md @@ -0,0 +1,21 @@ +# Trees + +This directory contains implementations of binary trees, binary heaps, and various tree-based algorithms. + +## Contents + +- **Binary Search Tree (BST)**: Basic implementation and validation. + - `BinarySearchTreesImple.py` + - `BinarySearchTreeCheckImpleSol1.py` + - `BinarySearchTreeCheckImpleSol2.py` + - `TrimBinarySearchTreeImple.py` +- **Binary Heap**: Implementation of binary heaps. + - `BinaryHeapImple.py` +- **Binary Search**: Recursive and iterative implementations of binary search. + - `BinarySearchImple.py` + - `BinarySearchRecursiveImple.py` +- **Tree Representation**: Different ways of representing binary trees in Python. + - `TreeRepresentationWithNodesReferences.py` + - `buildTreeTest.py` (List of Lists) +- **Level Order Print**: Print a binary tree in level order. + - `TreeLevelOrderPrintImple.py` diff --git a/deque/README.md b/deque/README.md new file mode 100644 index 0000000..88a56f0 --- /dev/null +++ b/deque/README.md @@ -0,0 +1,8 @@ +# Deque + +This directory contains implementations of double-ended queue (deque) data structures. + +## Contents + +- **Deque Implementation**: Basic operations (FIFO/LIFO): `addFront`, `addRear`, `removeFront`, `removeRear`, `isEmpty`, `size`. + - `DequeImple.py`