1 of 28

Lecture 30:

Review & Wrap-Up

CS 136: Spring 2024

Katie Keith

2 of 28

  • Final project presentations next week. Schedule here
    • Please attend to support your classmates and learn new data structures!
    • Any remaining lecture time will be project work time / open help session
    • Present what you have completed so far (ok if you are not fully finished)
  • Final projects due to Gradescope May 14 at 4pm (hard deadline set by the College)
  • Katie’s office hours next Monday 2-5pm
  • Review session Sunday, May 12, 7-8pm

📣 Announcements

3 of 28

Today’s agenda

  • Review & Reflection (15-20 minutes)
  • Student Course Survey (SCS) (15-20 minutes)
  • Final exam information (15 minutes)

4 of 28

CS 136: Learning Goals

Analysis

Tradeoffs of Time and Space

Advanced Programming

OOP, Java, JUnit, Git

ADTs &

Data Structures

Use & Implement

5 of 28

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.

6 of 28

ADTs to Data Structures

ADTs

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

7 of 28

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

8 of 28

ADTs to Data Structures

Hash Table

w/ separate chaining

ADTs

Data Structures

Binary Search Tree

Hash Table

w/ linear probing

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

9 of 28

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

10 of 28

CS 136: Learning Goals

Analysis

Tradeoffs of Time and Space

Advanced Programming

OOP, Java, JUnit, Git

ADTs &

Data Structures

Use & Implement

11 of 28

Running time of algorithms of different orders of growth

Very long = exceeds 10^25 years

Our running example: n is the number of elements in an array

12 of 28

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.

13 of 28

CS 136: Learning Goals

Analysis

Tradeoffs of Time and Space

Advanced Programming

OOP, Java, JUnit, Git

ADTs &

Data Structures

Use & Implement

14 of 28

Principles of software development

Iterative Development

Compile often, execute often, test often.

Test-Driven Development

First write tests, then write code to pass those tests.

15 of 28

Lab progression

Lab 0: “Onboarding”

Final project: Open-ended! Aim to have you be a independent, proficient programmer

16 of 28

Lab progression

Lab 1

Lab 6:

Binary Search Trees

Lab 8: Graphs &

Dijkstra’s algorithm

Lab 7:

Tries

17 of 28

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?

18 of 28

Student Course Survey (SCS)

Instructions:

  • These end-of-semester course evaluations help improve this course for other students and are used by Williams to determine whether I remain a professor here
  • You may skip questions you don’t wish to answer and there is no penalty for choosing not to participate
  • All your answers are confidential and I will only receive a report after I have submitted final grades for this class

To access:

  • Log into Glow
  • On Glow, you’ll see a course called “Course Evaluations”
  • Fill out the evaluation for CS 136

19 of 28

SCS

(15-20 minutes)

Q6. For CS “feedback from instructor” also includes:

  • Lab autograder
  • Lab 1-on-1’s

20 of 28

Final exam

  • May 16 from 9:30am-12pm in Physics 203
  • 2 hours + 30 minute reading period (I’m writing the exam to take 2 hrs)
  • Covers all material Lecture 0 through (and including) Lecture 27
  • Accommodations → email Katie
  • Emphasis on problem-solving
    • Pen & paper exam. You’ll read some code, write some code, answer some conceptual questions
  • Closed book, closed notes except for:
    • Allowed one 8.5x11 hand-written reference sheet (front & back)

21 of 28

Breakdown of points

Total points = total number of minutes the exam should take you

Breakdown of points can help you weight the importance of studying different topics

22 of 28

Tips for Final Exam Studying

  • Create study groups
  • Review your labs
  • Readings from the textbook
  • Exercises from the textbook
  • Review your midterm/midterm corrections
  • Practice exam from Jim:
    • Disclaimer: He may have covered a different subset of material than we did

23 of 28

Binary Search Tree to implement a Symbol Table

To implement a Symbol Table with a Binary Search Tree, the keys of nodes still obey the left subtree/right subtree ordering and nodes also have an associated value.

In order traversal!

24 of 28

Binary Search Trees (Lab 6)

public class BinarySearchTree<Key, Value> implements SymbolTable<Key, Value>{

public Node first; // Root of BST

public int countPrint; // Number already printed for order traversal

public int size; // Number of key-value pairs

public class Node {

public Key key; // sorted by key

public Value val; // associated data

public Node left, right; // left and right subtrees

public Node(Key key, Value val) {

this.key = key;

this.val = val;

}

25 of 28

BST put

public void put(Key key, Value val, Comparator comparator){

first = putHelper(first, key, val, comparator);

}

private Node putHelper(Node x, Key key, Value val, Comparator comparator) {

if (x == null){

this.size += 1;

return new Node(key, val);

}

int cmp = comparator.compare(key, x.key);

if (cmp < 0) x.left = putHelper(x.left, key, val, comparator);

else if (cmp > 0) x.right = putHelper(x.right, key, val, comparator);

else x.val = val;

return x;

}

26 of 28

BST get

public Value get(Key key, Comparator comparator){

return getHelper(this.first, key, comparator);

}

public Value getHelper(Node x, Key key, Comparator comparator){

if(x == null){return null;}

int cmp = comparator.compare(key, x.key);

if (cmp < 0) return getHelper(x.left, key, comparator);

else if (cmp > 0) return getHelper(x.right, key, comparator);

else return x.val;

}

27 of 28

In-order traversal

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);

}

Number to print

28 of 28

Today’s agenda

  • Review & Reflection (15-20 minutes)
  • Student Course Survey (SCS) (15-20 minutes)
  • Final exam information (15 minutes)