You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: notes/data_structures.md
+6-20Lines changed: 6 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,9 @@
3
3
In computer science, a _collection_ (often interchangeably referred to as a _container_) is a sophisticated data structure designed to hold multiple entities, these could be simple elements like numbers or text strings, or more complex objects like user-defined structures. Collections play a critical role in helping you store, organize, and manipulate different types of data in your programs.
4
4
5
5
1. At **The Abstract Level**, we focus on the conceptual understanding of collections, defining what they are and their characteristics. This includes how they store and retrieve items, whether it's based on a specific order (as in arrays or lists) or using unique keys (as in dictionaries or maps).
6
-
2.**The Machine Level** refers to the practical implementation of collections, where we concentrate on efficiently realizing the abstract models. Factors such as memory usage, operation speeds (insertion, deletion, search), and flexibility are crucial in determining the most suitable data structures and algorithms for a particular task.
6
+
2.**The Machine Level** refers to the practical implementation of collections, where we concentrate on efficiently realizing the abstract models. Factors like memory usage, operation speeds (insertion, deletion, search), and flexibility help determine the best data structures and algorithms for a specific task.
7
7
8
-
Understanding and studying collections in-depth is crucial for every programmer. This knowledge empowers you to choose the most appropriate collection type for a given task, leading to programs that are not only more efficient in terms of time and space complexities, but also much more maintainable and robust due to clear structure and organization.
8
+
Every programmer benefits from thoroughly understanding and studying collections. This knowledge empowers you to choose the most appropriate collection type for a given task, leading to programs that are not only more efficient in terms of time and space complexities, but also much more maintainable and robust due to clear structure and organization.
@@ -48,8 +48,6 @@ Here are some standard operations associated with linked lists:
48
48
49
49
#### Time Complexity
50
50
51
-
Understanding the time complexity of basic operations is key to efficient use of linked lists:
52
-
53
51
| Operation | Average case | Worst case |
54
52
| --- | --- | --- |
55
53
| Access |`O(n)`|`O(n)`|
@@ -102,8 +100,6 @@ Some of the commonly used operations for vectors are:
102
100
103
101
#### Time Complexity
104
102
105
-
A thorough understanding of the time complexity of basic operations is key to efficient use of vectors:
106
-
107
103
| Operation | Average case | Worst case |
108
104
| --- | --- | --- |
109
105
| Access |`O(1)`|`O(1)`|
@@ -154,8 +150,6 @@ Stacks are incredibly versatile and are used in a multitude of applications, inc
154
150
155
151
#### Time Complexity
156
152
157
-
Knowing the time complexity of stack operations is crucial for writing efficient code:
158
-
159
153
| Operation | Average case | Worst case |
160
154
| --- | --- | --- |
161
155
| Access |`O(n)`|`O(n)`|
@@ -193,7 +187,7 @@ The standard operations associated with a queue are:
193
187
*`enqueue(element)`: This method adds a new element to the end of the queue.
194
188
*`dequeue()`: This method returns the front element of the queue and simultaneously removes it.
195
189
*`front()`: This method simply returns the front element without removing it from the queue, giving a peek at the next item to be dequeued.
196
-
*`is_empty()`: This method checks if the queue is empty, a crucial operation before attempting to `dequeue()` or `front()` to avoid errors.
190
+
*`is_empty()`: This method checks if the queue is empty, an important step before calling `dequeue()` or `front()` to prevent errors.
197
191
198
192
#### Practical Applications
199
193
@@ -215,8 +209,6 @@ While stacks and queues are similar data structures, they differ in several key
215
209
216
210
#### Time Complexity
217
211
218
-
Understanding the time complexity of queue operations is critical for writing efficient code:
219
-
220
212
| Operation | Average case | Worst case |
221
213
| --- | --- | --- |
222
214
| Access |`O(n)`|`O(n)`|
@@ -262,14 +254,12 @@ The basic operations of a heap are as follows:
262
254
263
255
Heaps are versatile and find widespread use across various computational problems:
264
256
265
-
- In **graph algorithms**, heaps play a crucial role in well-known algorithms like Dijkstra's algorithm for finding the shortest paths and Prim's algorithm for constructing the minimum spanning tree.
257
+
- In **graph algorithms**, heaps are used in algorithms like Dijkstra's for finding shortest paths and Prim's for constructing minimum spanning trees.
266
258
-**Priority queues** are efficiently implemented using heaps, as they provide fast insertion and extraction of the highest or lowest priority elements.
267
259
- In **sorting**, the heap sort algorithm utilizes heap properties to sort an array in-place, achieving a worst-case time complexity of **$O(n \log n)$**.
268
260
269
261
#### Time Complexity of Heap Operations
270
262
271
-
The time complexity of standard heap operations is as follows:
272
-
273
263
| Operation | Average case |
274
264
| --- | --- |
275
265
| Find min/max |`O(1)`|
@@ -361,7 +351,7 @@ The AVL tree's self-balancing property lends itself to various applications, suc
361
351
362
352
- Implementing associative arrays or sets in programming languages.
363
353
- Database storage and indexing, where rapid data retrieval is essential.
364
-
- Priority queues and dictionaries, where maintaining order is crucial.
354
+
- Priority queues and dictionaries, where maintaining order matters.
365
355
- Word suggestion systems and spell checkers, which benefit from fast lookups.
366
356
- Networking algorithms and data compression, requiring efficient data structure.
367
357
@@ -376,8 +366,6 @@ AVL trees support standard BST operations with some modifications to maintain ba
376
366
377
367
#### Time Complexity of AVL Tree Operations
378
368
379
-
Thanks to their self-balancing property, AVL trees ensure logarithmic time complexity for essential operations, even in the worst-case scenario.
380
-
381
369
| Operation | Average | Worst |
382
370
| --- | --- | --- |
383
371
| Access |`O(log n)`|`O(log n)`|
@@ -394,7 +382,7 @@ The key to maintaining AVL trees' balance is the application of rotation operati
394
382
3.**Right-left rotation** is necessary when the right subtree of a node is taller, but the right child's left subtree is taller than its right subtree. This rotation involves first applying a right rotation on the right child, followed by a left rotation on the original node, with height updates for all affected nodes.
395
383
4.**Left-right rotation** is applied when the left subtree of a node is taller, and the left child's right subtree is taller than its left subtree. The process starts with a left rotation on the left child, followed by a right rotation on the original node, and concludes with height updates.
396
384
397
-
These rotations ensure that AVL trees maintain their crucial property of balance, offering consistently high performance.
385
+
These rotations keep AVL trees balanced, ensuring consistent performance.
@@ -440,8 +428,6 @@ Red-Black trees support typical BST operations, albeit with additional steps to
440
428
441
429
#### Time Complexity of Red-Black Tree Operations
442
430
443
-
Due to their self-balancing nature, Red-Black trees ensure efficient performance even in the worst-case scenarios, with a logarithmic time complexity for key operations:
0 commit comments