• Binary search
  • What you’ll learn about solving problems




    Download 24.82 Mb.
    Pdf ko'rish
    bet7/120
    Sana30.06.2022
    Hajmi24.82 Mb.
    #24606
    1   2   3   4   5   6   7   8   9   10   ...   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’ll learn about solving problems
    You’ll learn techniques for solving problems that might have been out of 
    your grasp until now. For example:
    • If you like making video games, you can write an AI system that 
    follows the user around using graph algorithms.
    • You’ll learn to make a recommendations system using k-nearest 
    neighbors.
    • Some problems aren’t solvable in a timely manner! The part of this 
    book that talks about NP-complete problems shows you how to 
    identify those problems and come up with an algorithm that gives 
    you an approximate answer.
    More generally, by the end of this book, you’ll know some of the most 
    widely applicable algorithms. You can then use your new knowledge to 
    learn about more specific algorithms for AI, databases, and so on. Or 
    you can take on bigger challenges at work.


    3
    Binary search
    Binary search
    Suppose you’re searching for a person in the phone book (what an old-
    fashioned sentence!). Their name starts with K. You could start at the 
    beginning and keep flipping pages until you get to the Ks. But you’re 
    more likely to start at a page in the middle, because you know the K
    are going to be near the middle of the phone book.
    Or suppose you’re searching for a word in a dictionary, and it
    starts with O. Again, you’ll start near the middle. 
    Now suppose you log on to Facebook. When you do, Facebook 
    has to verify that you have an account on the site. So, it needs to 
    search for your username in its database. Suppose your username is 
    karlmageddon. Facebook could start from the As and search for your 
    name—but it makes more sense for it to begin somewhere in the 
    middle.
    This is a search problem. And all these cases use the same algorithm
    to solve the problem: binary search.
    Binary search is an algorithm; its input is a sorted list of elements
    (I’ll explain later why it needs to be sorted). 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
    .

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




    Download 24.82 Mb.
    Pdf ko'rish

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    What you’ll learn about solving problems

    Download 24.82 Mb.
    Pdf ko'rish