Exam 2 Review Sheet


Recursion

You should be prepared for the following:

Things to remember:

Algorithm Analysis

You should be prepared to give the running time of a specified method and to write methods that have a specified running time. Remember, most of the methods we've looked at have a running time of O(1) or O(N).

Linked Lists

You should be prepared for the following (for singly and doubly linked lists):

Things to remember:

Stacks/Queues

You should be prepared for the following (for both stacks and queues):

Things to remember:

Trees

You should be prepared for the following:

Things to remember:

Practice Problems

These problems are similar to the questions that will appear on the exam.

1. Use a Stack to determine whether the parentheses are balanced in a given Java statement.

2. Sketch the implementation of a class TwoStack. TwoStack behaves as two independent stacks implemented in a single class and provides four methods: pushA, pushB, popA, popB. Use a single array to store data and only throw a StackFullException in the case that the entire array is full.

3. Implement a Stack using two Queues. What is the running time of push/ pop?

4. Give the pseudocode for a method that takes as input the references to the heads of two unsorted singly linked lists and returns a reference to a sorted singly linked list that contains all of the elements of l1 and all of the elements of l2. What is the running time of your algorithm?


Sami Rollins

Date: 2007-11-19