Question | Answer |
How does a linear search check for a selected item? | A linear search checks each item of the list in order to see if it is the item it's looking for. |
What is an advantage of using a linear search? | It is much simpler than a binary search. |
What are the disadvantages of a linear search? | - Due to its inefficiency, the linear search is usually only used on small lists. - If it is a large list of items, the item you are looking for can take a long period of time to be found. |
If I had Chocolate, Butterscotch, Vanilla and Strawberry, and I wanted to find Strawberry using a linear search, what would the program look like? | It would look like: Chocolate ≠ Strawberry Butterscotch ≠ Strawberry Vanilla ≠ Strawberry Strawberry = Strawberry ITEM FOUND |
What does a Binary Search look for items in? | They look for items in ordered lists. |
What is an advantage of a binary search? | A binary search is much more efficient than a linear search; it takes fewer steps to search for an item. |
If I had 9 items in a list, what would the first step be? | The first step would be to find the middle term. |
How do you do the first step? | To find the middle item in the list of 9 items, you would: - Do 9 + 1 (= 10) - Divide that number (10) by 2 (10/2) = 5 - The answer to the sum above (5) will be the middle term (this means that the 5th term is the middle term in this case). |
What's the second step? | If it's the item that is being looked for, stop the search because you've found it. If not, carry on to step 3. |
What's the third step? | If the item is not the middle term, compare it to the middle term; if it is above the middle term, remove the first half of the list, but if it's below the middle term, remove the second half of the list. |
What's the fourth step? | The list will be half the size of the original list, so you can repeat steps 1 and 3 until you find the item that is being searched for. |
What is a disadvantage of binary searches? | They are more complex than linear searches. |
There are no comments, be the first and leave one below:
Want to create your own Flashcards for free with GoConqr? Learn more.