https://github.com/costineest/grokking-algorithms-with-aditya-bhargava
Book notes
https://github.com/costineest/grokking-algorithms-with-aditya-bhargava
algorithms-implemented book-notes manning-publications
Last synced: 13 days ago
JSON representation
Book notes
- Host: GitHub
- URL: https://github.com/costineest/grokking-algorithms-with-aditya-bhargava
- Owner: costinEEST
- Created: 2025-07-04T15:21:47.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-07-25T18:47:52.000Z (3 months ago)
- Last Synced: 2025-07-26T01:30:19.313Z (3 months ago)
- Topics: algorithms-implemented, book-notes, manning-publications
- Language: Python
- Homepage: https://www.manning.com/books/grokking-algorithms-second-edition
- Size: 10.7 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Gotchas
| Gotcha | Python | Java | JavaScript |
| ------------------------ | -------------------------------------- | ---------------------------------------------------------------------------- | --------------------------------------- |
| **Integer Division** | `(low + high) // 2` | `(low + high) / 2` ⚠️ **Overflow risk!**
Better: `low + (high - low) / 2` | `Math.floor((low + high) / 2)` |
| **Array Length** | `len(arr)` | `arr.length` | `arr.length` |
| **Function Definition** | `def binary_search():` | `public static Integer binarySearch()` | `function binarySearch()` |
| **Variable Declaration** | `low = 0` | `int low = 0;` | `let low = 0;` |
| **Equality Check** | `==` | `==` (primitives)
`equals()` (objects) | `===` (strict)
`==` (loose, avoid!) |
| **Null/None Value** | `None` | `null` | `null` |
| **Return Type** | Dynamic | Must declare `Integer` (not `int`) to return `null` | Dynamic |
| **Naming Convention** | `snake_case` | `camelCase` | `camelCase` |
| **Division Behavior** | `/` returns float
`//` returns int | `/` returns int for integers
float for mixed types | `/` always returns float |
| **Semicolons** | Optional (not used) | Required `;` | Optional but recommended `;` |# Syntax
- In Python, arrays are called [lists](https://docs.python.org/3/library/stdtypes.html#lists).
- [`range(start, stop[, step])`](https://docs.python.org/3/library/stdtypes.html#range)# Theory
- Algorithm times are measured in terms of growth of an algorithm.
- Algorithm times are written in [big O notation](https://en.wikipedia.org/wiki/Big_O_notation).
- Common big O run times, sorted from fastest to slowest:
- `O(log n)`, also known as [logarithmic time](https://en.wikipedia.org/wiki/Time_complexity#Logarithmic_time) (binary search).
- `O(n)`, also known as linear time (simple search).
- `O(n * log n)`, a fast sorting algorithm (quicksort).
- `O(n*n)`, a slow sorting algorithm (selection sort).
- `O(n!)`, a really slow algorithm (traveling salesperson).
- Lists are better if you want to insert elements into the middle.
- Linked lists allow fast inserts an deletes.
- Random access (offered by arrays), means you can jump directly to a specific element.
- Arrays are faster because they can use caching.
- Insertions and deletions are `O(1)`, or constant time, only if you can instantly access the element to be deleted.# Tooling
- https://code.visualstudio.com/docs/python/jupyter-support-py#_jupyter-code-cells
- https://code.visualstudio.com/docs/languages/java#_install-a-java-development-kit-jdk
- Execute a Typescript file from CLI: `node --experimental-transform-types 01_binarySearch.ts`