Exam 2 Review Sheet
Recursion
You should be prepared for the following:
- Identify and repair errors in a given recursive algorithm or
method.
- Describe the output of a given recursive method.
- Write a recursive method (in pseudocode) to solve a given problem, for
example a portion of a lab or project where you previously used
iteration.
- Analyze the running time of a recursive method.
Things to remember:
- A recursive method must have a base case.
- Recursive calls must make progress toward the base case.
- Recursive algorithms should never duplicate work.
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):
- Identify and repair errors in a LinkedList method.
- Describe the output of a given LinkedList method
- Write a method (in pseudocode) for a LinkedList class.
- Analyze the running time of a given method from a LinkedList class.
Things to remember:
- Always remember to handle special cases such as when your list is
empty.
- The order in which you move references is extremely important.
Stacks/Queues
You should be prepared for the following (for both stacks and queues):
- Know how to execute stack/queue methods on data.
- Analyze the running time of stack/queue methods.
- Understand the implementation of a stack/queue using an array and a
singly linked list.
- Use stacks/queues to solve other problems.
- Write new stack/queue methods to perform given operations.
Things to remember:
- To achieve O(1) running time for enqueue/dequeue when using an array as
the underlying implementation, you must use a circular array.
- Always remember to handle special cases, such as when your stack/queue
is full/empty.
Trees
You should be prepared for the following:
- Know how to execute tree methods on data.
- Understand the ordering property of binary search trees.
Things to remember:
- The worst case tree is a linked list.
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