80 likes | 93 Views
Learn about different search methods used by computers, such as linear search, binary search, and hashing, for finding specific information quickly and efficiently.
E N D
Searching for Information Using a Computer Module 3- Searching and Sorting
Mobile Phones can query the amount of credit remaining. Bank tellers need to look up the balance for a customer’s account number On-line music stores are able to find the songs sung by a given artist. Why do Computers Need to Perform Searches? Some Examples
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 How do Computers Perform Searches? The Method
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 Types of Searches? Some Examples
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.
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.
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