Friday, November 16, 2012

Searching & OrderedArrayList

1. Consider the following list :
52 14 68 99 120 54 28 96
Using the sequential search as described in this chapter, how many comparisons are required to find whether the following items are in the list? (Recall that by comparisons we mean item comparisons, not index comparisons.)
a. 84
b. 54
c. 14
d. 250
2. Consider the following list :
48 1 12 23 62 54 14 21 95 68 74
Using the binary search as described in this chapter, how many comparisons are required to find whether the following items are in the list? Show the values of first, last, and middle and the number of comparisons after each iteration of the loop.
a. 52
b. 62
c. 95
d. 47
3. Write the definition of the method seqSearch for the class OrderedArrayList to implement a version of the sequential search algorithm for ordered lists. Also, write a program to test it.


Alright, the first 2 questions is actually tracing output, so doing programming (like I did) is like cheating. But what really matters is the third question. I want to make OrderedArrayList. But, the insert() method is different, so I can't really use inherited method from class ArrayList. How did I do it? Can I explain it next time?











No comments:

Post a Comment