From 49644bdbafcf6b428c188812cffe6a64ba153041 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Tue, 19 Dec 2023 03:41:10 +0000 Subject: [PATCH] add ex 1.1/1.2 --- chapter1/ex1.1.py | 7 +++++++ chapter1/ex1.2.py | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 chapter1/ex1.1.py create mode 100644 chapter1/ex1.2.py diff --git a/chapter1/ex1.1.py b/chapter1/ex1.1.py new file mode 100644 index 0000000..613ddd8 --- /dev/null +++ b/chapter1/ex1.1.py @@ -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." +) diff --git a/chapter1/ex1.2.py b/chapter1/ex1.2.py new file mode 100644 index 0000000..aa80532 --- /dev/null +++ b/chapter1/ex1.2.py @@ -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." +)