Download presentation
Presentation is loading. Please wait.
Published byBuddy Berry Modified over 8 years ago
1
Module 3- Searching and Sorting Searching for Information Using a Computer
2
Why do Computers Need to Perform Searches? Some Examples Bank tellers need to look up the balance for a customer’s account number Mobile Phones can query the amount of credit remaining. On-line music stores are able to find the songs sung by a given artist.
3
How do Computers Perform Searches? The Method Get a Search Key For Example Phone Number Bank Account number Song Artist/ Song title Locate Information Related to the Search Key For Example Amount of Credit Remaining Account Balance Songs available for download sung by that Artist
4
Types of Searches? Some Examples Game 1 The linear Search Go straight through a list Game 2 Binary Search Divide and Conquer Game 3 Keys in a hash tables are associated with values
5
Linear Search Computers work very quickly. How efficient is a linear search? E.g. Imagine starting at the first page of the phone book and checking every page until you find a phone number for a man called John Williams.
6
Binary Search Your items must be sorted in order for a binary search to work. It is similar to how people locate information in a dictionary. In the phone book example, a book with 1 million names can now be searched with a maximum of 20 probes, which might take two hundredths of a second— hardly noticeable.
7
Number of Items in a listNumber of comparisons required in a binary search 2121 21 2 42 2323 83 2424 164 2828 2568 2 12 409612 2 16 65,53616 2 20 1,048,57620 2 30 1,073,741,82430 Binary Search
8
Game 3 - Hashing Data is stored at a specific location based on a hash function. Our game used a hash function to identify a column number for a ship. This column number (Hash Key) was created using the final digit of the sum of the digits of a ship’s number. As you have seen, it was slow to find the right ship in a chosen column if there was a large number of ships in a column. However, it was very quick if there was just one ship in a column. Hashing can be used for searching through lists of unsorted information. For example the Hong Kong Book. = 7 = 14
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.