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 |
UNIVERSITY OF CALIFORNIA
Department of Electrical Engineering
and Computer Sciences
Computer Science Division
CS61B
Fall 2015
P. N. Hilnger
CS 61B: Introduction to Programming, Part II
General Course Information
Instructor:
Paul N. Hilnger, 787 Soda Hall,
A
get
B
C
size
D
containsKey
E
F
put
G
clear
A
get
B
C
size
D
containsKey
E
F
put
G
clear
A
B
C
D
E
F
G
A
B
C
D
E
F
G
A
B
C
D
E
F
G
A
B
C
D
E
F
G
A
B
C
D
E
F
D
B
A
F
C
E
G
G
A
A
A
B
B
C
C
C
B
C
bushiness is an intuitive concept
that we havent defined.
Ex
A Note for those Stumbling on these Slides (Hi!)
These lecture slides are not intended as written reference materials. Best
used in combination with videos and source code references.
See (Video) and (Code) links under each lecture of:
http:/berkeley-cs
CS61B Spring15 Discussion 11
In-Place Sort:
Keeps sorted items in original array (destructive)
No equivalent for linked list-based input
Stable Sort:
Keeps elements with equal keys in same relative
order in output as in input
Algorithm
Partition array
Announcements
For your project storage design plan:
Dont store everything in a giant blahblah.ser file. While this could
theoretically work, itd mean that every time you do a commit, you have to
rebuild the entire .ser file (which could take a long time)
Announcements
Midterm 2 is graded!
Grades released this evening (along with video walkthroughs).
Project 3:
The Boggle part of the project is now part of the gold points (was
previously required).
Project 2 feedback meetings co-opted by struggling-stude
Announcements
Announcement 1 (via Austin from HKN):
Drop-in tutoring exists. 11 AM - 5 PM every weekday (290 Cory and 345
Soda).
Schedule on website: https:/hkn.eecs.berkeley.edu/tutoring
Review session tomorrow night (but of course theres that project
The catch: On real machines, scheduling
execution of programs must be done by
an operating system. In practice requires
list of running programs sorted by sleep
time.
#
5
Sandra
Vanilla
Grimes
0
Lauren
Mint
Jon Talabot
11
Lisa
Vanilla
Blue Peter
9
Dave
C
CS61B
Lecture 9: Subtype Polymorphism
OOP and Polymorphism
Inheritance (is-a) in Java
Dynamic Method Selection
Subtleties
Motivation: Operating on Many Types
Lets design part of a programming language.
Goal: Given a shape stored in variable x, what sy
Now on to some new stuff.
Lets start with some experiments.
CS61B, Spring 2015
Lecture 5: Bit Operations and Binary, CS61C Preview
Numerical Types in Java
Binary Representations of Integers (61C Preview)
Binary and Java
(Extra) Pointers and Caching (6
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
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
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 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
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
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
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 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
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
G
F
C
B
E
F
A
insert
contains
Why not
k
e
v
b
a
g
d
f
p
j
m
y
r
x
z
contains
insert
a
z
f
j
r
d
x
m
contains
insert
Unordered arrays
are terrible (and so
are ordered ones).
But a third type of
array.
T
F
F
F
F
T
F
F
F
F
T
T
F
F
F
F
0
1
2
3
4
5
6
7
8
9
Announcements
1/26: Unix/VIM Workshop tonight in HP auditorium 6:30-9:00.
1/27: H(ackers)@B(erkeley) Workshop on Git in Woz from 8-10 PM [Melanie]
There will be a coding exercise today. We intend for you to write it on paper,
but if you want to do it on a
.
.
cap
cat
.
.
striking
.
.
.
.
cap
cat
.
.
striking
.
.
Called the pivot.
Called the pivot.
rp
bp
rp
bp
Q: How would we use this
operation for sorting?
Only size 1 problems remain, so were done.
Only size 1 problems remain, so were done.
Only size 1 pr
Quick Refresher of Hashing for HW7
By Chris Jeng, [email protected]
Basics of hashCode
(Head First Java talks about hashCode and HashSet on pg 559 for about six total pages, a very quick
and digestible read. This guide is going to suck, so you should defini
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
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 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] =