Skip to content

Commit 7a66fd5

Browse files
committed
Add DSA 101 contents
1 parent c49379b commit 7a66fd5

File tree

7 files changed

+168
-0
lines changed

7 files changed

+168
-0
lines changed

archetypes/note.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: '{{ replace .File.ContentBaseName "-" " " | title }}'
3+
summary: '{{ replace .File.ContentBaseName "-" " " | title }}'
4+
description: '{{ replace .File.ContentBaseName "-" " " | title }}'
5+
disableShare: true
6+
editPost:
7+
disabled: true
8+
hideSummary: false
9+
comments: false
10+
searchHidden: true
11+
hiddenInHomeList: true
12+
private: true
13+
---
Binary file not shown.
10.3 KB
Binary file not shown.
Binary file not shown.
6.6 KB
Binary file not shown.
Binary file not shown.

content/notes/dsa-101/index.md

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
---
2+
title: 'Data Structure and Algorithms 101'
3+
summary: 'Data Structure and Algorithms Notes'
4+
description: 'Data Structure and Algorithms Notes'
5+
disableShare: true
6+
editPost:
7+
disabled: true
8+
hideSummary: false
9+
comments: false
10+
searchHidden: true
11+
hiddenInHomeList: true
12+
private: true
13+
---
14+
15+
## Solving a Coding Question in an Interview
16+
17+
1. If we are dealing with **top/maximum/minimum/closest** 'K' elements among 'N' elements, we will be using a **Heap**.
18+
2. If the given input is a **sorted array or a list**, we will either be using **Binary Search** or the **Two Pointers** strategy.
19+
3. If we need to try all **combinations (or permutations)** of the input, we can either use **Backtracking** or **Breadth First Search**.
20+
4. Most of the questions related to **Trees** or **Graphs** can be solved either through **Breadth First Search** or **Depth First Search**.
21+
5. Every **recursive** solution can be converted to an **iterative** solution using **Stack**.
22+
6. For a problem involving arrays, if there exists a solution in **O(n^2)** time and **O(1)** space, there must exist two other solutions:
23+
24+
- Using a **HashMap or a Set** for **O(n)** time and **O(n)** space,
25+
- Using **sorting** for **O(n log n)** time and **O(1)** space.
26+
27+
7. If a problem is asking for **optimization** (e.g., maximization or minimization), we will be using **Dynamic Programming**.
28+
8. If we need to find some common **substring** among a set of strings, we will be using a **HashMap** or a **Trie**.
29+
9. If we need to **search/manipulate** a bunch of strings, **Trie** will be the best data structures.
30+
10. If the problem is related to a **LinkedList** and we can't use extra space, then use the **Fast & Slow Pointer** approach.
31+
32+
## Big O - Time Complexity
33+
34+
Big-O notation is a mathematical notation that is used to describe the performance or complexity of an algorithm, specifically how long an algorithm takes to run as the input size grows.
35+
36+
Understanding Big-O notation is essential for software engineers, as it allows them to analyze and compare the efficiency of different algorithms and make informed decisions about which one to use in a given situation.
37+
38+
![Time Complexity](img/time-complexity.webp#center)
39+
40+
![Understanding Big O](img/understanding-big-o.webp)
41+
42+
## Space Complexity
43+
44+
- Primitive variables (booleans, numbers, undefined, null) are constant space O(1)
45+
- Strings require O(n) space (where n is the string length)
46+
- Reference types are generally O(n), where n is the length (for arrays) or the number or keys (for objects)
47+
48+
## Searching Algorithms
49+
50+
### Linear Search
51+
52+
### Binary Search
53+
54+
## Sorting Algorithms
55+
56+
![Big O of sorting algorithms](img/big-o-sorting-algorithms.webp)
57+
58+
### Bubble sort
59+
60+
### Selection sort
61+
62+
### Insertion sort
63+
64+
### Merge sort
65+
66+
![Big O of merge sort](img/big-o-merge-sort.webp)
67+
68+
### Quick sort
69+
70+
### Radix sort
71+
72+
## Data Structures
73+
74+
Data structures are collections of values, the relationships among them, and the functions or
75+
operations that can be applied to the data. Commonly used data structures in javascript: array and object
76+
77+
### Singly Linked List
78+
79+
#### Linked List
80+
81+
- Do not have indexes
82+
- Connected via nodes with a next pointer
83+
- Random access is not allowed
84+
85+
#### Arrays
86+
87+
- Indexed in order
88+
- Insertion and deletion can be expensive
89+
- Can quickly be accessed at a specific index
90+
- Searching a value could be expensive while using linked list, however if you need to
91+
perform insertion and deletion in a large data set then it could be the better option
92+
than an array
93+
94+
#### Time complexity
95+
96+
- Insertion: O(1)
97+
- Removal: Depends O(1) or O(n)
98+
- Search: O(n)
99+
- Access: O(n)
100+
101+
### Doubly Linked List
102+
103+
- Has one more pointer previous than singly link list
104+
- Takes up more memory but has more flexibility than singly link list
105+
106+
Time complexity:
107+
108+
- Insertion: O(1)
109+
- Removal: O(1)
110+
- Search: O(n)
111+
- Access: O(n)
112+
113+
### Stack & Queues
114+
115+
#### Stack
116+
117+
- Implementation using Singly Link list
118+
- Insert at the beginning and remove at the beginning (shift and unShift)
119+
120+
Time complexity:
121+
122+
- Insertion: O(1)
123+
- Removal: O(1)
124+
- Searching: O(n)
125+
- Access: O(n)
126+
127+
#### Queue
128+
129+
- Implementation using Singly Link list
130+
- Insert at the end and remove at the beginning (push and shift)
131+
132+
Time complexity:
133+
134+
- Insertion: O(1)
135+
- Removal: O(1)
136+
- Searching: O(n)
137+
- Access: O(n)
138+
139+
### Trees
140+
141+
### Binary Heap
142+
143+
### Priority Queue
144+
145+
### Hash Tables
146+
147+
### Graph
148+
149+
## Algorithms and it's Applications
150+
151+
![Algorithm and it's Applications](img/algorithm-application.webp)
152+
153+
## Reference
154+
155+
- https://dev.to/arslan_ah/20-essential-coding-patterns-to-ace-your-next-coding-interview-32a3

0 commit comments

Comments
 (0)