Self-Review Questions

  1. An iterator over an ArrayList object returns the items in
    a)   insertion order
    b)   comparable order
    c)   random order

  2. An iterator over a HashSet object returns the items in
    a)   insertion order
    b)   comparable order
    c)   random order

  3. An iterator over a TreeSet object returns the items in
    a)   insertion order
    b)   comparable order
    c)   random order

  4. Implement a method that prints a given ArrayList using an Iterator interface
    public void printList( ArrayList<Integer> data )

  5. Consider the following sequence of integer keys to be hashed into a hash table using the hash function H(key) = key modulo tablesize:
    11,  4,  5,  12,  25,  18

    Insert each key above, from left to right, into the hash table below using linear probing to resolve collisions.
     
      0     1     2     3     4     5     6     7  
                   

  6. Given an array of size n. One of its elements is repeated twice. Design an efficient algorithm that would find that duplicate.

  7. Given an array of integers. Design an efficient algorithm that finds two numbers x and y such that x + y = 0. Consider two cases a)sorted array; b)unsorted array.