{"id":22668684,"url":"https://github.com/thecollinsbyte/dsa","last_synced_at":"2026-02-26T12:05:05.485Z","repository":{"id":170849502,"uuid":"647109633","full_name":"TheCollinsByte/DSA","owner":"TheCollinsByte","description":"Java implementations of essential Data Structures and Algorithms for learning and practice.","archived":false,"fork":false,"pushed_at":"2024-11-17T09:49:41.000Z","size":341,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-19T16:27:55.620Z","etag":null,"topics":["algorithms","data-structures","data-structures-and-algorithms","dsa","gradle","java"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TheCollinsByte.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-05-30T04:47:52.000Z","updated_at":"2024-11-17T09:49:44.000Z","dependencies_parsed_at":"2024-01-30T17:24:36.533Z","dependency_job_id":"2c355006-2a09-4775-b806-51901ad358da","html_url":"https://github.com/TheCollinsByte/DSA","commit_stats":null,"previous_names":["paradigm-lab/shortest-path-first-algorithm","theoddagen/shortest-path-first-algorithm","theoddagen/dsa","collinsbyte/dsa","thecollinsbyte/dsa"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/TheCollinsByte/DSA","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheCollinsByte%2FDSA","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheCollinsByte%2FDSA/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheCollinsByte%2FDSA/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheCollinsByte%2FDSA/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TheCollinsByte","download_url":"https://codeload.github.com/TheCollinsByte/DSA/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheCollinsByte%2FDSA/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29858461,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-26T08:51:08.701Z","status":"ssl_error","status_checked_at":"2026-02-26T08:50:19.607Z","response_time":89,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","data-structures","data-structures-and-algorithms","dsa","gradle","java"],"created_at":"2024-12-09T15:16:19.231Z","updated_at":"2026-02-26T12:05:05.467Z","avatar_url":"https://github.com/TheCollinsByte.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n\u003ch1\u003e\u003ca href=\"https://github.com/TheCollinsByte/DSA\"\u003eData Structures and Algorithms (DSA)\u003c/a\u003e\u003c/h1\u003e\n\n\u003ca href=\"https://github.com/TheCollinsByte/DSA/blob/main/LICENSE\"\u003e\n\u003cimg alt=\"License\" src=\"https://img.shields.io/github/license/TheCollinsByte/DSA?style=flat\u0026color=eee\u0026label=\"\u003e \u003c/a\u003e\n\n\u003ca href=\"https://github.com/TheCollinsByte/DSA/graphs/contributors\"\u003e\n\u003cimg alt=\"People\" src=\"https://img.shields.io/github/contributors/TheCollinsByte/DSA?style=flat\u0026color=ffaaf2\u0026label=People\"\u003e \u003c/a\u003e\n\n\u003ca href=\"https://github.com/TheCollinsByte/DSA/stargazers\"\u003e\n\u003cimg alt=\"Stars\" src=\"https://img.shields.io/github/stars/TheCollinsByte/DSA?style=flat\u0026color=98c379\u0026label=Stars\"\u003e \u003c/a\u003e\n\n\u003ca href=\"https://github.com/TheCollinsByte/DSA/network/members\"\u003e\n\u003cimg alt=\"Forks\" src=\"https://img.shields.io/github/forks/TheCollinsByte/DSA?style=flat\u0026color=66a8e0\u0026label=Forks\"\u003e \u003c/a\u003e\n\n\u003ca href=\"https://github.com/TheCollinsByte/DSA/watchers\"\u003e\n\u003cimg alt=\"Watches\" src=\"https://img.shields.io/github/watchers/TheCollinsByte/DSA?style=flat\u0026color=f5d08b\u0026label=Watches\"\u003e \u003c/a\u003e\n\n\u003ca href=\"https://github.com/TheCollinsByte/DSA/pulse\"\u003e\n\u003cimg alt=\"Last Updated\" src=\"https://img.shields.io/github/last-commit/TheCollinsByte/DSA?style=flat\u0026color=e06c75\u0026label=\"\u003e \u003c/a\u003e\n\n\u003c/div\u003e\n\n## Description\n\nWelcome to the \u003cb\u003eData Structures and Algorithms Repository!\u003c/b\u003e This repository is a comprehensive collection of implementations for various data structures and algorithms in Java. Whether you're preparing for coding interviews, improving your algorithmic skills, or seeking efficient solutions to common problems, this repository is designed to assist you.\n\n- [Installation](#installation)\n- [Data Structures](#data-structures)\n- [Algorithm](#algorithm)\n- [Analysis Of Algorithm](#analysis-of-algorithms)\n- [Contributing](#contributing)\n- [License](#license)\n\n\n## Installation\n\nInstructions on how to set up the project on a local machine:\n\n1. Clone the repository:\n    ```bash\n    git clone https://github.com/TheCollinsByte/DSA\n    ```\n2. Navigate to the project directory:\n    ```bash\n    cd DSA\n    ```\n3. Ensure you have JDK version 21 installed. You can download it [here](https://www.oracle.com/java/technologies/downloads/#java21).\n\n4. Compile the project:\n    ```bash\n   ./gradlew build\n    ```\n\n5. Run the project:\n    ```bash\n    ./gradlew :{MODULE_NAME}:test -Dtest.verbose=true\n    ```\n\n# Data Structures\n\nA data structure is the mathematical or logical model of an organization of data.\n\n## Classification of Data Structure\n\n- \u003cb\u003eLinear Data Structure: \u003c/b\u003eData structure in which data elements are arranged sequentially or linearly, where each element is attached to its previous and next adjacent elements. Example: Array, Stack, Queue, Linked List etc.\n- \u003cb\u003eStatic Data Structure: \u003c/b\u003ehas a fixed memory size. It is easier to access the elements in a static data structure. Example: Array.\n- \u003cb\u003eDynamic Data Structure: \u003c/b\u003eIn dynamic data structure, the size is not fixed. it can be randomly updated during the runtime which may be considered efficient concerning the memory (space) complexity of the code. Example: Queue, Stack etc\n- \u003cb\u003eNon-Linear Data Structure: \u003c/b\u003eIs where data elements are not placed sequentially or linearly. We can't traverse all the elements in a single run only. Example: Trees and Graphs.\n\n## Types of Data Structures\n\n- \u003cb\u003eArrays: \u003c/b\u003eAn array is a collection of elements of the same type placed in contiguous memory locations.\n- \u003cb\u003eLinked List: \u003c/b\u003eIt is a linear data structure, in which the elements are not stored at contiguous memory locations and the elements are linked with each other.\n- \u003cb\u003eStacks: \u003c/b\u003eFollow LIFO (Last In First Out) principle, In this, the last element in the stack will be removed first.\n- \u003cb\u003eQueues: \u003c/b\u003eFollow FIFO (First In First Out) principle, In this, the first element stored is removed first.\n- \u003cb\u003eHash Tables (Hash Maps/Sets): \u003c/b\u003eThis is a type of data structure that store values which have keys related to each of them.\n- \u003cb\u003eTrees: \u003c/b\u003eIt is a data structure in which data is organized hierarchically and linked together. Some Examples are the Binary Search tree, Binary tree, Splay tree, AVL tree etc.\n- \u003cb\u003eHeaps: \u003c/b\u003eIt is specialized tree-based data structure, also called Binary heap in which the tree is a complete binary tree and the data is stored.\n- \u003cb\u003eGraphs: \u003c/b\u003eIt consists of a set of nodes and edges connecting each other.\n- \u003cb\u003eTries (Prefix Tree): \u003c/b\u003ea tries is a specialized tree-based data structure used to store a dynamic set of strings, where the keys are usually strings. It is often used for tasks such as autocomplete or searching for words in a dictionary. Tries enable efficient retrieval of strings based on their prefixes.\n- \u003cb\u003eUnion-Find (Disjoint Set Union (DSU)): \u003c/b\u003ethis data structure keeps track of a set of elements partitioned into disjoint subsets. It supports two operations: find(determines which subset a particular element is in) and Union (merges two subsets). It is often used in network connectivity and Kruskal's algorithm for finding minimum spanning trees.\n\n\n# Algorithm\n\n- An algorithm is a well-defined sets of instructions designed that are used to solve problems or perform a task.\n\n## Types of Algorithms\n\n- \u003cb\u003eRecursion: \u003c/b\u003eA recursive algorithm is based on recursion. In this case, a problem is broken into several sub-parts and called the same function again and again.\n- \u003cb\u003eDynamic Programming Algorithm: \u003c/b\u003eThis algorithm uses the concept of using the already found solution to avoid repetitive calculation of the same part of the problem. It divides the problem into smaller overlapping subproblems and solves them.\n- \u003cb\u003eGreedy Algorithms: \u003c/b\u003eIn this type of algorithm, the solution is built part by part. The solution for the next part is built based on the immediate benefit of the next part. The one solution that gives the most benefit will be chosen as the solution of the next part.\n- \u003cb\u003eBacktracking: \u003c/b\u003eThe backtracking algorithm builds the solution by searching among all possible solutions. Using this algorithm, we keep on building the solution following criteria. Whenever a solution fails we trace back to the failure point build on the next solution and continue this process till we find the solution or all possible solutions are looked after.\n- \u003cb\u003eBrute Force Algorithm: \u003c/b\u003eIt's the simplest approach to a problem. A brute force algorithm is the first approach that comes to finding when we see a problem.\n- \u003cb\u003eSearching Algorithm: \u003c/b\u003eare the ones that are used for searching elements or groups of elements from a particular data Structure. They can be of different types based on their approach or the data Structure in which the element should be found.\n- \u003cb\u003eHashing Algorithm: \u003c/b\u003eworks similarly to the searching algorithm. But they contain an index with a key ID. In hashing, a key is assigned to a specific data.\n- \u003cb\u003eSorting Algorithm: \u003c/b\u003eis arranging a group of data in a particular manner according to the requirment. Generally sorting algorithms are used to sort groups of data in an increasing or decreasing manner.\n- \u003cb\u003eDivide and Conquer Algorithm: \u003c/b\u003eThis algorithm breaks a problem into sub-problems, solves a single sub-problem, and merges the solutions to get the final solution. It Consists of the following three steps: Divide, Solve and Combine.\n- \u003cb\u003eRandomized Algorithms: \u003c/b\u003eIn the randomized algorithm, we use a random number so it gives immediate benefit. The random number helps in deciding the expected outcome.\n- \u003cb\u003ePattern Searching: \u003c/b\u003eThese algorithm are useed to find a pattern (substring) within a larger text (string). They help locate the position of a pattern in a given string. Common examples include the Knuth-Morris-Pratt (KMP) and Boyer-Moore algorithms.\n- \u003cb\u003eGeometric Algorithms: \u003c/b\u003eThese algorithm solve geometric problems like finding the convex hull, intersections of lines, and nearest neighbors. They deal with points, lines and polygons in 2D or 3D Space.\n- \u003cb\u003eMathematical Algorithms: \u003c/b\u003eThese are algorithms that solve mathematical problems such as calculating prime numbers, performing matrix operations or solving linear equations. Examples include algorithms for number theory, combinatorics and algebraic problems like the Euclidean algorithm for finding the greatest common divisor (GCD).\n- \u003cb\u003eBit Algorithms: \u003c/b\u003eBit manipulation algorithms perform operations at the bit level such as flipping, setting or shifting bits. They are efficient in optimizing space and speed for tasks like counting bits or performing XOR operations. Common bit algorithms include bitwise AND, OR and XOR operations.\n- \u003cb\u003eGraph Algorithms: \u003c/b\u003eThese algorithms deal with problems related to graphs, which are structures made up of vertices (nodes) connected by edges. Graph algorithms include finding the shortest path (Dijkstra's, Bellman-Ford), detecting cycles, or finding minimum spanning trees (Kruskal's, Prim's).\n- \u003cb\u003eBranch and Bound: \u003c/b\u003eThis is an optimization algorithm used for solving combinatorial problems, such as the Traveling Salesman Problem or Knapsack Problem. The algorithm explores all possible solutions but \"bounds\" parts of the search space that cannot lead to an optimal solution to avoid unnecessary exploration.\n\n# Analysis Of Algorithms\n\nAnalysis of algorithm deals in finding the best algorithm which runs fast and takes in less memory.\n\n- Time Complexity\n- Space Complexity\n\n### Time Complexity\n\n- Amount of time taken by algorithm to run.\n- The input processed by an algorithm helps in determining the time Complexity.\n\n### Space Complexity\n\n- Amount of memory or space taken by algorithm to run.\n- The memory required to process the input by an algorithm helps in determining the space complexity.\n\n## Asymptotic Analysis of an Algorithm\n\n- Asymptotic analysis helps in evaluating performance of an algorithm in terms of input size and its behaviour as the input size approaches infinity.\n- Using asymptotic analysis we don't measure actual running time of algorithm.\n- It helps in determining how time and space taken by algorithm increases with input size.\n\n### Asymptotic Notations\n\n- Asymptotic Notations are the mathematical tools used to describe the running time of an algorithm in terms or input size.\n- Example - Performance of car in 1 liter of petrol\n\n```markdown\nHighway (Min Traffic) - 25 km/litre\nCity (Max Traffic) - 15 km/litre\nCity + Highway (average Traffic) - 20 km/litre\n```\n\nAsymptotic Notations helps us in determine:\n* Best Case\n* Average Case\n* Worst Case\n\n### Types of Asymptotic Notations\n\nThere are three notations for performing runtime analysis of an algorithm\n\n* Omega (Ω) Notation\n* Big O (O) Notation\n* Theta (Θ) Notation\n\n\n## Omega (Ω) Notation\n\n- The formal way to express the lower bound of an algorithm's running time.\n- Lower bound means for any given input this notation determines best amount of time an algorithm can take to complete.\n\n## Big O (O) Notation\n\n- The formal way to express the upper bound of an algorithm running time.\n- Upper bound means for any given input this notation determines longest amount of time an algorithm can take to complete.\n- Worst case analysis\n\n## Rules of Big O (O) Notation\n\n- It's a single processor\n- It performs sequential Execution of Statements\n- Assignment operation takes 1 unit of time. eg: int x = 5 -\u003e 1 Unit of Time\n- Return Statement takes in 1 unit of time. eg: return x -\u003e 1 unit of Time\n- Arithmetic operation takes 1 unit of time. eg: x + y -\u003e 1 unit of Time\n- Logical operation takes 1 unit of time. eg: x \u0026\u0026 y -\u003e 1 unit of Time\n- Other small/single operations takes 1 unit of time.\n- Drop lower order terms. eg: Polynomial Equation: T = n\u003csup\u003e2\u003c/sup\u003e + 3n + 1 =\u003e O(n\u003csup\u003e2\u003c/sup\u003e)\n- Drop constant multipliers. eg: Polynomial Equation: T = 3n\u003csup\u003e2\u003c/sup\u003e + 6n + 1 =\u003e O(n\u003csup\u003e2\u003c/sup\u003e)\n\n## Theta (Θ) Notation\n\n- The formal way to express both the upper and lower bound of an algorithm running time.\n- By Lower and Upper bound means for any given input this notation determines average amount of time an algorithm can take to complete.\n- Average Case analysis\n\n\n## Contributing\n\nContributions are Welcome! Please follow these steps:\n\n1. Fork the repository.\n2. create a new branch (`git checkout -b name-dsa-module`)\n3. Make your changes and commit them (`git commit -m \"DSA: Solutions\"`)\n4. Push to the branch (`git push origin name-dsa-module`).\n5. Create a new Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n\u003cbr/\u003e\u003cbr/\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n\u003cstrong\u003e⭐ hit the star button if you found this useful ⭐\u003c/strong\u003e\u003cbr\u003e\n\n\u003ca href=\"https://github.com/TheCollinsByte/DSA\"\u003eSource\u003c/a\u003e\n| \u003ca href=\"https://x.com/TheCollinsByte\" target=\"_blank\"\u003eTwitter \u003c/a\u003e\n| \u003ca href=\"http://www.linkedin.com/in/collins-boniface\" target=\"_blank\"\u003eLinkedIn \u003c/a\u003e\n| \u003ca href=\"mailto:collo@fastmail.com\"\u003eEmail\u003c/a\u003e\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecollinsbyte%2Fdsa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthecollinsbyte%2Fdsa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecollinsbyte%2Fdsa/lists"}