https://github.com/olegchuev/grokking-algorithms
https://github.com/olegchuev/grokking-algorithms
algorithms crystal-lang python ruby
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/olegchuev/grokking-algorithms
- Owner: OlegChuev
- Created: 2023-07-07T18:35:55.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-23T18:35:15.000Z (almost 3 years ago)
- Last Synced: 2025-03-30T18:46:58.446Z (over 1 year ago)
- Topics: algorithms, crystal-lang, python, ruby
- Language: Python
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Grokking Algorithms
The main idea of the repo is to go through Grokking Algorithms book by Aditya Y. Bhargava.
Languages:
* Python
* Ruby
* Crystal
---
### #1 - Binary search
#### Complexity
`O log(n)`
1.1) If you have a sorted list of 128 names and you are searching for a value in it using the binary search method, what is the maximum number of comparisons that may be required?
Answer: log2(128) => 7
1.2) Assuming the size of the list doubled, how will the maximum number of comparisons change?
Answer: log2(256) => 8
1.3) Given the surname, you need to find the phone number in the phone book.
Answer: O(log n)
1.4) Given the phone number, you need to find the surname in the phone book.
Answer: O(n)
1.5) You need to read the phone numbers of all people in the phone book.
Answer: O(n)
1.6) You need to read the phone numbers of all people whose surnames start with the letter.
Answer: O(n)
---
### #2 - Selection sort
#### Complexity
`O(n^2)`
### #3 - Quick sort
#### Complexity
`O(n*log(n))`