CSC 263 H1
Worth: 2%
Problem Set # 1
Winter 2015
Due: By 5:59pm on Tuesday 13 January
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
CSC373S
Selected solutions for Problem Set 1
Spring, 2008
Due: Wed, January 30, beginning of lecture
1. This question concerns Dijkstras shortest (i.e. least cost) paths algorithm. (See
section 4.4).
(a) Construct an example of an edge weighted directed g
=
CSC 263
Tutorial Exercise for Week 1
=
Consider the following algorithm to find the maximum element in a list.
FIND-MAX(L):
max = -oo # minus infinity
for k = L.length-1,.,1,0:
if L[k] > max:
max = L[k]
return max
For this problem, we are interested in
CSC 263 H1
Worth: 12%
Assignment # 1
Winter 2015
Due: By 5:59pm on Tuesday 10 February
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
Winter 2015
MOCK MidtermSolutions
CSC 263 H1
Question 1. [9 marks]
Consider the following Python code which simulates rolling a pair of dice and counting the number
of rolls until we reach n pairs. We are interested in the number of time the random.randin
Fibonacci (Min-)Heap
a forest of heap-order trees (parent priority child priority)
roots in circular doubly-linked list
pointer to minimum-priority root
siblings in circular doubly-linked list;
parent knows just one arbitrary child
23
7
3
18
39
52
17
38
4
Union-Find
Union-nd stores a bunch of disjoint sets. Supports:
from a member, nd its owning set
union two sets
Basic idea:
Each set is a directed tree. Members are vertices.
Use root to stand for the set.
Edges go from children to parents. (So, only paren
Random, Average, Probability
Some algorithms have terrible worst-case times, but:
on random input, they are fast on average
or, they contain randomizing steps, and are fast on average
We will study their average case times.
(Harder, rarely done in this co
Introduction
Today we begin studying how to calculate the total time of a
sequence of operations as a whole.
(As opposed to each operation individually.)
Why and when we care:
you have an algorithm that uses a certain data structure
some operation takes a
Hash Tables
Assume you can map keys to natural numbers from 0 to m 1.
Call that function h.
Use an array A of length m.
Put key k in A[h(k)]. Except. . .
What if h maps several different keys to the same number?
Solution:
A is an array of lists. Put key k
Shufing An Array
for i from 1 to n 1: (where n = A.length)
swap A[i] with A[random(i, n)]
1 / 10
Shufing An Array
for i from 1 to n 1: (where n = A.length)
swap A[i] with A[random(i, n)]
Every nal permutation is equally likely. To see why:
Example: initia
Motivation
Old storage organization:
CPU
RAM
disk
slow
cache
RAM
slow
Modern storage organization:
CPU
Data stored in the slow device. But read/write is per block.
Want to read/write fewer blocks.
Want to take full advantage of each block.
1 / 19
B-Trees,
1)
(a) The best case complexity of LastOne is O(1). In the best case, the input array of size n is an array
containing all 0s. Since the array contains only 0s, the two while loops will only execute once to check its
condition. This is because p = (m - 1)
Kao-Tsun Chang 1000064681
csc263, Fall 2014
Exercise 2
(a)
return min1(A, k):
S := array()
Build-Min-heap(A)
for 1 to k cfw_
x := extract Min(A)
S.append(x)
for item in S cfw_
print item
(b)
The algorithm from (a) has the following runtime: The second l
CSC263 Winter 2015
Data Structures and Analysis
Section L0301
Larry Zhang
Email: [email protected]
Office: BA5206
The teaching team
Instructors:
Michelle Craig (L0101, L0201)
Larry Zhang (L0301)
Franois Pitt (L5101)
TAs:
Mohamed Aballa, Eric Banna
CSC263 Week 2
If you feel rusty with probabilities, please
read the Appendix C of the textbook. It is
only about 20 pages, and is highly relevant to
what we need for CSC263.
Appendix A and B are also worth reading.
This week topic
ADT: Priority Queue
Da
Introduction
c
8
b
7
d
2
9
4
4
a
i
11
e
14
7
8
10
h
f
6
1
g
2
These are computers and costs of direct connections. What is a
cheapest way to network them?
1 / 25
(Edge-)Weighted Graph
Many useful graphs have numbers attached to edges.
Think of: each edge
http:/goo.gl/forms/S9yie3597B
Thursday
CSC263 Week 7
PS5 out, due next Tuesday
Pre-test office hour today at BA5287
11am~1pm, 2pm~4pm
Announcement
But unlike average-case analysis, there is NO probability
or expectation involved.
The amortized sequence
Weight-balanced Binary Search Trees
Weight-balanced BSTs are one way to achieve (log(n) tree
height.
A weight-balanced BST:
is a binary search tree
at every node v:
size(v.left) + 1
1
3
3 size(v.right) + 1
Equivalently:
size(v.left) + 1 (size(v.right) + 1
This Course Is About. . . (1/2)
Data structures: how to store data.
Examples: arrays, linked lists.
This course goes way beyond them.
But why? Why other data structures?
Because you need this course to graduate. :)
1 / 30
This Course Is About. . . (1/2)
D
%
%
%
%
%
%
Assignment Document Class (for CSC263)
Copyright 2013, David Liu
Modified by Larry Zhang, 2016
Note to students: while you need to have this file to compile the problem
set files, you don't need to understand the contents of this file to be
su
CSC263H, Summer 2016
Assignment 2
Name: JingXi, Hao; Ye, Cao
Student Number: 1000654188; 1001237422
Due June 17th, 2016 Midnight
1. For this question you will design algorithms that utilizes data structures we have seen in class to solve
a problem.
Consid
Sample Solutions
CSC 263H
June 9, 2016
This document is a guide for what I would consider a good solution to problems in this course. You
may also use the TeX file to build your solutions.
1. Consider the following problem we have seen in class:
We have a
CSC263H, Summer 2016
Assignment 1
Name: JingXi, Hao; Ye, Cao
Student Number: 1000654188; 1001237422
Due May 27th, 2016 Midnight
1. Consider the implementation of MergeSort from tutorial. We modify it by replacing the base case
with the following:
If L k,
CSC263 Winter 2017
Data Structures and Analysis
Week 1
1
Larry Zhang (Coordinator)
Email: [email protected]
Office: DH-3076
Dan Zingaro
[email protected]
Office: DH-3078
2
Outline for today
Why take CSC263?
What is in CSC263?
How to do we