Final review page for CS241: Data Structures -- Spring 2017
Disclaimers:
Not all of these questions will appear on the final.
Not all of the questions on the final appear here.
First, make sure you can answer the questions on the midterm review page... especially
if your midterm score was less than satisfying! There will be questions from the first half of the term on the final!
Sample questions:
O and Θ
What is the definition of O?
Does O(n) -> O(n^2)? I.e. if an algorithm is O(n) does that mean it is also O(n^2)? Explain why.
What is the definition of Θ?
Does Θ(n) -> Θ(n^2)? Explain.
What does "divide & conquer" have to do with the log n term in the various log n algorithms?
What is the running time of: some sort? Where "some" is one of: bubble, shell, insertion, merge, quick, tree, heap, selection, insertion,
oracle, counting/table, random
The previous question assumed we meant "average" running time. Why do we need to think about worst case running times as well in special cases?
Write pseudocode for: some sort. Where "some" is one of: bubble, shell, insertion, merge, quick, tree, heap, selection, insertion,
oracle, counting/table, random
Hashtable
Why is look-up O(1)?
What does H: K->V mean? Hint: H, is a hashmap, K is a key, V is a value
What is Java's hashtable called?
clone
What is the difference between a shallow copy and a deep copy? Write a snippet of code to illustrate.
Given: this.x = that.x; in a constructor, is this that same as: x = that.x;? Explain.
Assuming you have written clone(), or a constructor that acts like it; how do you test to make sure you have
really made a deep copy? Give an example.
Binary tree/ Binary Search Tree/heap
What is the definition of a binary tree?
Given that definition, if you store 3 values in a binary tree, how many binary trees are in it total? How many empty trees?
Write a method, ht, that returns the ht of a binary tree.
Write a method, size, that returns the number of non-null sub trees in a tree
What is the definition of a BST?
What is the definition of a heap?
How does a heap represent the binary tree?
Write pseudocode for tree sort.
Write pseudocode for heap sort.
N-nary tree
What is the definition of an nary tree?
Define an nary tree class including a constructor
Write a method to traverse an n-ary tree, send toString to each root, and sout it with indentation showing its depth
Write ht and size (see above)
Write pseudocode for displaying an nary tree graphically
Given a Board class with BoardList generateNextLegalBoards(Board), creates an entire gametree!
Dynamic programming
What is the Needleman-Wunsch algorithm used for?
Write it! Pseudocode is fine.
What is its running time?
Why is this called dynamic programming?
Write pseudocode for generating Fibonacci numbers using dynamic programming.
Cellular automata
What are the rules of Conway's life?
How to you make the board a torus? Write code!
What's wrong with this loop?
for each cell {
count nbrs
update state
}
Space and time
How can you trade space for time? Give an example.
How can you trade time for space? Give an example.
Write a Board class for tic tac toe that represents the board as a 2D array of ints (1 for X, -1 for O, 0 for empty)
Write a method that is passed a Board and returns a unique int representing that Board.