Skip to content

Commit 70ef656

Browse files
committed
Minor changes
1 parent a353f99 commit 70ef656

File tree

13 files changed

+13
-10
lines changed

13 files changed

+13
-10
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

1-binary-search/README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
# Binary Search
22

3-
- Binary search is a divide-and-conquer algorithm; its input is a **sorted** list of elements. If an element you're looking for is in that list, binary search returns the position **where it's located**. Otherwise, binary search returns **null**.
3+
- Binary search is an example of the famous divide-and-conquer algorithm; its input is a **sorted** list of elements. If an element you're looking for is in that list, binary search returns the position of the item. Otherwise, it returns **null**.
44

5-
- We can only conduct binary search with ordered lists, such as alphabetically ordered phone list, ordered list of numbers etc.
5+
- You can only conduct binary search in ordered lists.
66

7-
- In general, for any list of n, binary search will take **log<sub>2</sub>n** steps to run in the worst case, whereas simple search will take **n** steps.
7+
- In general, for any list of `n`, binary search will take **log<sub>2</sub>n** steps to run in the worst case, whereas simple search will take **n** steps.
88

99
![logarithms](images/logarithms.png)
1010

11-
In this book, when I talk about running time in Big O notation (explained a little later), log always means log<sub>2</sub>.
11+
In the documents, log always means log<sub>2</sub>.
1212

1313
## Running Time
1414

1515
| Running Time | Log(n) vs n |
1616
| ------------ | ----------- |
1717
| ![running-time](images/running-time.png) | ![log-n](images/log-n.png) |
1818

19-
The key idea is that when binary search makes an incorrect guess, the portion of the array that contains reasonable guesses is reduced by at least half. If the reasonable portion had 32 elements, then an incorrect guess cuts it down to have at most 16. Binary search halves the size of the reasonable portion upon every incorrect guess.
19+
When binary search makes an incorrect guess, the portion of the array that contains reasonable guesses is reduced by at least half. If the reasonable portion had 32 elements, then an incorrect guess cuts it down to have at most 16. Binary search halves the size of the reasonable portion upon every incorrect guess.
20+
21+
## Interesting Fact
2022

2123
> According to 'Programming Pearls', only 10% of professional programmers are able to implement binary search in their code. They can explain it very well, but coding it is a challenge for them.

10-hash-tables/.DS_Store

-6 KB
Binary file not shown.
-6 KB
Binary file not shown.

14-greedy-algorithms/.DS_Store

-6 KB
Binary file not shown.

2-big-o-notation/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Big-o-notation
22

3-
- Big-o-notation is special notation that tells you how fast an algorithm is.
3+
- Big-o-notation is a special notation that tells you how fast an algorithm is.
44

5-
- Simple search needs to check each element, so it will take **n** operations. The run tme in Big O notation is **O(n)**.
5+
- Simple search needs to check each element, so it will take **n** operations. The run time in Big O notation is **O(n)**.
66

77
- Binary search needs **log(n)** operations to check a list of size n. Running time in Big O notation is **O(log n)**.
88

9-
- Big O will not tell you anything about how long it will take, it will only tell you how fast the algorithm grows.
9+
- Big O will not tell you anything about how long it will take, it will only tell you how fast the algorithm grows, in other words how your algorithm scales.
1010

11-
- Big O always considers the worst case. If we are lucky, we can find the value that we are searching for even in the first try, but Big(O) always considers the worst case. Omega(n) considers the best case, and Theta(n) considers the average case.
11+
- Big O always considers the worst case. If you are lucky, you can find the value that we you searching for even in the first try, but Big(O) always considers the worst case. Omega(n) considers the best case, and Theta(n) considers the average case.
1212

1313
![big-o-notation](images/big-o-notation.png)
1414

@@ -18,7 +18,7 @@
1818
- O(n), also known as linear time. Simple search.
1919
- O(n * log<sub>n</sub>). A fast sorting algorithm like quicksort.
2020
- O(n<sup>2</sup>). A slow sorting algorithm like selection sort.
21-
- 0(n!). A really slow algorithm like traveling salesperson.
21+
- O(n!). A really slow algorithm like traveling salesperson.
2222

2323
## Summary
2424

3-selection-sort/.DS_Store

-6 KB
Binary file not shown.

4-arrays-and-linked-lists/.DS_Store

-6 KB
Binary file not shown.

5-recursion/.DS_Store

-6 KB
Binary file not shown.

6-stack/.DS_Store

-6 KB
Binary file not shown.

7-quicksort/.DS_Store

-6 KB
Binary file not shown.

8-divide-and-conquer/.DS_Store

-6 KB
Binary file not shown.

9-big-o-revisited/.DS_Store

-6 KB
Binary file not shown.

0 commit comments

Comments
 (0)