Lecture Reviews
- Lecture 1: Classes and Objects
- Using what we know about classes, how can you make a field read-only? For example, say we want a class that has a field; a programmer then creates an object, assigns a value to that field, then the field can never be changed after that.
- Lecture 2: References and New Classes
- For this class:
public class Class02 {
private int x;
public Class02(int value) {
x = value;
}
public void setValue(int value) {
x = value;
}
public int getValue() {
return x;
}
}
What does the following code print out?
Class02 a = new Class02(15);
System.out.println("a = "+a.getValue());
Class02 b = a;
b.setValue(500);
a.setValue(10);
System.out.println("a = "+a.getValue());
System.out.println("b = "+b.getValue());
- How does composition differ from inheritance?
- Why is composition useful for data structures?
- Lecture 3: Polymorphism, Abstract Classes, and Interfaces
- How is polymorphism useful for data structures?
- How might method overriding play a part in data structures?
- Why are interfaces useful for data structures?
- Lecture 4: Generics and Abstract Data Types (ADTs)
- How are ADTs different from classes? How are they similar?
- What are the similarities and differences between abstract classes and abstract data types?
- How are generics useful for abstract data types?
- Lecture 5: Bag
- When implementing abstract data types, what questions must you answer? Is there anything else you must consider?
- When implementing the add and remove methods for the fixed size array, we saw that how we implemented one affected the implementation of the other. This will happen a lot in data structures (and in programming in general). What are ways to notice these situations? How do you approach these situations? What kinds of things should you look out for?
- Lecture 6: Dynamic Size Bag and Memory
- What are the differences between a fixed size bag and a dynamic size bag? What are the advantages and disadvantages to each?
- Assuming someone has already implemented the fixed size bag and the dynamic size bag, why might you choose to use the fixed size bag?
- What are the steps involved in resizing an array?
- What is contiguous memory? What is non-contiguous memory? How do they differ?
- Lecture 7: Linked Lists and LinkedBag
- How does a linked list know about (or get access to) the elements stored in it?
- How you traverse (walk through or iterate through) the nodes in a linked list?
- What are the tradeoffs between a dynamic size array and a linked list? When might one be better than the other?
- Lecture 8: Stacks and Algorithm Analysis
- Give some examples of real-life stacks.
- When implementing a stack with an array, where should the "top" of the stack be? Why?
- When implementing a stack with a linked list, where should the "top" of the stack be? Why?
- How is algorithm analysis useful for data structures?
- Why use binary search? Why use sequential search?
- Lecture 9: Algorithm Analysis
- Runtimes with logarithmic runtimes have some peculiar characteristics. What do you think some of those characteristics are?
- Lecture 10: Amortized Algorithm Analysis & Introduction to Recursion
- How can we use amortized analysis to analyze this method:
public static int[] doubleOn3s(int num) {
int size;
if (num % 3 != 0) {
size = num;
}
else {
size = num * num;
}
int[] array = new int[size];
for(int i=0; i < size; i++)
array[i] = i;
return array;
}
- What are the runtimes for
push
, pop
, and peek
for both the ArrayStack and the LinkedStack?
- Lecture 11: Divide and Conquer
- When should you use (or consider using) a divide and conquer algorithm? What properties must a problem or solution have to make it worth considering?
- Do divide and conquer algorithms always require two (or more) recursive calls?
- How is divide and conquer different from recursion?
- Lecture 12: Tail Recursion and Backtracking
- Any recursive algorithm can be written as an iterative algorithm. In all cases, the iterative version can use a stack but some iterative versions must use a stack. Why would a stack be needed for iterative versions of recursive algorithms?
- Why is the recursive solution to the 8 Queens Problem easier to write than an iterative solution?
- In some cases, a recursive solution is better than an iterative one. What are the properties of a solution that make a recursive implementation better than an iterative implementation?
- Lecture 13: Backtracking, Sorting, Insertion Sort, and Bounded Generics
- In your own words, describe how the recursive solution for Towers of Hanoi works.
- Why do we only need one array for Insertion Sort?
- What does
<T extends Comparable<? super T>>
mean?
- Lecture 14: Insertion Sort, Selection Sort, & Shellsort
- How does Selection Sort differ from Insertion Sort?
- How does Shellsort differ from Insertion Sort?
- Determine the worst-case runtime for Selection Sort.
- When should you use bubble sort?
End of Material for Midterm
- Lecture 15: Merge Sort & Quick Sort
- How is Merge sort a divide and conquer algorithm, but Shellsort isn't?
- In your own words, why is Merge sort faster than Insertion sort or Selection sort?
- Lecture 16: Quick Sort & Merge Sort
- How does Quick Sort differ from Merge Sort?
- Which is better and why: Quick Sort or Merge Sort?
- Lecture 17: List ADT and Array-Implemented List
- How can you implement a Stack using a List? Is it a good idea to do this or a bad idea? Why?
- How does an array differ from a List? How are they the same?
- Lecture 18: Linked List and List ADT Runtimes
- We saw how to implement a list using both an array and a linked list. How would you implement a list using a stack? What are the runtimes of a stack-implemented list's add and remove methods?
- What advantage does a doubly-linked list provide over a circular linked list? What advantage does a circular linked list provide over a doubly-linked list?
- Lecture 19: Iterators
- Why should an array provide an iterator?
- For a Linked List, how is providing an iterator better than using the
toArray
method and a simple for loop?
- Lecture 20: Iterators and Introduction to Trees
- Is it possible to have an iterator for a Stack? Why or why not?
- How would you invalidate iterators when the list is modified?
- What data structure have we seen that isn't necessarily linear?
- Is is possible to have a leaf node with no parent in a tree?
- Lecture 21: Binary Trees and Tree Height
- A trinary tree is a tree where each node can have up to three children. If a trinary tree has 24 nodes, what are the minimum and maximum possible heights for this tree?
- Lecture 22: Binary Trees and Tree Traversal
- How do each of the tree traversals differ? How are they the same? When might you use one over another?
- What is the runtime of each of the binary tree traversals? How would those runtimes compare to traversals in a trinary tree?
- Lecture 23: Binary Search Trees
- The List ADT has an add operation that allows us to put a value at any position in the list. Why doesn't the Binary Search Tree ADT have such an operation?
- The Binary Tree doesn't have an add operation, but the Binary Search Tree does. Why is that? Why don't we just implement an add method for our Binary Tree class and just use that in the Binary Search Tree?
- Lecture 24: Binary Search Trees and Queues
- How does deleting a node from a binary search tree compare to deleting a node from a link list? How are they different?
- When might queues be useful?
- What are examples of real-life queues?
- Lecture 25: Queue Implementations
- It is possible to implement a queue using a stack. How would you do that? What would the runtime of the
enqueue
operation be? What would the runtime of the dequeue
be?
- Why use an array implementation over a linked list implementation? Why use a linked list implementation over an array implementation?
- Lecture 26: Priority Queues
- Why are array and linked list implementations inefficient?
- How does a min heap differ from a max heap?
- How does a heap compare/contrast to a binary search tree?
- Lecture 27: Heaps, Mutable Objects, and Cloning
- Implement a priority queue using a bag. What is the efficiency of the add and remove operations?
- Implement a heap using a binary search tree. Is this possible? Why or why not?
- How does a deep copy compare/constrast to a shallow copy?