• Chapter 1 I
  • Looking for companies in a phone book with binary search
  • A better way to search
  • Grokking Algorithms




    Download 24.82 Mb.
    Pdf ko'rish
    bet8/120
    Sana30.06.2022
    Hajmi24.82 Mb.
    #24606
    1   ...   4   5   6   7   8   9   10   11   ...   120
    Bog'liq
    grokking-algorithms-illustrated-programmers-curious
    ppt 1, Oraliq nazorat Javoblari, 5-mustaqil ish, 5-мустақил иш, Илмий тадқиқот методологияси ишчи дастур 2020, Allayarov A. 2, ТПроформа договора по лоту №73719 (1), 7-topshiriq, 7-8-9 lab, Amplitudali modulyatsiya, 1-1610, fazliddin fozilov 123, Dasturlash 3 natija, Calendar plan-Maxsus fanlarni o\'qitish metodikasi (3)
    What you need to know
    You’ll need to know basic algebra before starting this book. In parti- 
    cular, take this function: f(x) = x × 2. What is f(5)? If you answered 10, 
    you’re set.
    Additionally, this chapter (and this book) will be easier to follow if 
    you’re familiar with one programming language. All the examples in 
    this book are in Python. If you don’t know any programming languages 
    and want to learn one, choose Python—it’s great for beginners. If you 
    know another language, like Ruby, you’ll be fine.


    Chapter 1 
     
    I
     
     
    Introduction to algorithms
    4
    For example:
    Here’s an example of how binary search works. I’m thinking of a 
    number between 1 and 100. 
    You have to try to guess my number in the fewest tries possible. With 
    every guess, I’ll tell you if your guess is too low, too high, or correct.
    Suppose you start guessing like this: 1, 2, 3, 4 …. Here’s how it would 
    go.
    Looking for companies 
    in a phone book with 
    binary search


    5
    Binary search
    This is simple search (maybe stupid search would be a better term). With 
    each guess, you’re eliminating only one number. If my number was 99, 
    it could take you 99 guesses to get there!
    A better way to search
    Here’s a better technique. Start with 50.
    Too low, but you just eliminated half the numbers! Now you know that 
    1–50 are all too low. Next guess: 75. 
    A bad approach to 
    number guessing


    Chapter 1 
     
    I

    Download 24.82 Mb.
    1   ...   4   5   6   7   8   9   10   11   ...   120




    Download 24.82 Mb.
    Pdf ko'rish