Computer Science 15-100 (Sections T & U), Fall 2007
Homework 7
Due: Fri 2-Nov-2007 at 8:30am (email copy) and at recitation (physical
copy)
You should understand the two search algorithms we covered --
linearSearch and binarySearch. You should be able to "trace" these
algorithms, listing in order which indexes in an array they would check for
a given search. Given a list with n elements in it, the worst-case for
linear search is n steps, whereas for binary search it is log(n) steps
(where the log is base 2, which is generally assumed in computer science).
Doubling the list will take twice as long (worst-case) for linear search,
whereas squaring the list size will do so for binary search.
As for sorting, you should understand the three sorting algorithms we
covered -- bubblesort, insertionsort, and selectionsort. You should be able
to "trace" these algorithms, listing in order the swaps that each would make
for a given sort (you can instrument the swap method as we did in class to
practice this).
When studying how the sorting algorithms work, you may wish to use the very
handy xSortLab demo that we used in class.
http://math.hws.edu/TMCM/java/xSortLab/
Carpe diem!