Answer:
- Do the cities have to be in order?
- No, the cities can be in any order. Linear search examines them one by one regardless of their order.
- Does it hurt that "Albany" is in the array twice?
- There are two answers to this:
- If the target is not "Albany", it makes no difference at all.
- If the target is "Albany", linear search finds the first one, and says nothing about the second. Depending on your application this might or might not be acceptable.
- There are two answers to this:
Analysis of Algorithms
We have (partially) analyzed the algorithm by looking it over and answering some questions about how it works. Professional programmers must be able to analyze algorithms in order to use them successfully. Many books have been written about the analysis of algorithms, and all university computer science departments have at least one course in the topic.
QUESTION 15:
What type of control structure do you suppose will be used to look through the cells of the array one by one (as required by linear search)?