Searching Flashcards
What are the 2 main algorithms used for searching?
Linear and binary searches.
Which type of search would be more efficient at searching for an item in a large list?
A binary search would be quicker.
Which type of search would be used on an unordered list?
A linear search can be used on an unordered list.
What are the advantages of a linear search?
The advantages of a linear search are that it works on any list, as the list does not have to be ordered. Also, it is simpler to code than a binary search.
What are the disadvantages of a binary search?
The drawbacks of a binary search is that binary searches only work on ordered lists,
In this list, how many checks would it take to find the word Tuna if you used a binary search?
Ham, Cheese, Chicken, Tomato, Tuna, Jam, Peanut Butter.
3 checks.
Using the same list, how many checks would it take for a linear search to find the word Tomato?
Ham, Cheese, Chicken, Tomato, Tuna, Jam, Peanut Butter.
4 checks.
In this list, which searching algorithm would find the word Gerbil quicker?
Rabbit, Guinea Pig, Dog, Parrot, Cat, Snake, Lizard, Gerbil, Hamster, Fish,
A binary search.
A linear search would take 8 checks, whereas a binary search would take only 2 checks
What are the advantages of a binary search?
The advantages are that a binary search is much more efficient than a linear search when searching for an item within a large list. Also, binary search takes much fewer steps to find an item. For example, a binary search would take a maximum of eight loops to find an item with 1000 items.
What are the disadvantages of a linear search?
The disadvantages are that a linear search is that it takes much longer with a large list than a binary search, because it has to check each item 1 by 1. Also, if he required item is at the end of the list, the search has to go through all the items until it gets to the required item.