Skip to Content
Grokking Algorithms, Second Edition
book

Grokking Algorithms, Second Edition

by Aditya Bhargava
March 2024
Beginner to intermediate
320 pages
7h 6m
English
Manning Publications
Content preview from Grokking Algorithms, Second Edition

Appendix C. Answers to exercises

Chapter 1

  1.1 Suppose you have a sorted list of 128 names, and you’re searching through it using binary search. What’s the maximum number of steps it would take?

Answer: 7.

  1.2 Suppose you double the size of the list. What’s the maximum number of steps now?

Answer: 8.

  1.3 You have a name, and you want to find the person’s phone number in the phone book.

Answer: O(log n).

  1.4 You have a phone number, and you want to find the person’s name in the phone book. (Hint: You’ll have to search through the whole book!)

Answer: O(n).

  1.5 You want to read the numbers of every person in the phone book.

Answer: O(n).

  1.6 You want to read the numbers of just the As.

Answer: O(n). You may think, “I’m only doing this ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Grokking Algorithms

Grokking Algorithms

Aditya Bhargava
Algorithms: 24-part Lecture Series

Algorithms: 24-part Lecture Series

Robert Sedgewick, Kevin Wayne

Publisher Resources

ISBN: 9781633438538Supplemental ContentPublisher SupportOtherPublisher WebsiteSupplemental ContentPurchase Link