{"id":22688080,"url":"https://github.com/9andresc/dsna","last_synced_at":"2025-03-29T16:12:29.604Z","repository":{"id":79350702,"uuid":"167418284","full_name":"9andresc/dsna","owner":"9andresc","description":"Data Structures 'N' Algorithms","archived":false,"fork":false,"pushed_at":"2019-02-08T19:27:28.000Z","size":52,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-04T16:50:20.507Z","etag":null,"topics":["algorithms","data-structures","python"],"latest_commit_sha":null,"homepage":"","language":"Python","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/9andresc.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}},"created_at":"2019-01-24T18:44:20.000Z","updated_at":"2023-03-08T03:35:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"c3995ef9-273e-40b3-ac1e-145c58231b5b","html_url":"https://github.com/9andresc/dsna","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/9andresc%2Fdsna","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/9andresc%2Fdsna/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/9andresc%2Fdsna/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/9andresc%2Fdsna/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/9andresc","download_url":"https://codeload.github.com/9andresc/dsna/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246207509,"owners_count":20740723,"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":["algorithms","data-structures","python"],"created_at":"2024-12-10T00:12:57.631Z","updated_at":"2025-03-29T16:12:29.597Z","avatar_url":"https://github.com/9andresc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DSNA (Data Structures 'N' Algorithms)\n\nMy practices of Data Structures and Algorithms using several languages\n(just for fun) in the long run.\n\n\u003e The Big O describes how much an algorithm slows down as the input grows.\n\n## Data Structures\n\n### Binary Search Tree\n\n#### Description\n\nIs a special kind of binary tree in which all nodes are ordered, this means\nthat every node must be greater than or equal to any node in left sub-tree, and\nless than or equal to any node in the right sub-tree.\n\n#### Time complexity in the average case\n\n| Search    | Insertion | Deletion  |\n| --------- | --------- | --------- |\n| O(log(n)) | O(log(n)) | O(log(n)) |\n\n#### Time complexity in the worst case\n\n| Search | Insertion | Deletion |\n| ------ | --------- | -------- |\n| O(n)   | O(n)      | O(n)     |\n\n#### Implementations\n\n- Python 3\n\n### Binary Tree\n\n#### Description\n\nIt a simple kind of tree in which parent nodes have at most two child nodes,\nwhich are referred to as the left child and the right child. There a few ways\nto traverse a tree, the two most general ways are:\n\n- BFS (Breadth-first search): It starts at the tree root and explores all of\n  the siblings nodes at the present level prior to moving on to the nodes at the\n  next level.\n\n- DFS (Depth-first search): It starts at the tree root and explores as far as\n  possible along each branch before backtracking. This method has different\n  options to traverse a tree, which are:\n\n  - Pre-order: Check off a node as you see it before you traverse any further\n    in the tree.\n  - In-order: Check off a node when you've seen its left child and come back to\n    it.\n  - Post-order: Check off a node after you've seen all its children and come\n    back to it.\n\n#### Time complexity\n\n| Search | Insertion | Deletion |\n| ------ | --------- | -------- |\n| O(n)   | O(log(n)) | O(n)     |\n\n#### Implementations\n\n- Python 3\n\n### Graph\n\n#### Description\n\nIs a set of **vertices** that can contain data, these vertices can be connected\nthrough a series of **edges**, which could hold data as well. Graphs are used to\nsolve many real-life problems, one of the most common are networks.\n\nEdges can have a **direction**, meaning the relationship between two nodes only\napplies one way and not the other. Thus, a **directed graph** is a graph where\nits edges have a sense of direction.\n\nUnlike trees, graphs can have **cycles**. A cycle happens when you can start at\none node and follow edges all the way back to that node. Cycles can be harmful\nwhile programming because they can cause infinite loops. One way to avoid cycles\nis working with a **directed acyclic graph** (DAG).\n\nA **disconnected graph** has some vertex or group of vertices that is\ndisconnected from the rest of the graph. Thus, a **connected graph** has no\ndisconnected vertices.\n\nA directed graph is **weakly connected** when only replacing all of the\ndirected edges with undirected edges can cause it to be connected.\n\n**Strongly connected** directed graphs must have a path from every node and\nevery other node. So, there must be a path from A to B and B to A.\n\nThere are several ways to represent connections on graphs that only use lists,\nthose are:\n\n- Edge list: the edges themselves are represented by a list of two elements,\n  these elements are normally the IDs of the vertices.\n- Adjacency list: the vertices normally have an ID number that corresponds to\n  an index in the array, in which each slot is used to store a list of nodes\n  that the node with our ID is adjacent to.\n- Adjacency matrix: the indices in the outer array and inner arrays represent\n  nodes with those IDs. If there's an edge between two nodes, a 1 goes into the\n  two slots that intersect the corresponding indices.\n\n#### Time complexity\n\n| Search                 |\n| ---------------------- |\n| O( \\| E \\| + \\| N \\| ) |\n\n#### Implementations\n\n- Python 3\n\n### Hash Table\n\n#### Description\n\nIs a kind of list which stores unordered key/value pairs. To select where to\nstore each incoming value there's a function called **hash function** which\nmaps the values with each key. To measure how loaded a Hash Table is, you\nshould divide the number of possible values by the size of the table, this is\noften called the **load factor**. It is possible that some values map to the\nsame keys twice or more, in that case a **collusion** occurs. To resolve such\ncollisions there are **rehashing functions**.\n\n#### Time complexity in the average case\n\n| Search | Insertion | Deletion |\n| ------ | --------- | -------- |\n| O(1)   | O(1)      | O(1)     |\n\n#### Time complexity in the worst case\n\n| Search | Insertion | Deletion |\n| ------ | --------- | -------- |\n| O(n)   | O(n)      | O(n)     |\n\n#### Implementations\n\n- Python 3\n\n### Heap\n\n#### Description\n\nIs a tree-based data structure which is essentially an almost **complete tree**\nthat satisfies the **heap property**: if P is a parent node of node N, then the\nvalue of P is either greater than or equal to (in **max heap**) or less than or\nequal to (in a **min heap**) the value of N. The heap is a very efficient\nimplementation of a **priority queue**, and if fact priority queues are often\nreferred to as \"heaps\", regardless of how they may be implemented.\nIn a heap, the highest (or lowest) priority value is always stored at the root.\nHowever, a heap is not a sorted structure; it can be regarded as being\npartially ordered. A heap is a useful data structure when it is necessary to\nrepeatedly remove the node with the highest (or lowest) priority.\n\n#### Time complexity\n\n| Search | Insertion | Deletion  |\n| ------ | --------- | --------- |\n| O(n)   | O(log(n)) | O(log(n)) |\n\n#### Implementations\n\n- Python 3\n\n### Linked List\n\n#### Description\n\nIs a linear collection of data elements, whose order is not given by their\nphysical placement in memory. Instead, each element points to the next.\n\n#### Time complexity\n\n| Search | Insertion | Deletion |\n| ------ | --------- | -------- |\n| O(n)   | O(1)      | O(1)     |\n\n#### Implementations\n\n- Python 3\n\n### Queue\n\n#### Description\n\nIs a collection in which the elements are kept in order and the principal\noperations on the collection are the addition of elements to the rear terminal\nposition, known as **enqueue**, and removal of elements from the front terminal\nposition, known as **dequeue**.\n\n#### Time complexity\n\n| Search | Insertion | Deletion |\n| ------ | --------- | -------- |\n| O(n)   | O(1)      | O(1)     |\n\n#### Implementations\n\n- Python 3\n\n### Red-Black Tree\n\n#### Description\n\nIt's the most common example of a self-balancing tree, which tries to minimize\nthe number of levels that it uses, and its nodes might have some additional\nproperties. A RBT have a few rules to ensure that it never gets too unbalanced,\nwhich are:\n\n- Every node has a property called color which can be either red or black.\n- The root node must be black.\n- There are no two adjacent red nodes (A red node cannot have a red parent or\n  red child).\n- Every path from a node to its descendant null nodes must contain the same\n  number of black nodes.\n\nIt also follows the rules of a Binary Search Tree.\n\n#### Time complexity\n\n| Search    | Insertion | Deletion  |\n| --------- | --------- | --------- |\n| O(log(n)) | O(log(n)) | O(log(n)) |\n\n#### Implementations\n\n- Python 3\n\n### Stack\n\n#### Description\n\nIs a basic data structure that can be logically thought of as a linear\nstructure represented by a real physical stack or pile, a structure where\ninsertion and deletion of items takes place at one end called top of the stack.\n\n#### Time complexity\n\n| Search | Insertion | Deletion |\n| ------ | --------- | -------- |\n| O(n)   | O(1)      | O(1)     |\n\n#### Implementations\n\n- Python 3\n\n## Algorithms\n\n### Binary Search\n\n#### Description\n\nIt halves your **ordered** array and compares your value with the middle\nelement. If your value is equal to the middle element it returns\n**the index of the later**, but if it's less than the middle element, it\nshould do the same process in the left halve, and if it's greater, it will\nsearch on the right halve. This task will go on until it matches the element\nwith your value or there are no more halves, in which case, it will return **-1**.\n\n#### Time complexity\n\n| Average      | Worst        |\n| ------------ | ------------ |\n| O(n\\*log(n)) | O(n\\*log(n)) |\n\n#### Iterative implementations\n\n- Python 3\n\n#### Recursive implementations\n\n- Python 3\n\n### Bubble Sort\n\n#### Description\n\nIt iterates through your whole array comparing adjacent pair of elements to\nmove all the bigger elements to the right side and leave the remaining elements\nin the left side. This same process is repeatedly made until the list is fully sorted.\n\n#### Time complexity\n\n| Average | Worst  |\n| ------- | ------ |\n| O(n^2)  | O(n^2) |\n\n#### Iterative implementations\n\n- Python 3\n\n#### Recursive implementations\n\n- Python 3\n\n### Merge Sort\n\n#### Description\n\nIt breaks down your array into n subarrays, each containing one element. Then, it\nrepeatedly merges adjacent subarrays to produce new sorted subarrays until there's\nonly one subarray remaining. This will be your sorted array.\n\n#### Time complexity\n\n| Average      | Worst        |\n| ------------ | ------------ |\n| O(n\\*log(n)) | O(n\\*log(n)) |\n\n#### Iterative implementations\n\n- Python 3\n\n#### Recursive implementations\n\n- Python 3\n\n### Quick Sort\n\n#### Description\n\nIt chooses the **last element** of your array as a pivot and starts to iterate from\nthe first element comparing all the elements with the pivot. The ones that are less\nthan the pivot will be in the left side of the final position of the pivot and the\nothers that are greater will be in the right side of the pivot. This same process\nwill happen on the **left** and **right** side until all the elements are in their\nfinal positions.\n\n#### Time complexity\n\n| Average      | Worst  |\n| ------------ | ------ |\n| O(n\\*log(n)) | O(n^2) |\n\n#### Iterative implementations\n\n- Python 3\n\n#### Recursive implementations\n\n- Python 3\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F9andresc%2Fdsna","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F9andresc%2Fdsna","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F9andresc%2Fdsna/lists"}