├── LICENSE ├── README.md └── Data-structure-note.md /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Nuel geek 3.0 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # **MY SHORT NOTE TO DATA STRUCTURE** 2 | ## **Author: [Nuelgeek](https://twitter.com/theNuelgeek) | Software Engr | Smart Contract Developer** 3 | 4 | -------------------- 5 | 6 | **ABOUT :** 7 | - This note will contain a summary of different data structures, algorithms, and some implementation on typescript. These contents are notes I made up from Data structure classes from Frontend masters. 8 | 9 | **AIM :** 10 | - This note is to help you with snippet of data structure and algorithms meanings and how it works. 11 | 12 | - It can be useful for preparation of job interview without the hassle of reading voluminous information. 13 | 14 | - Looking for straight forward contents on Data structure, this is for you. 15 | 16 | 17 | ------------- 18 | 19 | # *! Let's Gooooooooooo* 20 | 21 | 22 | ## What is Data Structure ? 23 | Data structures frame the organization of information so that machines and humans can better understand it. 24 | 25 | ## What is Alogrithm ? 26 | Algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a certain order to get the desired output. 27 | 28 | ## What is Big O ? 29 | Big O is a way to categorize your algorithms time or memory requirements based on input. It is not meant to be an exact measurement. It will not tell you how many CPU cycles it takes, instead it is meant to generalize the growth of your algorithm. 30 | 31 | ## Important Concepts 32 | 1. Growth is with respect to the input 33 | 2. Constants are dropped 34 | 3. Worst case is usually the way we measure 35 | 36 | ------ 37 | 38 | # SEARCH 39 | 40 | - **Linear search** is an alorithm technique, where you must traverse through the array's index to obtain a value. 41 | that is measurable in O(N) . [typescript implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/LinearSearchList.ts) 42 | - A form of search method called **binary search** involves halving the size of an ordered dataset until the target value is located. Measured in 43 | O(logN) or O(NlogN). [typescript implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/BinarySearchList.ts) 44 | 45 | ----------- 46 | 47 | # SORT 48 | - **Bubble sort** is a type of algorithm where a single iteration produces the largest number (data) at the last index till the dataset is sorted. The next iteration won’t include the last index. It is measured in O(N^2). [typescript implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/BubbleSort.ts) 49 | - **A linked list** is a linear collection of data elements whose order is not given by their physical placement in memory. Instead, each element points to the next. It is a data structure consisting of a collection of nodes which together represent a sequence. Runtime is O(1). 50 | - **A Queue** is a specific implementation of a linked list where there is no Bi link to the Node, which is denoted as FIFO (First In First Out) operation. The runtime is N(1). [typescript implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/Queue.ts) 51 | - **A Stack** is a single-Linked list where we get to add to it and remove from the head, denoted as FILO (First In Last Out). Runtime is O(1). [typescript implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/Stack.ts) 52 | 53 | ---- 54 | # ARRAY 55 | 56 | - **Array vs Linked list** 57 | 58 | | Array | Linked list | 59 | | ----------- | ----------- | 60 | | 1. Access to Indices | Indices don’t exist in the list. | 61 | | 2. It is O(1) when you want to write into an array. | It is O(1) when you want to insert into a listext | 62 | | 3. You have to allocate the memory of your array up front, even if you’re not aware of the memory length needed. | Memory are created instantly when a data is added to the node, but it costs a runtime to create the memory. | 63 | | 4. You have options of search methods in your array. E.g. Binary Search etc | Linear search is your only option when you want to search for a data in your list. | 64 | 65 | - **ArrayList** uses the array as the fundament base to perform extra operations on it like Resizing, Pushing, Popping etc. Array list is time-consuming using Enqueue/Dequeue and fast with Push/Pop.[typescript implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/array-test.ts) 66 | - **Array Buffer**, is used when there is some uncertainty about the amount of data or the rate of arrival of the data that will be placed there. 67 | 68 | ------ 69 | # RECURSION 70 | **Recursion** is a type of algorithm that constantly calls its function until the base case is satisfied, or an action is completed. Understanding your base case will help you comprehend recursion better. 71 | 72 | **Three steps make up recursion.** 73 | - Pre; Before recusing, you can do an operation. 74 | - Recuse; Does the calling of the function. 75 | - Post; After recusing, you can execute an operation. 76 | 77 | Even if you don't use these stages directly, it's still vital to be aware of them because pathing depends heavily on them. 78 | [MazeSolver algorithm Implementation to understand recursion](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/MazeSolver.ts) 79 | 80 | *Note :* 81 | - If you have a solid understanding of why you should stop recusing, that reason makes up a solid base case. 82 | - You might ask when should you use a recursion algorithm instead of loop algorithm?; Answer: When there is no defined end or when there is branching factor. 83 | 84 | # QUICK SORT 85 | 86 | Divide and conquer is a strategy used by the **QuickSort algorithm**. 87 | The algorithm selects a pivot element and moves the array's elements in such a way that those that are smaller than the pivot element are moved to the left side and those that are greater are moved to the right side. 88 | The subarrays to the left and right of the pivot element are then sorted repeatedly by the algorithm. The running time of this algorithm is O(NlogN) or O(N^2) 89 | 90 | ------ 91 | # TREE 92 | 93 | The tree is a data structure that starts from a single point and goes all down like roots, the computer’s hard drives, its directories and how it is organized is a good illustration of a tree. 94 | A tree is a structure made up of one node called the root and zero, one, or more subtrees. It can also be empty and have no nodes. 95 | 96 | # TREE TERMINOLOGY 97 | 98 | - **Root:** The most parent node. The First. Adam. 99 | - **Height:** The longest path from the root to the most child node 100 | - **Binary tree:** A tree in which has at most 2 children, at least 0 children 101 | - **General tree:** A tree with 0 or more children 102 | - **Binary search tree:** A tree in which has a specific ordering to the nodes and at most 2 children 103 | - **Leaves:** A node without children 104 | - **Balanced:** A tree is perfectly balanced when any node's left and right children have the same height. 105 | - **Branching factor:** The amount of children a tree has. 106 | 107 | # Traversal | Visiting a Node 108 | There are different ways in which you can visit the nodes of a tree. 109 | - Pre order 110 | - In order 111 | - Post order 112 | 113 | Inorder traversal traverses one subtree of a node, visits the node, and then traverses its other subtree. Preorder traversal visits a node and then traverses both of its subtrees. Postorder traversal traverses both subtrees of a node, then visits the node. 114 | The traversal method makes use of recursion technique while visiting the nodes. The running time of this traversal is O(N). Implementation ([PreOrder](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/BTPreOrder.ts), [InOrder](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/BTInOrder.ts), [PostOrder](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/BTPostOrder.ts)). Note: This type of order is Depth First search | DFS, We implicitly used stack DS for calling the recuse function. 115 | 116 | # TREE SEARCH 117 | **Breath first search:** This is a type of tree search that implicitly makes use of Queue data structure while visiting each node on a tree level. The run time of this data structure is O(N), but if make use of an array list, the run time will be O(N^2). [Breath first search Implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/BTBFS.ts). 118 | 119 | - Note: An Interview question example of comparing two binary trees to see if they equal in both shape and structure. Depth-first search preserves tree shape, while breadth-first search does not. [implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/CompareBinaryTrees.ts). 120 | 121 | # Heap (priority queue) 122 | Heap data structure as a binary tree, where every child and grandchild is smaller (MinHeap) or larger than (MaxHeap) the current node. 123 | 124 | - Whenever a node is added, we must adjust the tree 125 | - Whenever a node is deleted, we must adjust the tree 126 | - There is no traversing in the tree 127 | - Binary is always a complete tree 128 | ------------------------ 129 | **Some cool characteristics** 130 | - It is self-balancing 131 | - It can be used for priority 132 | - Funnest data structure to implement, but easy to get wrong! 133 | 134 | The runtime of this algorithm is O(N log n). [Heap Typescript implementation 135 | ](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/MinHeap.ts). 136 | 137 | # Tries 138 | A trie is a special tree that can compactly store strings. Also known as radix tree, prefix tree, digital tree, you can perceive is as an auto complete e.g., when you swipe through your phone keyboard it auto generates a word for you that’s how a trie works. Runtime O(1). 139 | 140 | # Graphs 141 | Graphs are a series of node with some amount of connection or no connection, and they are connected nodes without roots. 142 | 143 | ## **Terminology of Graphs** 144 | ----------------------- 145 | This is not an exhaustive list of terms, but it is the terms that we may end up using today. 146 | 147 | **Graph Terms** 148 | 149 | - **cCcle:** When you start at Node(x), follow the links, and end back at Node(x). 150 | 151 | - **Acyclic:** A graph that contains no cycles 152 | connected: When every node has a path to another node. 153 | 154 | - **Directed:** When there is a direction to the connections. Think Twitter 155 | 156 | - **Undirected:** !directed. 157 | Weighted: The edges have a weight associated with them. Think Maps. 158 | 159 | - **Dag:** Directed, acyclic graph. 160 | 161 | --------------- 162 | ## **Implementation Terms** 163 | **Node:** a point or vertex on the graph. 164 | 165 | **Edge:** the connection betxit two nodes. 166 | 167 | ---------------- 168 | 169 | The **BigO** is commonly stated in terms of V and E where V stands for vertices and E stands for edges 170 | So O(V * E) means that we will check every vertex, and on every vertex we check every edge 171 | 172 | ------------------------- 173 | ## **How are graphs represented** 174 | - **Adjacency list:** This is a type of list where the indices map to the node. [DFS on Adjacency list typescript implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/DFSGraphList.ts). 175 | 176 | - **Adjacency matrix:** An adjacency matrix is a way of representing a graph as a matrix of booleans (0's and 1's). A finite graph can be represented in the form of a square matrix on a computer. [BFS on Adjacency matrix typescript implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/BFSGraphMatrix.ts). 177 | 178 | - **Dijkstra shortest path search:** Dijkstra's shortest path is an algorithm that finds the shortest paths between nodes in a graph. It produces the shortest path tree with the source node as the root. It is profoundly used in computer networks to generate optimal routes with the aim of minimizing routing costs. Runtime is O(logV(V + E)). [Dijkstra implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/DijkstralList.ts). 179 | 180 | ------------------------- 181 | # Maps & LRU (Least Recently Used) 182 | A Map is a type of fast key lookup data structure that offers a flexible means of indexing into its individual elements. 183 | 184 | **Terms** 185 | - **load factor:** The amount of data points vs the amount of storage (data.len / storage.capacity) 186 | - **key:** a value that is hashable and is used to look up data. The hash has to be consistent. 187 | - **Value:** a value that is associated with a key 188 | collision: when 2 keys map to the same cell. 189 | 190 | # LRU 191 | The Least Recently Used (LRU) Cache mechanism, allowing you to quickly identify which item hasn't been used for the longest amount of time. An LRU cache is a combination of map and linked list data structures. This algorithm makes use of double linked list & Hash maps. [LRU cache typescript implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/LRU.ts). 192 | 193 | ------------------------- 194 | 195 | - ## Thanks for reading my note, if you find this note valuable you can give me a follow on twitter [@the_nuelgeek](https://twitter.com/theNuelgeek) and subscribe to email list on hashnode [Geeks Oasis](https://nuelgeek.hashnode.dev/) 196 | 197 | - ## You can also make a pull request or contact me, if you have any extra data structure / Alogrithm you want to add. 198 | 199 | - ## Contact me for your smart contract development project and smart contract auditng. Next new skill Frontend development. 200 | - ## Feedbacks are highly welcomed. -------------------------------------------------------------------------------- /Data-structure-note.md: -------------------------------------------------------------------------------- 1 | # **MY SHORT NOTE TO DATA STRUCTURE** 2 | ## **Author: [Nuelgeek](https://twitter.com/theNuelgeek) | Software Engr | Smart Contract Developer** 3 | 4 | -------------------- 5 | 6 | **ABOUT :** 7 | - This note will contain a summary of different data structures, algorithms, and some implementation on typescript. These contents are notes I made up from Data structure classes from Frontend masters. 8 | 9 | **AIM :** 10 | - This note is to help you with snippet of data structure and algorithms meanings and how it works. 11 | 12 | - It can be useful for preparation of job interview without the hassle of reading voluminous information. 13 | 14 | - Looking for straight forward contents on Data structure, this is for you. 15 | 16 | 17 | ------------- 18 | 19 | # *! Let's Gooooooooooo* 20 | 21 | 22 | ## What is Data Structure ? 23 | Data structures frame the organization of information so that machines and humans can better understand it. 24 | 25 | ## What is Alogrithm ? 26 | Algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a certain order to get the desired output. 27 | 28 | ## What is Big O ? 29 | Big O is a way to categorize your algorithms time or memory requirements based on input. It is not meant to be an exact measurement. It will not tell you how many CPU cycles it takes, instead it is meant to generalize the growth of your algorithm. 30 | 31 | ## Important Concepts 32 | 1. Growth is with respect to the input 33 | 2. Constants are dropped 34 | 3. Worst case is usually the way we measure 35 | 36 | ------ 37 | 38 | # SEARCH 39 | 40 | - **Linear search** is an alorithm technique, where you must traverse through the array's index to obtain a value. 41 | that is measurable in O(N) . [typescript implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/LinearSearchList.ts) 42 | - A form of search method called **binary search** involves halving the size of an ordered dataset until the target value is located. Measured in 43 | O(logN) or O(NlogN). [typescript implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/BinarySearchList.ts) 44 | 45 | ----------- 46 | 47 | # SORT 48 | - **Bubble sort** is a type of algorithm where a single iteration produces the largest number (data) at the last index till the dataset is sorted. The next iteration won’t include the last index. It is measured in O(N^2). [typescript implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/BubbleSort.ts) 49 | - **A linked list** is a linear collection of data elements whose order is not given by their physical placement in memory. Instead, each element points to the next. It is a data structure consisting of a collection of nodes which together represent a sequence. Runtime is O(1). 50 | - **A Queue** is a specific implementation of a linked list where there is no Bi link to the Node, which is denoted as FIFO (First In First Out) operation. The runtime is N(1). [typescript implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/Queue.ts) 51 | - **A Stack** is a single-Linked list where we get to add to it and remove from the head, denoted as FILO (First In Last Out). Runtime is O(1). [typescript implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/Stack.ts) 52 | 53 | ---- 54 | # ARRAY 55 | 56 | - **Array vs Linked list** 57 | 58 | | Array | Linked list | 59 | | ----------- | ----------- | 60 | | 1. Access to Indices | Indices don’t exist in the list. | 61 | | 2. It is O(1) when you want to write into an array. | It is O(1) when you want to insert into a listext | 62 | | 3. You have to allocate the memory of your array up front, even if you’re not aware of the memory length needed. | Memory are created instantly when a data is added to the node, but it costs a runtime to create the memory. | 63 | | 4. You have options of search methods in your array. E.g. Binary Search etc | Linear search is your only option when you want to search for a data in your list. | 64 | 65 | - **ArrayList** uses the array as the fundament base to perform extra operations on it like Resizing, Pushing, Popping etc. Array list is time-consuming using Enqueue/Dequeue and fast with Push/Pop.[typescript implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/array-test.ts) 66 | - **Array Buffer**, is used when there is some uncertainty about the amount of data or the rate of arrival of the data that will be placed there. 67 | 68 | ------ 69 | # RECURSION 70 | **Recursion** is a type of algorithm that constantly calls its function until the base case is satisfied, or an action is completed. Understanding your base case will help you comprehend recursion better. 71 | 72 | **Three steps make up recursion.** 73 | - Pre; Before recusing, you can do an operation. 74 | - Recuse; Does the calling of the function. 75 | - Post; After recusing, you can execute an operation. 76 | 77 | Even if you don't use these stages directly, it's still vital to be aware of them because pathing depends heavily on them. 78 | [MazeSolver algorithm Implementation to understand recursion](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/MazeSolver.ts) 79 | 80 | *Note :* 81 | - If you have a solid understanding of why you should stop recusing, that reason makes up a solid base case. 82 | - You might ask when should you use a recursion algorithm instead of loop algorithm?; Answer: When there is no defined end or when there is branching factor. 83 | 84 | # QUICK SORT 85 | 86 | Divide and conquer is a strategy used by the **QuickSort algorithm**. 87 | The algorithm selects a pivot element and moves the array's elements in such a way that those that are smaller than the pivot element are moved to the left side and those that are greater are moved to the right side. 88 | The subarrays to the left and right of the pivot element are then sorted repeatedly by the algorithm. The running time of this algorithm is O(NlogN) or O(N^2) 89 | 90 | ------ 91 | # TREE 92 | 93 | The tree is a data structure that starts from a single point and goes all down like roots, the computer’s hard drives, its directories and how it is organized is a good illustration of a tree. 94 | A tree is a structure made up of one node called the root and zero, one, or more subtrees. It can also be empty and have no nodes. 95 | 96 | # TREE TERMINOLOGY 97 | 98 | - **Root:** The most parent node. The First. Adam. 99 | - **Height:** The longest path from the root to the most child node 100 | - **Binary tree:** A tree in which has at most 2 children, at least 0 children 101 | - **General tree:** A tree with 0 or more children 102 | - **Binary search tree:** A tree in which has a specific ordering to the nodes and at most 2 children 103 | - **Leaves:** A node without children 104 | - **Balanced:** A tree is perfectly balanced when any node's left and right children have the same height. 105 | - **Branching factor:** The amount of children a tree has. 106 | 107 | # Traversal | Visiting a Node 108 | There are different ways in which you can visit the nodes of a tree. 109 | - Pre order 110 | - In order 111 | - Post order 112 | 113 | Inorder traversal traverses one subtree of a node, visits the node, and then traverses its other subtree. Preorder traversal visits a node and then traverses both of its subtrees. Postorder traversal traverses both subtrees of a node, then visits the node. 114 | The traversal method makes use of recursion technique while visiting the nodes. The running time of this traversal is O(N). Implementation ([PreOrder](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/BTPreOrder.ts), [InOrder](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/BTInOrder.ts), [PostOrder](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/BTPostOrder.ts)). Note: This type of order is Depth First search | DFS, We implicitly used stack DS for calling the recuse function. 115 | 116 | # TREE SEARCH 117 | **Breath first search:** This is a type of tree search that implicitly makes use of Queue data structure while visiting each node on a tree level. The run time of this data structure is O(N), but if make use of an array list, the run time will be O(N^2). [Breath first search Implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/BTBFS.ts). 118 | 119 | - Note: An Interview question example of comparing two binary trees to see if they equal in both shape and structure. Depth-first search preserves tree shape, while breadth-first search does not. [implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/CompareBinaryTrees.ts). 120 | 121 | # Heap (priority queue) 122 | Heap data structure as a binary tree, where every child and grandchild is smaller (MinHeap) or larger than (MaxHeap) the current node. 123 | 124 | - Whenever a node is added, we must adjust the tree 125 | - Whenever a node is deleted, we must adjust the tree 126 | - There is no traversing in the tree 127 | - Binary is always a complete tree 128 | ------------------------ 129 | **Some cool characteristics** 130 | - It is self-balancing 131 | - It can be used for priority 132 | - Funnest data structure to implement, but easy to get wrong! 133 | 134 | The runtime of this algorithm is O(N log n). [Heap Typescript implementation 135 | ](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/MinHeap.ts). 136 | 137 | # Tries 138 | A trie is a special tree that can compactly store strings. Also known as radix tree, prefix tree, digital tree, you can perceive is as an auto complete e.g., when you swipe through your phone keyboard it auto generates a word for you that’s how a trie works. Runtime O(1). 139 | 140 | # Graphs 141 | Graphs are a series of node with some amount of connection or no connection, and they are connected nodes without roots. 142 | 143 | ## **Terminology of Graphs** 144 | ----------------------- 145 | This is not an exhaustive list of terms, but it is the terms that we may end up using today. 146 | 147 | **Graph Terms** 148 | 149 | - **cCcle:** When you start at Node(x), follow the links, and end back at Node(x). 150 | 151 | - **Acyclic:** A graph that contains no cycles 152 | connected: When every node has a path to another node. 153 | 154 | - **Directed:** When there is a direction to the connections. Think Twitter 155 | 156 | - **Undirected:** !directed. 157 | Weighted: The edges have a weight associated with them. Think Maps. 158 | 159 | - **Dag:** Directed, acyclic graph. 160 | 161 | --------------- 162 | ## **Implementation Terms** 163 | **Node:** a point or vertex on the graph. 164 | 165 | **Edge:** the connection betxit two nodes. 166 | 167 | ---------------- 168 | 169 | The **BigO** is commonly stated in terms of V and E where V stands for vertices and E stands for edges 170 | So O(V * E) means that we will check every vertex, and on every vertex we check every edge 171 | 172 | ------------------------- 173 | ## **How are graphs represented** 174 | - **Adjacency list:** This is a type of list where the indices map to the node. [DFS on Adjacency list typescript implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/DFSGraphList.ts). 175 | 176 | - **Adjacency matrix:** An adjacency matrix is a way of representing a graph as a matrix of booleans (0's and 1's). A finite graph can be represented in the form of a square matrix on a computer. [BFS on Adjacency matrix typescript implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/BFSGraphMatrix.ts). 177 | 178 | - **Dijkstra shortest path search:** Dijkstra's shortest path is an algorithm that finds the shortest paths between nodes in a graph. It produces the shortest path tree with the source node as the root. It is profoundly used in computer networks to generate optimal routes with the aim of minimizing routing costs. Runtime is O(logV(V + E)). [Dijkstra implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/DijkstralList.ts). 179 | 180 | ------------------------- 181 | # Maps & LRU (Least Recently Used) 182 | A Map is a type of fast key lookup data structure that offers a flexible means of indexing into its individual elements. 183 | 184 | **Terms** 185 | - **load factor:** The amount of data points vs the amount of storage (data.len / storage.capacity) 186 | - **key:** a value that is hashable and is used to look up data. The hash has to be consistent. 187 | - **Value:** a value that is associated with a key 188 | collision: when 2 keys map to the same cell. 189 | 190 | # LRU 191 | The Least Recently Used (LRU) Cache mechanism, allowing you to quickly identify which item hasn't been used for the longest amount of time. An LRU cache is a combination of map and linked list data structures. This algorithm makes use of double linked list & Hash maps. [LRU cache typescript implementation](https://github.com/TheNuelgeek/Data-Structure-Algorthim-kata-machine/blob/master/src/day1/LRU.ts). 192 | 193 | ------------------------- 194 | 195 | - ## Thanks for reading my note, if you find this note valuable you can give me a follow on twitter [@the_nuelgeek](https://twitter.com/theNuelgeek) and subscribe to email list on hashnode [Geeks Oasis](https://nuelgeek.hashnode.dev/) 196 | 197 | - ## You can also make a pull request or contact me, if you have any extra data structure / Alogrithm you want to add. 198 | 199 | - ## Contact me for your smart contract development project and smart contract auditng. Next new skill Frontend development. 200 | - ## Feedbacks are highly welcomed. --------------------------------------------------------------------------------