A good answer might be:

  • 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:
      1. If the target is not "Albany", it makes no diference at all.
      2. 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.

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 in large application programs. Books have been written about analysis of algorithms, and all university computer science departments have at least one course in the topic. Of course, things get more involved than what we have just done.

QUESTION 11:

What type of control structure do you suppose will be used to look through the slots of the array one by one (as required by linear search)?

Click Here after you have answered the question