Homework 2

Due Dates:


Referenced exercises are from Data Structures and Algorithm Analysis in Java by Mark A. Weiss. Page numbers are for the third edition (3/e) and the second edition (2/e) of the textbook.


  1. Exercise 3.2, parts a & b (3/e: p. 96, 2/e: p. 95).

    Note: For part a, assume that the singly linked list has a dummy header node and that the link is stored in a member called next. Also, assume that you are given a reference to the item before the first of the two adjacent items.

    For part b, assume the links are in members named next and prev. Also assume that you are given a reference to the first of the two adjacent items.

  2. Exercise 3.7 (3/e p. 97, 2/e p. 96). Briefly justify your answers.

  3. Exercise 3.8, parts a – d (3/e p. 97, 2/e p. 96). Briefly justify your answers.

    Additional Instructions: For part a, what would happen if the for loop was written as?

    for (int i = 0 ; i < lst.size()/2 ; i++) {
       lst.remove(0) ;
    }
    

    How much of the list would be removed? Why?