62
62
* pop* , which removes the most recently added element
63
63
* Last in, first out data structure (LIFO)
64
64
* Time Complexity:
65
- * Access: ` O(n) `
66
- * Search: ` O(n) `
67
- * Insert: ` O(1) `
68
- * Remove: ` O(1) `
65
+ * Access: ` O(n) `
66
+ * Search: ` O(n) `
67
+ * Insert: ` O(1) `
68
+ * Remove: ` O(1) `
69
69
70
70
### Queue
71
71
* A * Queue* is a collection of elements, supporting two principle operations: * enqueue* , which inserts an element
72
72
into the queue, and * dequeue* , which removes an element from the queue
73
73
* First in, first out data structure (FIFO)
74
74
* Time Complexity:
75
- * Access: ` O(n) `
76
- * Search: ` O(n) `
77
- * Insert: ` O(1) `
78
- * Remove: ` O(1) `
75
+ * Access: ` O(n) `
76
+ * Search: ` O(n) `
77
+ * Insert: ` O(1) `
78
+ * Remove: ` O(1) `
79
79
80
80
### Tree
81
81
* A * Tree* is an undirected, connected, acyclic graph
93
93
node must be greater than or equal to any value stored in the left sub-tree, and less than or equal to any value stored
94
94
in the right sub-tree
95
95
* Time Complexity:
96
- * Access: ` O(log(n)) `
97
- * Search: ` O(log(n)) `
98
- * Insert: ` O(log(n)) `
99
- * Remove: ` O(log(n)) `
96
+ * Access: ` O(log(n)) `
97
+ * Search: ` O(log(n)) `
98
+ * Insert: ` O(log(n)) `
99
+ * Remove: ` O(log(n)) `
100
100
101
101
<img src =" /Images/BST.png?raw=true " alt =" Binary Search Tree " width =" 400 " height =" 500 " >
102
102
115
115
a range of values, and by combining that sum with additional ranges encountered during an upward traversal to the root, the prefix
116
116
sum is calculated
117
117
* Time Complexity:
118
- * Range Sum: ` O(log(n)) `
119
- * Update: ` O(log(n)) `
118
+ * Range Sum: ` O(log(n)) `
119
+ * Update: ` O(log(n)) `
120
120
121
121
![ Alt text] ( /Images/fenwickTree.png?raw=true " Fenwick Tree ")
122
122
123
123
### Segment Tree
124
124
* A Segment tree, is a tree data structure for storing intervals, or segments. It allows querying which of the stored segments contain
125
125
a given point
126
126
* Time Complexity:
127
- * Range Query: ` O(log(n)) `
128
- * Update: ` O(log(n)) `
127
+ * Range Query: ` O(log(n)) `
128
+ * Update: ` O(log(n)) `
129
129
130
130
![ Alt text] ( /Images/segmentTree.png?raw=true " Segment Tree ")
131
131
@@ -136,9 +136,9 @@ A heap can be classified further as either a "max heap" or a "min heap". In a ma
136
136
than or equal to those of the children and the highest key is in the root node. In a min heap, the keys of parent nodes are less than
137
137
or equal to those of the children and the lowest key is in the root node
138
138
* Time Complexity:
139
- * Access Max / Min: ` O(1) `
140
- * Insert: ` O(log(n)) `
141
- * Remove Max / Min: ` O(log(n)) `
139
+ * Access Max / Min: ` O(1) `
140
+ * Insert: ` O(log(n)) `
141
+ * Remove Max / Min: ` O(log(n)) `
142
142
143
143
<img src =" /Images/heap.png?raw=true " alt =" Max Heap " width =" 400 " height =" 500 " >
144
144
@@ -177,9 +177,9 @@ or equal to those of the children and the lowest key is in the root node
177
177
#### Quicksort
178
178
* Stable: ` No `
179
179
* Time Complexity:
180
- * Best Case: ` O(nlog(n)) `
181
- * Worst Case: ` O(n^2) `
182
- * Average Case: ` O(nlog(n)) `
180
+ * Best Case: ` O(nlog(n)) `
181
+ * Worst Case: ` O(n^2) `
182
+ * Average Case: ` O(nlog(n)) `
183
183
184
184
![ Alt text] ( /Images/quicksort.gif?raw=true " Quicksort ")
185
185
@@ -188,29 +188,29 @@ or equal to those of the children and the lowest key is in the root node
188
188
left subarray and right subarray and then merges the two sorted halves
189
189
* Stable: ` Yes `
190
190
* Time Complexity:
191
- * Best Case: ` O(nlog(n)) `
192
- * Worst Case: ` O(nlog(n)) `
193
- * Average Case: ` O(nlog(n)) `
191
+ * Best Case: ` O(nlog(n)) `
192
+ * Worst Case: ` O(nlog(n)) `
193
+ * Average Case: ` O(nlog(n)) `
194
194
195
195
![ Alt text] ( /Images/mergesort.gif?raw=true " Mergesort ")
196
196
197
197
#### Bucket Sort
198
198
* * Bucket Sort* is a sorting algorithm that works by distributing the elements of an array into a number of buckets. Each bucket
199
199
is then sorted individually, either using a different sorting algorithm, or by recursively applying the bucket sorting algorithm
200
200
* Time Complexity:
201
- * Best Case: ` Ω(n + k) `
202
- * Worst Case: ` O(n^2) `
203
- * Average Case:` Θ(n + k) `
201
+ * Best Case: ` Ω(n + k) `
202
+ * Worst Case: ` O(n^2) `
203
+ * Average Case:` Θ(n + k) `
204
204
205
205
![ Alt text] ( /Images/bucketsort.png?raw=true " Bucket Sort ")
206
206
207
207
#### Radix Sort
208
208
* * Radix Sort* is a sorting algorithm that like bucket sort, distributes elements of an array into a number of buckets. However, radix
209
209
sort differs from bucket sort by 're-bucketing' the array after the initial pass as opposed to sorting each bucket and merging
210
210
* Time Complexity:
211
- * Best Case: ` Ω(nk) `
212
- * Worst Case: ` O(nk) `
213
- * Average Case: ` Θ(nk) `
211
+ * Best Case: ` Ω(nk) `
212
+ * Worst Case: ` O(nk) `
213
+ * Average Case: ` Θ(nk) `
214
214
215
215
### Graph Algorithms
216
216
@@ -243,8 +243,8 @@ or equal to those of the children and the lowest key is in the root node
243
243
* Although it is slower than Dijkstra's, it is more versatile, as it is capable of handling graphs in which some of the edge weights are
244
244
negative numbers
245
245
* Time Complexity:
246
- * Best Case: ` O(|E|) `
247
- * Worst Case: ` O(|V||E|) `
246
+ * Best Case: ` O(|E|) `
247
+ * Worst Case: ` O(|V||E|) `
248
248
249
249
![ Alt text] ( /Images/bellman-ford.gif?raw=true " Bellman-Ford ")
250
250
@@ -253,9 +253,9 @@ or equal to those of the children and the lowest key is in the root node
253
253
no negative cycles
254
254
* A single execution of the algorithm will find the lengths (summed weights) of the shortest paths between * all* pairs of nodes
255
255
* Time Complexity:
256
- * Best Case: ` O(|V|^3) `
257
- * Worst Case: ` O(|V|^3) `
258
- * Average Case: ` O(|V|^3) `
256
+ * Best Case: ` O(|V|^3) `
257
+ * Worst Case: ` O(|V|^3) `
258
+ * Average Case: ` O(|V|^3) `
259
259
260
260
#### Prim's Algorithm
261
261
* * Prim's Algorithm* is a greedy algorithm that finds a minimum spanning tree for a weighted undirected graph. In other words, Prim's find a
0 commit comments