As you have seen, Linear Search (also called sequential search) is a very simple algorithm, for which the data to be searched can be in any order. But… the algorithm is not very efficient. Imagine looking for a name in a phone book that hasn’t been sorted alphabetically…
If your data is sorted, then there is a much more efficient algorithm called Bisection Search that you can use to look for an item in your list.
If you cannot see this codecast, please click here.
Check Your UnderstandingCheck Your Understanding
1.
Which of the following is the correct sequence of instructions to swap the values of two variables a and b (you may use an additional variable c if you wish)?
Feel free to use the window below to try out some code. Be sure to work the correct answer out "by hand" first before verifying your answer using the code window.