Skip to content

Commit 16be43d

Browse files
committed
Update submodules to latest main branch
1 parent 5ec103c commit 16be43d

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,62 @@ Also consult [Visualgo] for visualizing data structures and algorithms through a
107107
[docs]: https://github.com/Codecademy/docs
108108
[curriculum]: https://github.com/freeCodeCamp/freeCodeCamp
109109
[projects]: https://github.com/codecrafters-io/build-your-own-x
110+
111+
## Guide to Data Structures and Algorithms
112+
113+
Personally, what I did was to start brushing up on the basics of data structures and algorithms through easy reading [Grokking Algorithms] and [Grokking Data Structures]. Both are pretty updated books from last year, and I just wanted to get a bit more familiar with the ideas.
114+
115+
Arrays seems like the most fundamental data structure, so the first thing you should be able to do it's to work with that.
116+
117+
### Arrays
118+
119+
There are two types of arrays: static and dynamic. Static arrays have a fixed size, which means the size must be defined at compile time and cannot be changed during runtime. Dynamic arrays, on the other hand, can grow and shrink in size as needed during program execution. Understanding the difference between these two types is crucial for efficient memory management and performance optimization.
120+
121+
**Static Array in C:**
122+
123+
```c
124+
#include <stdio.h>
125+
126+
int main() {
127+
int arr[5] = {1, 2, 3, 4, 5};
128+
int i = 0;
129+
while (i < 5) {
130+
printf("%d ", arr[i]);
131+
i++;
132+
}
133+
printf("\n");
134+
return 0;
135+
}
136+
```
137+
138+
Use Case: Static arrays are suitable when the number of elements is known in advance and does not change, such as storing the days of the week.
139+
140+
**Dynamic Array in Python:**
141+
142+
```python
143+
arr = [1, 2, 3, 4, 5]
144+
print(arr)
145+
arr.append(6)
146+
print(arr)
147+
```
148+
149+
### Binary search
150+
151+
![animation idea](/animations/binary_search.html)
152+
153+
```python
154+
def binary_search(array, target):
155+
low, high = 0, len(array) - 1
156+
while low <= high:
157+
mid = (low + high) // 2 # or low + (high - low) // 2
158+
if array[mid] == target:
159+
return mid
160+
elif array[mid] < target:
161+
low = mid + 1
162+
else:
163+
high = mid - 1
164+
return -1
165+
```
166+
167+
[Grokking Algorithms]: https://annas-archive.org/md5/6014af49a9c4c513b76f29b74a869e3f
168+
[Grokking Data Structures]: https://annas-archive.org/md5/8116130f95c8cfc0c010a5be29c75cf2

0 commit comments

Comments
 (0)