CSC 263 H1
Worth: 8%
Assignment # 2
Fall 2015
Due: By 5:59pm on Tuesday 13 October
Remember to write the full name and student number of every group member prominently on
your submission.
Please read and understand the policy on Collaboration given on the
READING: Sections 11.1, 11.2, 11.3 (except 11.3.3).
SELFTEST: Exercises 11.11, 11.21, 11.22.
Hashing
Problem 1: Read a text file, keep track of number of occurrences of each
character (ASCII codes 0 127).
Solution? Directaddress table: store number of occ
An undirected graph G = (V,E) is called "bipartite" when the vertices can be
partitioned into two subsets V = V_1 u V_2 (with V_1 n V_2 = cfw_) such that
every edge of G has one endpoint in V_1 and the other in V_2 (equivalently,
no edge of G has both end
CSC 263 H1
Worth: 2%
Problem Set # 8
Fall 2014
Due: By 9:59pm on Wednesday 19 November
Remember to write your full name and student number prominently on your submission.
Please read and understand the policy on Collaboration given on the Course Informati
CSC 263 H1
Worth: 2%
Problem Set # 3
Fall 2014
Due: By 9:59pm on Wednesday 1 October
Remember to write your full name and student number prominently on your submission.
Please read and understand the policy on Collaboration given on the Course Information
CSC 263 H1
Worth: 2%
Problem Set # 6
Fall 2014
Due: By 9:59pm on Wednesday 5 November
Remember to write your full name and student number prominently on your submission.
Please read and understand the policy on Collaboration given on the Course Informatio
CSC 263 H1
Worth: 2%
Problem Set # 7
Fall 2014
Due: By 9:59pm on Wednesday 12 November
Remember to write your full name and student number prominently on your submission.
Please read and understand the policy on Collaboration given on the Course Informati
CSC 263 H1
Worth: 2%
Problem Set # 2
Fall 2014
Due: By 9:59pm on Wednesday 24 September
Remember to write your full name and student number prominently on your submission.
Please read and understand the policy on Collaboration given on the Course Informat
CSC 263 H1
Problem Set # 1
Worth: 2%
Fall 2014
Due: By 9:59pm on Wednesday 17 September
Remember to write your full name and student number prominently on your submission.
Please read and understand the policy on Collaboration given on the Course Informat
CSC 263 H1
Worth: 2%
Problem Set # 5
Fall 2014
Due: By 9:59pm on Thursday 30 October
Remember to write your full name and student number prominently on your submission.
Please read and understand the policy on Collaboration given on the Course Information
CSC 263 H1
Assignment # 1Complete
Worth: 12%
Fall 2014
Due: By 9:59pm on Thursday 16 October
Remember to write the full name and student number of every group member prominently on
your submission.
Please read and understand the policy on Collaboration gi
CSC 263 H1
Problem Set # 4
Worth: 2%
Fall 2014
Due: By 9:59pm on Wednesday 8 October
Remember to write your full name and student number prominently on your submission.
Please read and understand the policy on Collaboration given on the Course Information
1. Prove an Omega(m log n) bound on the worst-case sequence complexity of m
MAKE-SET, UNION, and FIND-SET operations (n of which are MAKE-SET) using
the tree implementation with only union-by-rank (no path compression).
In order to answer this question, y
READINGS: Chapter 6.
SELFTEST: Exercises 6.11, 6.14, 6.24.
Priority Queues
"Priority queue": like a queue except every item has a "priority" (usually a
number) that determines retrieval order. More formally, a priority queue
consists of a set of elements
READING: Chapter 23.
SELF-TEST: Exercise 23.1-1, 23.2-2.
Minimum Spanning Trees
Let G = (V,E) be a connected, undirected graph with
edge weights w(e) for each edge e in E.
A tree is a subset of edges A such that
A is connected and does not contain a cycle
CSC 263 H1
Worth: 8%
Assignment # 1
Fall 2015
Due: By 5:59pm on Tuesday 29 September
Remember to write the full name and student number of every group member prominently on
your submission.
Please read and understand the policy on Collaboration given on t
CSC 263 H1
1.
Assignment # 1Sample Solutions
Fall 2015
(a) In the best case, A[1], the rst element we check, is v, so we nd v after one comparison, i.e.,
Line #2 is executed only once.
(b) The probability of the best case is the probability that we choose
CSC 263 H1
1.
Assignment # 2Sample Solutions
Fall 2015
(a) We use two AVL trees with keys sorted in dierent ways. Each node corresponds to one
position (x, y), and each nodes stores the set of colours (e.g., cfw_R, G) that are assigned to this
position.
(
READING: Sections 22.2, 22.3.
SELF-TEST: Exercise 22.3-2.
Last week Larry taught the BFS algorithm.
Q: What did we use to avoid getting caught in an infinite loop?
A: colours
Q: What did we end up with?
A: BFS Tree over the graph which gave shortest path
READINGS: Chapters 2, 3; Sections 4.5, 5.1, 5.2.
Data Structures
"Abstract Data Type" (ADT) set of objects together with set of operations
on these objects, e.g.:
1. Objects: integers
Operations: ADD(x,y), MULTIPLY(x,y), etc.
2. Stack
Objects: lists (or s
The "complete graph" K_n is the undirected graph on n vertices with every
pair of vertices connected by an edge.
1. Draw K_1, K_2, K_3, K_4 and K_5.
Write down the adjacency lists representation for K_5.
Write down the adjacency matrix representation for
READING: Sections 21.1, 21.2, 21.3.
SELF-TEST: Exercise 21.2-2.
Disjoint Sets
Disjoint Set ADT:
- Objects: Collection of nonempty disjoint sets S = cfw_S_1,S_2,.,S_k
each S_i is a nonempty set that has _no_ element in common with any
other S_j (S_i n S_j
READINGS: Part III (introduction), Sections 12.1, 12.2, 12.3.
SELFTEST: Exercises 12.23, 12.31.
Dictionaries
Dictionary ADT (slightly different version than textbook):
Objects:
Sets S where each element x has field x.key some totally ordered value.
Assump
READING: Sections 8.1, 9.1.
SELF-TEST: Exercise 8.1-1.
Lower Bounds
How fast can we sort?
- Existence of algorithms that run in worst-case time O(n log n) confirm
sorting can be done in time O(n log n), but does not rule out existence
of other algorithms
READING: Chapter 17.
SELF-TEST: Exercises 17.1-2.
Amortized Analysis
- Often, we perform _sequences_ of operations on data structures and time
complexity for processing the entire sequence is important.
- We define "worst-case sequence complexity" of sequ
READINGS: Problem 133, Sections 14.1, 14.2.
SELFTEST: Exercises 14.11, 14.12.
Mechanism to rebalance BST: "rotations"
y
right rotation
/\
>
/\
x C
/\
A y
left rotation
A B
x
<
/\
B C
Three references to change: parent's left/right, y.left, x.right.
Decrea
1. Let G = (V,E) be a weighted connected undirected graph with n vertices
and m edges. Write an O(m log(n) algorithm for finding E_cfw_min, a set
of edges of minimum total weight such that every cycle in G contains at
least one edge in E_cfw_min.
Hint: Co
READING: Chapter 7.
SELFTEST: Exercises 7.11, 7.22.
QuickSort
The following algorithm sorts an input sequence S in nondecreasing order.
QuickSort(S):
1.
if |S| <= 1: return S
else:
2.
select pivot p in S
3.
partition elements of S into:
L = elements of S