CS/SE 2C03. Sample solutions to the assignment 2.
Total of this assignment is 198pts, but 100% = 181pts. There are bonus 17 points. Each
assignment is worth 7%. Some solutions below are just sketches.
CS/SE 2C03. Sample solutions to the assignment 4.
Total of this assignment is 203 pts. Each assignment is worth 7%.
If you think your solution has been marked wrongly, write a short memo stating
where
CS/SE 2C03. Sample solutions to the assignment 3.
Total of this assignment is 220pts, but 100% = 195 pts. There are 25 bonus points. Each
assignment is worth 7%. Some solutions below are just sketches
SE/CS 2c03. Sample solutions to the assignment 3.
Total 235 pts. Each assignment is worth 7%.
If you think your solution has been marked wrongly, write a short memo stating
where marking in wrong and
CS/SE 2C03. Sample solutions to the assignment 1.
Total of this assignment is 131pts, but 100% = 111pts. There are 21 bonus points. Each
assignment is worth 7%.
If you think your solution has been mar
Algorithms
HAYA ELGHALAYINI
STACKS AND QUEUES
http:/algs4.cs.princeton.edu
Algorithms
R OBERT S EDGEWICK | K EVIN W AYNE
1.3 BAGS, QUEUES,
STACKS
stacks
Queues
applications
http:/algs4.cs.princeton
Algorithms
R OBERT S EDGEWICK | K EVIN W AYNE
2.4 H EAPSORT D EMO
Algorithms
F O U R T H
E D I T I O N
R OBERT S EDGEWICK | K EVIN W AYNE
http:/algs4.cs.princeton.edu
Heapsort demo
Heap construction.
Algorithms
R OBERT S EDGEWICK | K EVIN W AYNE
2.3 P ARTITIONING D EMOS
Sedgewick 2-way partitioning
Dijkstra 3-way partitioning
Algorithms
F O U R T H
E D I T I O N
R OBERT S EDGEWICK | K EVIN W AYN
2C03
ALGORITHMS
AND
DATA STRUCTURES
COPYRIGHT ROBERT SEDGEWICK
KEVIN WAYNE
2C03 course overview
data types
sorting
searching
graphs
strings
advanced
Why study algorithms?
Why study algorithms?
Why stu
Algorithms
R OBERT S EDGEWICK | K EVIN W AYNE
2.3 Q UICKSORT D EMO
Algorithms
F O U R T H
E D I T I O N
R OBERT S EDGEWICK | K EVIN W AYNE
http:/algs4.cs.princeton.edu
Quicksort
Basic plan.
input
Q
U
Algorithms
R OBERT S EDGEWICK | K EVIN W AYNE
2.1 S ELECTION S ORT D EMO
Algorithms
F O U R T H
E D I T I O N
R OBERT S EDGEWICK | K EVIN W AYNE
http:/algs4.cs.princeton.edu
Selection sort demo
In ite
Algorithms
R OBERT S EDGEWICK | K EVIN W AYNE
3.1 S YMBOL T ABLES
API
elementary implementations
Algorithms
F O U R T H
E D I T I O N
R OBERT S EDGEWICK | K EVIN W AYNE
http:/algs4.cs.princeton.edu
Algorithms
R OBERT S EDGEWICK | K EVIN W AYNE
2.2 M ERGING D EMO
Algorithms
F O U R T H
E D I T I O N
R OBERT S EDGEWICK | K EVIN W AYNE
http:/algs4.cs.princeton.edu
Merging demo
Goal. Given two sorte
Algorithms
R OBERT S EDGEWICK | K EVIN W AYNE
2.1 I NSERTION S ORT D EMO
Algorithms
F O U R T H
E D I T I O N
R OBERT S EDGEWICK | K EVIN W AYNE
http:/algs4.cs.princeton.edu
Insertion sort demo
In ite
Algorithms
R OBERT S EDGEWICK | K EVIN W AYNE
3.2 B INARY S EARCH T REES
BSTs
ordered operations
Algorithms
F O U R T H
E D I T I O N
R OBERT S EDGEWICK | K EVIN W AYNE
http:/algs4.cs.princeton.edu
CS/SE2C03.
Assignment #2. New version slightly different Question 9. Due February 28 (Tuesday),
2012, in class. Please put you assignment in an envelope with your name and student
number.
1.
Suppose y
CS/SE 2C03. Sample solutions to the assignment 1.
Total of this assignment is 131pts, but 100% = 111pts. There are 21 bonus points. Each
assignment is worth 7%.
If you think your solution has been mar
CS/SE2C03
Assignment #3. Due March 22 (Thursday), 2012, in class. Please put you assignment in an
envelope with your name and student number. Please put you assignment in an envelope
with your name an
CS/SE2C03
Assignment #4. Due April 4 (Wednesday), 2012, during a tutorial. Please put your
assignment in an envelope with your name and student number.
1.
For the graph below apply Ford-Fulkerson algo
SE2C03. Sample solutions to the assignment 2.
Total of this assignment is 205 pts. Each assignment is worth 7%.
If you think your solution has been marked wrongly, write a short memo stating
where mar
SOLUTIONS TO THE MIDTERM TEST
1.[10] a.[5]
b.[5]
6n3/(log n + 1) = O(n3)
Let c=7, n0=2. For all n 2, log n 1, and log n +1 2
Then, 6n3/(log n +1) 6n3/2 = 3n3 7n3 hold.
10n3 +9 = O(n).
We have to find
Solutions to Midterm
1.[10] a.[5] Using only definition of O(f(n) prove that the following statement is true:
2n2/(log n + 1) = O(n2)
b.[5] Using only definition of O(f(n) prove that the following sta
Algorithms
R OBERT S EDGEWICK | K EVIN W AYNE
2.1 H- SORTING D EMO
Algorithms
F O U R T H
E D I T I O N
R OBERT S EDGEWICK | K EVIN W AYNE
http:/algs4.cs.princeton.edu
h-sorting demo
In iteration i, s
Algorithms
R OBERT S EDGEWICK | K EVIN W AYNE
2.4 B INARY H EAP D EMO
Algorithms
F O U R T H
E D I T I O N
R OBERT S EDGEWICK | K EVIN W AYNE
http:/algs4.cs.princeton.edu
Binary heap demo
Insert. Add
Data Structures & Algorithms (2C03)
HAYA ELGHALAYINI
ANALYSIS OF ALGORITHMS
http:/algs4.cs.princeton.edu
Algorithms
R OBERT S EDGEWICK | K EVIN W AYNE
1.4 A NALYSIS
A LGORITHMS
OF
introduction
obser