mirror of
https://github.com/onyx-and-iris/grokking-algorithms.git
synced 2024-11-15 17:30:52 +00:00
add ex 1.1/1.2
This commit is contained in:
parent
f5603c824b
commit
49644bdbaf
7
chapter1/ex1.1.py
Normal file
7
chapter1/ex1.1.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import math
|
||||||
|
|
||||||
|
num_steps = int(math.log2(128))
|
||||||
|
print(
|
||||||
|
f"A binary search would take maximum {num_steps} steps "
|
||||||
|
"to search a list of 128 items."
|
||||||
|
)
|
7
chapter1/ex1.2.py
Normal file
7
chapter1/ex1.2.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import math
|
||||||
|
|
||||||
|
num_steps = int(math.log2(128*2))
|
||||||
|
print(
|
||||||
|
f"A binary search would take maximum {num_steps} steps "
|
||||||
|
"to search a list of 256 items."
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user