Lecture 30:
Review & Wrap-Up
CS 136: Spring 2024
Katie Keith
📣 Announcements
Today’s agenda
CS 136: Learning Goals
Analysis
Tradeoffs of Time and Space
Advanced Programming
OOP, Java, JUnit, Git
ADTs &
Data Structures
Use & Implement
ADTs to Data Structures
Abstract Data Types (ADTs)
Data Structures
Abstract. Defines a particular set of operations that can be performed on data, (without necessarily describing how they are implemented).
Concrete. The ADT implementation in a programming language.
ADTs to Data Structures
ADTs
List
Finite number of elements
(same element may occur more than once)
Stack
Last in first out (LIFO) operations
Symbol Table
Associates a key with a value
Graphs
A set of vertices, pairs of which are connected by edges
Priority Queue
Poll operation removes and returns elements with min (max) priority
Queue
First in first out (FIFO) operations
ADTs to Data Structures
Adjacency matrices
ADTs
Data Structures
Adjacency lists
List
Finite number of elements
(same element may occur more than once)
Stack
Last in first out (LIFO) operations
Queue
First in first out (FIFO) operations
Symbol Table
Associates a key with a value
Graphs
A set of vertices, pairs of which are connected by edges
Priority Queue
Poll operation removes and returns elements with min (max) priority
ADTs to Data Structures
Singly Linked Lists
ADTs
Data Structures
Arrays
int[] arr = {1, 2, 3, 4, 5};
List
Finite number of elements
(same element may occur more than once)
Stack
Last in first out (LIFO) operations
Queue
First in first out (FIFO) operations
Symbol Table
Associates a key with a value
Graphs
A set of vertices, pairs of which are connected by edges
Doubly Linked Lists
Priority Queue
Poll operation removes and returns elements with min (max) priority
ADTs to Data Structures
List
Finite number of elements
(same element may occur more than once)
Stack
Last in first out (LIFO) operations
Queue
First in first out (FIFO) operations
Symbol Table
Associates a key with a value
Graphs
A set of vertices, pairs of which are connected by edges
Priority Queue
Poll operation removes and returns elements with min (max) priority
Hash Table
w/ separate chaining
ADTs
Data Structures
Binary Search Tree
Hash Table
w/ linear probing
CS 136: Learning Goals
Analysis
Tradeoffs of Time and Space
Advanced Programming
OOP, Java, JUnit, Git
ADTs &
Data Structures
Use & Implement
Running time of algorithms of different orders of growth
Very long = exceeds 10^25 years
n is the number of elements
(in the data structure)
Analysis of Symbol Table’s Data Structures
Data Structure | put | get |
(Unordered) Linked List | O(n) | O(n) |
Two arrays (keys sorted, binary search) | O(n) | O(log n) |
Binary Search Tree | Ave = O(log n) Worst = O(n) | Ave = O(log n) Worst = O(n) |
Hash Table (with separate chaining) | Ave = O(1)* Worst= O(n) | Ave = O(1)* Worst= O(n) |
Hash table (with linear probing) | Ave = O(1)* Worst= O(n) | Ave = O(1)* Worst= O(n) |
*Depends on uniform hashing
Classic time-space tradeoff
Analysis: Sorting Algorithms
Algorithm | Time | Auxiliary Space |
Selection Sort | Best = Worst = O(n2) | O(1) |
Insertion Sort | Best = O(n) Worst = O(n2) | O(1) |
Merge Sort | Best = Worst = O(n log n) | O(n) |
Quick Sort | Average = Best = O(n log n) Worst = O(n2) | O(1) |
Sorting algorithms are an example of the time-space tradeoff.
CS 136: Learning Goals
Analysis
Tradeoffs of Time and Space
Advanced Programming
OOP, Java, JUnit, Git
ADTs &
Data Structures
Use & Implement
Lab progression
Lab 0: “Onboarding”
Final project: Open-ended! Aim to have you be a independent, proficient programmer
Lab progression
Lab 1
Lab 6:
Binary Search Trees
Lab 8: Graphs &
Dijkstra’s algorithm
Lab 7:
Tries
1. How has your understanding of data structures and programming changed since February?
2. What are you excited to keep learning about after this class end?
Student Course Survey (SCS)
Instructions:
To access:
SCS
(~15 minutes)
Q6. For CS “feedback from instructor” also includes:
Final exam logistics
Final exam logistics
Breakdown of points
Total points = expected number of minutes the exam should take
Breakdown of points can help you weight the importance of studying different topics
Tip: Review the learning objectives of the labs
Review: Binary Search Tree to implement a Symbol Table
To implement a Symbol Table with a Binary Search Tree:
'E'
root node
the key of this node is ‘E’
105
'S'
30
'X'
106
'A'
35
'C'
12
'H'
24
'R'
45
the value of this node is 105
Printing first n keys in alphabetical order
this.countPrint;
…
public void inOrderTraversalPrint(Node node, int n) {
if (node == null || this.countPrint >= n) {
return;
}
// Traverse left
inOrderTraversalPrint(node.left, n);
// Print center/parent node
if(this.countPrint < n){
System.out.println(node.key);
this.countPrint++;
}
// Traverse right
inOrderTraversalPrint(node.right, n);
}
Instance variable (earlier in the class)
Tip: Review the think-pair-shares
Tip: Reading the book now can also solidify concepts!
https://algs4.cs.princeton.edu/home/
Tips for Final Exam Studying
Today’s agenda