Discussion 12
CS 61B
Spring 2015
1 Quicksort
(a) Sort the following unordered list using quicksort. Assume that the pivot you use is always
the rst element. Show the steps taken at each partitioning step.
34, 25, 82, 34, 28, 16, 75, 96
28 25 16 | 34 34 |
CS 61B
Discussion 8
Spring 2017
1 More Running Time
Give the worst case and best case running time in () notation in terms of M and N.
(a) Assume that comeon() (1) and returns a boolean.
1
2
3
4
5
6
for (int i = 0; i < N; i += 1) cfw_
for (int j = 1; j <=
CS 61B
Discussion 11 Exam Prep Spring 2017
1 Warmup with DFS and BFS
1. For the graph above, give the vertices in the order theyd be visited by depth first search
starting from vertex A, assuming that we always visit alphabetically earlier vertices first
Discussion 10
CS 61B
Spring 2016
1 Heaps of fun
(a) Assume that we have a binary min-heap (smallest value on top) data structure called Heap
that stores integers, and has properly implemented insert and removeMin methods.
Draw the heap and its correspondi
CS 61B
Discussion 11 Exam Prep Spring 2017
1 Warmup with DFS and BFS
1. For the graph above, give the vertices in the order theyd be visited by depth first search
starting from vertex A, assuming that we always visit alphabetically earlier vertices first
CS 61B
Discussion 12 Exam Prep Spring 2017
1 Running MST and SP Algorithms (Spring 2015 Final Q1/9)
(a) For the graph below, use Kruskals algorithm to find the MST. The number on each edge is
the weight, and the letter is a unique label you should use in
Discussion 11
CS 61B
Spring 2017
1 Datastructures and Graph Traversals
In order to implement DFS and BFS, we must add neighbors to a data structure (usually called the
fringe) each time we visit a node, but the choice of data structure is very important a
CS 61B
Discussion 13
Spring 2015
1 Graph Representations
For the graph above, draw the adjacency list and adjacency matrix representation.
2 DFS and BFS
Give the DFS Preorder, DFS Postorder, and BFS order of the graph starting from vertex A. Whenever ther
Discussion 11
CS 61B
Spring 2015
1 Sorting I
Show the steps taken by each sort on the following unordered list:
106, 351, 214, 873, 615, 172, 333, 564
(a) Insertion sort. Show the sorted and unsorted portions at every step.
106
106
106
106
106
106
106
106
Discussion 9
CS 61B
Spring 2015
1 2-3-4 Tree Insertion and Deletion
Given the following 2-3 tree, draw what the tree would look like after inserting 18.
Original tree:
[8]
/
\
[6]
[14]
/
\
/
\
[3] [7] [10] [15, 16]
After inserting 18:
[8]
/
\
[6]
[14, 16]
Discussion 8
CS 61B
Spring 2015
1 Conceptual Check
Order the following big-O runtimes from most to least efcient:
O(n log n), O(1), O(2n ), O(n2 ), O(log n), O(n), O(n!)
O(1) O(logn) O(n) O(nlogn) O(n2 ) O(2n ) O(n!)
Are the statements in the right column
CS61B Spring 2015 Guerrilla Section 3 Worksheet
SOLUTIONS
Leo Colobong, Nick Fong, Jasmine Giang, Laura Harker, Yujie Huang, Anusha Ramakuri,
Nick Rose, Khalid Shakur, Jason Won, Fan Ye, Jason Zhang, Giulio Zhou
7 May 2015
Directions: In groups of 4-5, wo
CS61B Spring 2015 Guerrilla Section 2 Worksheet
SOLUTIONS
Akhil Batra, Leo Colobong, Nick Fong, Jasmine Giang, Laura Harker, Anusha Ramakuri,
Charles Zhang, Jason Zhang, Giulio Zhou
14 March 2015
Directions: In groups of 4-5, work on the following exercis
1. Basic Operations (6 Points).
a. To the right of the BST below, draw a BST that results if we delete 20 from the BST. You should
use the deletion procedure discussed in class (i.e. no more than 4 references should change). Either of
the two trees in red
CS61B Spring 2015 Guerrilla Section 1 Worksheet
SOLUTIONS
Leo Colobong, Nick Fong, Jasmine Giang, Andrew Huang, Yujie Huang, Nick Rose,
Khalid Shakur, Jason Won
15 February 2015
Directions: In groups of 4-5, work on the following exercises. Do not proceed
UC Berkeley Computer Science
CS61B: Data Structures
Midterm #1, Spring 2015
This test has 9 questions worth a total of 35 points. The exam is closed book, except that you are
allowed to use a one page written cheat sheet. No calculators or other electroni
CS 61B
2017
Discussion 13 Exam Prep Sol Spring
1 Distinguishing Sorts (Fall 2016 Final Q4)
Below you will find intermediate steps in performing various sorting algorithms on the same input
list. The steps do not necessarily represent consecutive steps in
CS 61B
Discussion 12
Spring 2017
1 Dijkstras Algorithm
For the graph below, let g(u, v) be the weight of the edge between any nodes u and v. Let
h(u, v) be the value returned by the heuristic for any nodes u and v.
Edge
g(A,
g(B,
g(C,
g(C,
g(F,
g(A,
g(D,
CS 61B
Discussion 13
Spring 2016
1 Quicksort
(a) Sort the following unordered list using stable quicksort. Assume that the pivot you use is
always the first element and that we use the 3-way merge partitioning process described in
lecture and lab last wee
CS 61B
Discussion 9 Exam Prep Spring 2017
1 Warmup (Spring 2015 MT2: 1c)
Draw the External Chaining Hash Set that results if we insert 5. As part of this insertion, you
should also resize from 4 buckets to 8 (in other words, the implementer of this data s
Discussion 9
CS 61B
Spring 2017
1 Fun with Hash Functions (CS 61BL Summer 2014 Midterm 2)
Here are three potential implementations of the Integers hashCode() function. Categorize
each as either a valid or an invalid hash function. If it is invalid, explai
Discussion 7
CS 61B
Spring 2017
1 Welcome O & Omega, s Not Alone!
Order the following big-O runtimes from most to least efficient:
O(log n), O(1), O(nn ), O(n3 ), O(n log n), O(n), O(n!), O(2n ), O(n2 log n)
Are the statements in the right column true or
CS 61B
Discussion 7 Exam Prep Spring 2017
1 Syntax Mastery (Spring 2015 Final Q5)
Give the output of main. You may not need all lines.
public class Sklarp implements Iterable <Character>, Iterator <Character> cfw_
public char[] contents;
public char magic
CS 61B
Discussion 10
Spring 2017
1 Heaps of fun
(a) Assume that we have a binary min-heap (smallest value on top) data structure called Heap
that stores integers, and has properly implemented insert and removeMin methods.
Draw the heap and its correspondi
CS 61B
Discussion 6 Exam Prep Spring 2017
1 Exceptions (Spring 2016 MT2 Q3)
Consider the code below. Recall that x / 2 rounds down to the nearest integer.
public static void checkIfZero(int x) throws Exception cfw_
if (x = 0) cfw_
throw new Exception("x w
CS 61B
Discussion 6
Spring 2017
1 Immutable Rocks
A class is immutable if nothing about its instances can change after they are constructed. Which
of the following classes are immutable?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
CS 61B
Discussion 8 Exam Prep Spring 2017
1 Warmup
Given the following method on a sorted array, what is the worst-case runtime?.
1
2
3
4
5
6
7
8
public static int f1(int i, int[] numList) cfw_
for (int j = 0; j < numList.length; j+) cfw_
if (numList[j] =
Main
Lab 1b
Navigation
Installing Java
Course Info
Staff
Assignments
Resources
Piazza
Lab 1b: Setting Up Your
Computer
A. Windows Setup
B. OS X Setup
C. Unix and Linux Setup
D. Test Run
Installing Java
1. You'll need to install the Java 1.8 JDK in order t
CS 61B
Discussion 13 Exam Prep Spring 2017
1 Distinguishing Sorts (Fall 2016 Final Q4)
Below you will find intermediate steps in performing various sorting algorithms on the same input
list. The steps do not necessarily represent consecutive steps in the
CS 61B
Discussion 12
Spring 2017
1 Dijkstras Algorithm
For the graph below, let g(u, v) be the weight of the edge between any nodes u and v. Let
h(u, v) be the value returned by the heuristic for any nodes u and v.
Edge
g(A,
g(B,
g(C,
g(C,
g(F,
g(A,
g(D,
CS 61B
Discussion 12 EP Sol
Spring 2017
1 Running MST and SP Algorithms (Spring 2015 Final Q1/9)
(a) For the graph below, use Kruskals algorithm to find the MST. The number on each edge is
the weight, and the letter is a unique label you should use in you
Discussion 11
CS 61B
Spring 2017
1 Datastructures and Graph Traversals
In order to implement DFS and BFS, we must add neighbors to a data structure (usually called the
fringe) each time we visit a node, but the choice of data structure is very important a
Discussion 13
CS 61B
Spring 2016
1 Quicksort
(a) Sort the following unordered list using stable quicksort. Assume that the pivot you use is
always the first element and that we use the 3-way merge partitioning process described in
lecture and lab last wee
CS 61B
Discussion 10 Exam Prep Spring 2017
1 Basic Operations (Spring 2015 MT2 Q1)
a. To the right of the BST below, draw a BST that results if we delete 20 from the BST. You should
use the deletion procedure discussed in class (i.e. no more than 4 refere