{"id":27918699,"url":"https://github.com/hannasdev/data-structures","last_synced_at":"2025-05-06T18:24:43.423Z","repository":{"id":84016537,"uuid":"146173540","full_name":"hannasdev/data-structures","owner":"hannasdev","description":null,"archived":false,"fork":false,"pushed_at":"2018-09-01T09:37:59.000Z","size":32,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-03-27T20:21:02.731Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hannasdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2018-08-26T11:09:40.000Z","updated_at":"2018-09-01T09:38:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"6508aaca-1065-4051-a94e-35db7000104b","html_url":"https://github.com/hannasdev/data-structures","commit_stats":null,"previous_names":["hannasdev/data-structures"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hannasdev%2Fdata-structures","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hannasdev%2Fdata-structures/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hannasdev%2Fdata-structures/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hannasdev%2Fdata-structures/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hannasdev","download_url":"https://codeload.github.com/hannasdev/data-structures/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252742429,"owners_count":21797238,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2025-05-06T18:24:42.683Z","updated_at":"2025-05-06T18:24:43.408Z","avatar_url":"https://github.com/hannasdev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Data Structures\n\n## 1. Linked Lists\n\n### Singly Linked List\n\n- A data structure that contains a head, tail and length property.\n- Consists of nodes.\n- Each node has a value and a pointer to another node (or null).\n- Big O:\n  - Insertion - O(1)\n  - Removal - O(1) from beginning, otherwise O(N)\n  - Searching - O(N)\n  - Access - O(N)\n\n### Doubly Linked List\n\n- Has connections to both parent and child in each Node.\n- Takes up more memory, but faster to find items in.\n- Big O:\n  - Insertion - O(1)\n  - Removal - O(1)\n  - Searching - O(N)\n  - Access - O(N)\n\n### Stacks\n\n- Implements Doubly Linked List\n- LI/FO: Last in, first out\n- Example of stacks:\n  - Undo/Redo\n  - Routing/History\n- Add/remove at beginning (shift/unshift) if using an Array is less optimal than from end (pop/push) since index isn't affected on the other items.\n- An even better solution is to use a Linked List, since it doesn't have any index at all.\n- Big O:\n  - Insertion O(1)\n  - Removal O(1)\n  - Searching O(N)\n  - Access O(N)\n\n### Queues\n\n- Implements Singly Linked List\n- FI/FO: First In, first out\n- Add att end, remove at beginning.\n- Big O:\n\n## 2. Trees\n\n- Parent/child relationships.\n- One parent can have several children. There are no relationship between siblings or from child to parent.\n- Everything is one-directional.\n- Leaf: Child with no children\n- Edge: Path between parent/child.\n- Examples of trees: HTML and the DOM, Network Routing, Folders and files.\n- Binary Search Tree:\n  - Has maximum 2 children.\n  - The child to the left is always smaller then the parent.\n  - The child to the right is always bigger than the parent.\n  - Big O:\n    - Insertion: O(log n)\n    - Searching: O(log n)\n\n### Tree Traversal\n\n- Breadth First Search: Traverse through each level, from parent to child, one level at a time.\n- Depth First Search:\n  - PreOrder: Order before checking children.\n    - Can be used to export a tree structure so that it is easily reconstructed.\n  - PostOrder: Order after checking children.\n  - InOrder: Order between left and right children, so result is from smaller to larger.\n\n### Binary Heaps\n\n- Max Binary Heap: Parents are always larger than their children.\n- Min Binary Heap: Parents are always smaller than their children.\n- Used for things like Priority Queues and Graph Traversals.\n- Big O:\n  - Insertion: O(log n)\n  - Removal: O(log n)\n\n#### Priority Queues\n\n- List of things with different priorities, such as patients in an Emergency Room.\n- Can be implemented as a Heap to be more effective than for example an Array.\n\n## 3. Hash Tables\n\n- Stores key-value pairs.\n- Like arrays, but not ordered.\n- Why we use them: They're fast!\n- Examples:\n  - Python: Dictionaries\n  - JavaScript: Objects, Maps\n  - Java, Go \u0026 Scala: Maps\n  - Ruby: Hashes\n- Big O:\n  - Insert: O(1)\n  - Deletion: O(1)\n  - Access: O(1)\n\n### Hash Functions\n\n- Should be: Fast, deterministic, distribute evenly\n- Avoiding collisions:\n  - Separate Chaining - Store conflicting values together (allows for more content).\n  - Linear Probing - Store at next vacant destination when conflict happens.\n\n## 4. Graphs\n\n- Set of nodes (or \"vertices\" or \"points\") with a set of connections (edges) between each other.\n- Examples:\n  - Social Networks\n  - Location / Mapping\n  - Shop recommendations\n  - Visual Hierarchy\n  - File System Optimizations\n\n### Types of graphs\n\n- Tree: One path between each node.\n- Directed: Has a beginning and end (like a path to a destination).\n- Undirected: Has no beginning or end (like friendships on Facebook).\n- Weighted: The path has a value (like the length of a path).\n- Unweighted: The path has no value (like who follows who on Instagram).\n\n### Types of edges\n\n- Adjacency List:\n  - List of arrays with connections between different nodes.\n  - Takes up more space.\n  - Slower to iterate over all edges.\n  - Faster to lookup specific edge.\n- Adjacency Matrix:\n  - A matrix of connections between nodes, 1 for true, 0 for false.\n  - Can take up less space.\n  - Faster to iterate over all edges.\n  - Can be slower to lookup specific edge.\n- Big O: (V = Vertices, E = Edges)\n\n  | Operation     | Adjacency List | Adjacency Matrix |\n  | ------------- | -------------- | ---------------- |\n  | Add Vertex    | O(1)           | O(V^2)           |\n  | Add Edge      | O(1)           | O(1)             |\n  | Remove Vertex | O(V+E)         | O(V^2)           |\n  | Remove Edge   | O(V+E)         | O(1)             |\n  | Query         | O(V+E)         | O(1)             |\n  | Storage       | O(V+E)         | O(V^2)           |\n\n### Graph Traversal\n\n- Going through each node and check their connections.\n- Examples:\n  - Peer to peer networking\n  - Web crawlers\n  - Finding closest match\n  - Finding shortest path\n- Depth first: Prioritize going to new nodes before backtracking.\n- Width first: Prioritize backtracking to known nodes before going to new nodes.\n\n### Dijkstra's Algorithm\n\n- Examples:\n  - GPS, finding shortest route\n  - Network Routing, shortest path\n  - Biology, spread of diseases\n  - Airline tickets, cheapest route\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhannasdev%2Fdata-structures","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhannasdev%2Fdata-structures","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhannasdev%2Fdata-structures/lists"}