Cmput 204
Seminar 6
Feb 22+23, 2016
Midterm practice. (Note: the topics in these questions are potentially different
from questions on the midterm.)
1. Prove directly from the definitions of O() and () that:
(a) If f (n) = O(n) and g(n) = O(n2 ), then f (
cmput 204
seminar 4
2014
Unless stated otherwise, variables are integers.
1. Assume that x and y are each kbit unsigned integers, with k 2.
(i) What is the min value of x? max value?
(ii) What is the exact formula (as a function of x) for k?
(iii) What i
cmput 204
seminar 1
2014 (revised 12 Sept)
Unless stated otherwise, variables are integers.
Dene as the golden ratio, i.e. (1 +
5)/2.
Dene f (n) as the nth Fibonacci number:
f (0) = 0, f (1) = 1, and, for all t 2, f (t) = f (t 1) + f (t 2).
Dene T (n) so
cmput 204
seminar 5
Dene, for all n 2, T (n) = 3T (n/2) + n2.
By hand, as in the lecture, solve the recurrence relation
Make the usual simplifying assumptions: T (1) = 1, n = 2k .
First, nd a closed form solution for T (n), as a function of k and/or n.
Th
cmput 204
seminar 2
2014
Unless stated otherwise, variables are integers.
1. One way to add k bits is to increase the sum by 1 each time a bit is 1. How long does this
method take? Hint: what is the runtime of the following algorithm?
def bincount(k): # n
cmput 204
seminar 3
2014
Unless stated otherwise, variables are integers.
1. By hand, compute 1123 mod 21.
2. By hand, trace recursive binary division of 91 12. Give the quotient and remainder.
3. Sort the following functions into buckets. Two functions s
cmput 204
seminar 6
2014
Draw the dfs forest of the graph below (include back edges as dashed lines, label
vertices with their pre/postorder time stamps). Give the number of components.
Draw the bfs forest (include cross edges as dashed lines, label each
cmput 204
seminar 7
2014
(i) In an undirected graph, the sum (over all vertices) of the degree of each
vertex equals _ times the number of edges.
(ii) In a directed graph, the sum (over all vertices) of the outdegree of each
vertex equals _ times the num
cmput 204
seminar 8
2014
Trace Dijkstras SSSP algorithm from node A on the graph with weights below.
Show distance, parent, inPQ? values each time a node has been removed from
the priorityqueue.
A
B
C
D
E
F
B
8
C
8
0
distance
A B C D
0   
D
9
9
3
E

cmput 204
seminar 9
2014
1. Trace Kruskals MST algorithm. Consider edges by nondecreasing weight; if
there is a tie, consider the edge which is rst in alphabetic order. In the UF
structure, use each root vertex as component label. Each time find(x) is ca
cmput 204
1. (i) p
seminar 10 hints
2014
1
2
=
n(n 1) 28
(ii) there is no problem with 2 components, but with 3 or more components,
the loop will never terminate, since the number of UF components will never drop
below the number of components in the gra
Cmput 204
Seminar 4
Feb 8+9, 2016
Unless stated otherwise, variables are integers.
1. (i) Using Euclids algorithm, find the gcd of 313 and 61.
(ii) Using the extended Euclid algorithm, express the gcd of 313 and 61 as a linear combination
of 313 and 61.
(
Cmput 204
Seminar 7
Feb 29 + Mar 1, 2015
1. Randomized selection algorithm best and worst case:
For the first two parts, consider the sequence S = [13, 4, 5, 1, 17, 16, 9] and show
at each level of recursion: 1.) all your random choices of v, 2.) the resu
Cmput 204
Seminar 8 Hints
Mar 7+8, 2016
1. See separate scan with handdrawn solution
2. (a) What is the length of visited at the time of the test marked by (*) above?
i
(b) What is the bestcase runtime in ()notation of this one test?
(1), happens when
Cmput 204
Seminar 5
Feb 8+9, 2016
Consider the recurrence T (n) = aT (dn/be) + O(nd ). In class we proved the Master Theorem for
the special cases when n is of the form n = bk . Here we will start to fill in some steps of the proof
for other, arbitrary va
CMPUT 201: Practical Programming Methodology
Guohui Lin
guohui@ualberta.ca
Department of Computing Science
University of Alberta
October 2016
Lecture 11: Pointers
Agenda:
One of the most important features
Pointer variables
The address and indirection
CMPUT 201: Practical Programming Methodology
Guohui Lin
guohui@ualberta.ca
Department of Computing Science
University of Alberta
October 2016
Lecture 17: Writing Large Programs
Agenda:
Dividing a program into files
Source files
Header files
Building a
CMPUT 201: Practical Programming Methodology
Guohui Lin
guohui@ualberta.ca
Department of Computing Science
University of Alberta
October 2016
Lecture 9: Functions
Agenda:
Definition
Defining and calling functions
Function declarations
Arguments
retur
CMPUT 201: Practical Programming Methodology
Guohui Lin
guohui@ualberta.ca
Department of Computing Science
University of Alberta
October 2016
Lecture 13: A Variant of Prims Algorithm
Agenda:
The minimum spanning tree problem
Prims algorithm
A variant (
Computing Science (CMPUT) 204
Algorithms I
Martin Mller
Department of Computing Science
University of Alberta
mmueller@ualberta.ca
Winter 2016
Notes for class today, Jan 6
CMPUT 204
Topics today:
How do we analyze algorithms?
Brief history of algorithms
F
Computing Science (CMPUT) 204
Algorithms I
Martin Mller
Department of Computing Science
University of Alberta
mmueller@ualberta.ca
Winter 2016
CMPUT 204
Part III
Divide and Conquer Algorithms
Notes for class today, Feb 1
CMPUT 204
Work on assignment 2, du
Cmput 204, Winter 2016
Assignment 2
Due: Feb 12, before class
Acknowledge all sources and collaborations. Give an acknowledgement statement, even if
you just say: I did not collaborate with anyone. If you do not give an acknowledgement
statement, your as
Cmput 204
Seminar 2
Jan 18+19, 2016
Notes:
Work on these questions in small groups. TA will help when needed.
Unless stated otherwise, variables are integers.
1. Prove by counterexample that the following statement is wrong:
1000n > n log n for all inte
Cmput 204
Seminar 3
Jan 25+26, 2016
Instructions: I recommend starting with question 4, then 5. Questions 1 and 2 are just tracing.
Question 3 is review. You need to first know what the question 4 algorithm does to do question 5.
Unless stated otherwise,
Cmput 204
Seminar 9
Mar 14+15, 2016
1. Prove: the strongly connected components (SCC) of a graph G are the same as the SCC of
its reverse GR .
Hint: use the definition of SCC  for each two nodes a, b in a SCC there is both a path from
a to b and a path f
Week 4: Heapsort, Quicksort
Agenda:
I
Heaps:
I
I
I
MaxHeapify
BuildMaxHeap
Heapsort
I
Priority Queues
I
Quicksort
Reading:
I
CLRS: 151169
CLRS: 170190
1/33
Week 4: Heaps
Heaps data structure (recall):
I
I
An array A[1.n] of n comparable keys (either
Week 1: Introduction, Basic Concepts
CMPUT204: Introduction to Algorithms
Agenda:
I
Course information
I
Algorithms concepts
I
Induction proofs
I
Pseudocode, RAM model
Textbook: pages 329, Cmput 272 material on Induction.
1/27
week 1: Introduction
Offic
Week 2: Types of analysis of algorithms, Asymptotic notations
Agenda:
I
Worst/Best/Avg case analysis
I
InsertionSort example
I
Loop invariant
I
Asymptotic Notations
I
Refreshment on logs and exps
Text p. 1623, 4859
Week 2: Insertion Sort
Insertion sort
Week 3: Solving recurrences
Agenda:
I
Divide and Conquer and analyzing recursive programs
I
Solving recurrences
I
Iterated substitution
I
Recursion tree method
I
Guess and test method
I
Master Theorem method
CLRS pages: 3039, 6567, 8397
1/28
Divide and
Homework Assignment #2
CMPUT 204
Department of Computing Science
University of Alberta
Due: 10am, Monday Feb 13, 2017
This assignment consists of two parts, the written question part given here, with total 80 marks, and
a quiz. The marking scheme is the