Skip to content

Commit cea2ebd

Browse files
authored
Update data_structures.md
1 parent d01b4f7 commit cea2ebd

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

notes/data_structures.md

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
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.
44

55
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.
77

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.
99

1010
![G70oT](https://user-images.githubusercontent.com/37275728/185710905-8acd7541-e8ed-4439-a644-5d739b39e783.png)
1111

@@ -48,8 +48,6 @@ Here are some standard operations associated with linked lists:
4848

4949
#### Time Complexity
5050

51-
Understanding the time complexity of basic operations is key to efficient use of linked lists:
52-
5351
| Operation | Average case | Worst case |
5452
| --- | --- | --- |
5553
| Access | `O(n)` | `O(n)` |
@@ -102,8 +100,6 @@ Some of the commonly used operations for vectors are:
102100

103101
#### Time Complexity
104102

105-
A thorough understanding of the time complexity of basic operations is key to efficient use of vectors:
106-
107103
| Operation | Average case | Worst case |
108104
| --- | --- | --- |
109105
| Access | `O(1)` | `O(1)` |
@@ -154,8 +150,6 @@ Stacks are incredibly versatile and are used in a multitude of applications, inc
154150

155151
#### Time Complexity
156152

157-
Knowing the time complexity of stack operations is crucial for writing efficient code:
158-
159153
| Operation | Average case | Worst case |
160154
| --- | --- | --- |
161155
| Access | `O(n)` | `O(n)` |
@@ -193,7 +187,7 @@ The standard operations associated with a queue are:
193187
* `enqueue(element)`: This method adds a new element to the end of the queue.
194188
* `dequeue()`: This method returns the front element of the queue and simultaneously removes it.
195189
* `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.
197191

198192
#### Practical Applications
199193

@@ -215,8 +209,6 @@ While stacks and queues are similar data structures, they differ in several key
215209

216210
#### Time Complexity
217211

218-
Understanding the time complexity of queue operations is critical for writing efficient code:
219-
220212
| Operation | Average case | Worst case |
221213
| --- | --- | --- |
222214
| Access | `O(n)` | `O(n)` |
@@ -262,14 +254,12 @@ The basic operations of a heap are as follows:
262254

263255
Heaps are versatile and find widespread use across various computational problems:
264256

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.
266258
- **Priority queues** are efficiently implemented using heaps, as they provide fast insertion and extraction of the highest or lowest priority elements.
267259
- 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)$**.
268260

269261
#### Time Complexity of Heap Operations
270262

271-
The time complexity of standard heap operations is as follows:
272-
273263
| Operation | Average case |
274264
| --- | --- |
275265
| Find min/max | `O(1)` |
@@ -361,7 +351,7 @@ The AVL tree's self-balancing property lends itself to various applications, suc
361351

362352
- Implementing associative arrays or sets in programming languages.
363353
- 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.
365355
- Word suggestion systems and spell checkers, which benefit from fast lookups.
366356
- Networking algorithms and data compression, requiring efficient data structure.
367357

@@ -376,8 +366,6 @@ AVL trees support standard BST operations with some modifications to maintain ba
376366

377367
#### Time Complexity of AVL Tree Operations
378368

379-
Thanks to their self-balancing property, AVL trees ensure logarithmic time complexity for essential operations, even in the worst-case scenario.
380-
381369
| Operation | Average | Worst |
382370
| --- | --- | --- |
383371
| Access | `O(log n)` | `O(log n)` |
@@ -394,7 +382,7 @@ The key to maintaining AVL trees' balance is the application of rotation operati
394382
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.
395383
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.
396384

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.
398386

399387
* [C++](https://github.com/djeada/Algorithms-And-Data-Structures/tree/master/src/collections_and_containers/cpp/avl_tree)
400388
* [Python](https://github.com/djeada/Algorithms-And-Data-Structures/tree/master/src/collections_and_containers/python/avl_tree)
@@ -440,8 +428,6 @@ Red-Black trees support typical BST operations, albeit with additional steps to
440428

441429
#### Time Complexity of Red-Black Tree Operations
442430

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:
444-
445431
| Operation | Average | Worst |
446432
| --- | --- | --- |
447433
| Access | `O(log n)` | `O(log n)` |

0 commit comments

Comments
 (0)