Skip to content

Commit 59e0b23

Browse files
authored
Update brain_teasers.md
1 parent 79c4e46 commit 59e0b23

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

notes/brain_teasers.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Understanding and effectively using data structures is fundamental in programmin
2424
#### Working with Arrays
2525

2626
Arrays are fundamental data structures that store elements in contiguous memory locations, allowing efficient random access. Here are strategies for working with arrays:
27+
2728
- **Sorting** an array can simplify many problems. Algorithms like Quick Sort and Merge Sort are efficient with $O(n \log n)$ time complexity. For nearly sorted or small arrays, **Insertion Sort** may be a better option due to its simplicity and efficiency in those cases.
2829
- In **sorted arrays**, binary search provides a fast way to find elements or their positions, working in $O(\log n)$. Be cautious with **mid-point calculations** in languages prone to integer overflow due to fixed-size integer types.
2930
- The **two-pointer technique** uses two indices, often starting from opposite ends of the array, to solve problems involving pairs or triplets, like finding two numbers that add up to a target sum. It helps optimize time and space.
@@ -418,49 +419,50 @@ Combine the two smallest frequency nodes into a new node. Repeat until there is
418419
I. Combine 5(A) and 9(B):
419420

420421
```
421-
(14)
422-
/ \
423-
5(A) 9(B)
422+
(14)
423+
/ \
424+
5(A) 9(B)
424425
```
425426

426427
Updated Heap: $[12(C), 13(D), 14(AB), 16(E), 45(F)]$
427428

428429
II. Combine 12(C) and 13(D):
429430

430431
```
431-
(25)
432-
/ \
433-
12(C) 13(D)
432+
(25)
433+
/ \
434+
12(C) 13(D)
434435
```
435436

436437
Updated Heap: $[14(AB), 16(E), 25(CD), 45(F)]$
437438

438439
III. Combine 14(AB) and 16(E):
439440

440441
```
441-
(30)
442-
/ \
443-
14(AB) 16(E)
442+
(30)
443+
/ \
444+
14(AB) 16(E)
444445
```
445446

446447
Updated Heap: $[25(CD), 30(ABE), 45(F)]$
447448

448449
IV. Combine 25(CD) and 30(ABE):
449450

450451
```
451-
(55)
452-
/ \
453-
25(CD) 30(ABE)
452+
(55)
453+
/ \
454+
25(CD) 30(ABE)
454455
```
455456

456457
Updated Heap: $[45(F), 55(CDABE)]$
457458

458459
V. Combine 45(F) and 55(CDABE):
459460

460461
```
461-
(100)
462-
/ \
463-
45(F) 55(CDABE)
462+
Tree:
463+
(100)
464+
/ \
465+
45(F) 55(CDABE)
464466
/ \
465467
25(CD) 30(ABE)
466468
/ \ / \
@@ -489,6 +491,7 @@ F = 11
489491
**Final Huffman Tree Diagram:**
490492

491493
```
494+
Tree:
492495
(100)
493496
/ \
494497
(45) (55)

0 commit comments

Comments
 (0)