CPSC 221: Summer Term 2015
Laboratory Exercises 4
Exercises for Lab 4:
These must be completed and shown to your lab TA either by the end
of this lab, or by the start of the following lab):
1. Download the code found in the Lab 04 code folder on UBC Conne
Computer Science 221: Basic Algorithms and Data Structures
Sample Questions for Midterm 1
1. Using the denition of Big-Omega, prove that 22n4 100n3 + 17 is in (n4 ).
2. Using the denition of Big-O, prove or disprove (by showing a counter-example) that for
CPSC 221: Written Assignment 2
Last Updated: October 9, 2013
Due: Monday, October 29, 2012 at the beginning of class in class.
Late submissions are not accepted.
1. (5 points) Consider the following code for nding a maximum element in an array:
/ Find a m
CPSC 221: Written Assignment 3
Last Updated: November 14, 2013
Due: Monday, November 25, 2013 at the beginning of class in class.
Late submissions are not accepted.
1. Draw the Dictionary data structure obtained after inserting:
10, 20, 30, 40, 50, 60, 70
CPSC 221: Written Assignment 1
Last Updated: September 10, 2013
Due: Monday September 23, 2013 at the beginning of class in class.
Late submissions are not accepted.
1. (5 points) The following pseudo-code is intended to remove all occurrences of element
CS221: Algorithms and
Data Structures
Analyzing Runtime
Alan J. Hu
(Borrowing many slides from Steve Wolfman)
1
Types of analysis
Orthogonal axes
bound flavor
upper bound (O)
lower bound ()
asymptotically tight ()
analysis case
worst case (adversary)
CPSC 221:
Algorithms and Data Structures
Crash Course on Arrays
Alan J. Hu
1
Why Arrays?
Arrays are a very low-level data structure, that
basically matches the underlying memory.
Good: They are very efficient!
Bad: They have unpleasant limitations.
Fac
CS221: Algorithms and
Data Structures
Lecture #3
Mind StevePriority Queues
Your Wolfman
2013W2
1
Todays Outline
Trees, Briefly
Priority Queue ADT
Heaps
Implementing Priority Queue ADT
Focus on Create: Heapify
Brief introduction to d-Heaps
2
Trees
Family T
CPSC 221: Fall 2015
Lab 1
These must be completed and shown to your lab TA either by the end of this lab,
or by the start of your next lab. You may work in groups of up to two people.
This is an introduction to C+ through some simple activities. You shoul
CPSC 221: Fall 2015
Lab 2
These must be completed and shown to your lab TA either by the end of this lab,
or at the start of your next lab. You may work in groups of up to two people.
1. Please look at the brief introduction to C+ slides available on the
CPSC 221:
Algorithms and Data Structures
Lecture #0: Introduction
Alan J. Hu
(Borrowing some slides from Steve
Wolfman)
Webpage: http:/www.ugrad.cs.ubc.ca/~cs221
1
Rule #1: Ask questions!
Who I Am
Alan J. Hu (You can call me Alan or Prof. Hu.)
[email protected]
CS221: Algorithms and
Data Structures
Priority Queues and Heaps
Alan J. Hu
(Borrowing slides from Steve Wolfman)
1
Learning Goals
After this unit, you should be able to:
Provide examples of appropriate applications for
priority queues and heaps
Manipula
CS221: Algorithms and
Data Structures
Big-O
Alan J. Hu
(Borrowing some slides from Steve Wolfman)
1
Learning Goals
Define big-O, big-Omega, and big-Theta: O(), (), ()
Explain intuition behind their definitions.
Prove one function is big-O/Omega/Theta o
CPSC 221: Algorithms and
Data Structures
Lecture #6
Balancing Act
Steve Wolfman
2013W2
1
Todays Outline
Addressing one of our problems
Single and Double Rotations
AVL Tree Implementation
2
Beauty is Only (log n) Deep
Binary Search Trees are fast if theyre
CPSC 221: Data Structures
Lecture #5
Branching Out
Steve Wolfman
2013W2
1
Todays Outline
Binary Trees
Dictionary ADT
Binary Search Trees
Deletion
Some troubling questions
2
Binary Trees
Binary tree is either
empty (NULL for us), or
a datum, a left subtree
Come up and say hello!
1
CPSC 221:
Algorithms and Data Structures
Lecture #0: Introduction
Steve Wolfman
2013W2
2
Fibonacci
0
+
=
1, 1, 2, 3, 5, 8, 13, 21,
Applications, in order of importance:
Fun for CSists
Brief appearance in Da Vinci Code
Endlessly a
CPSC 221: Algorithms and
Data Structures
Lecture #7
Sweet, Sweet Tree is)
Hives
(B+-Trees, that
Steve Wolfman
2013W2
1
Todays Outline
Addressing our other problem
B+-tree properties
Implementing B+-tree insertion and deletion
Some final thoughts on B+-tre
CSE 221: Algorithms and
Data Structures
Lecture #8
The Constant Struggle for Hash
Steve Wolfman
(Unplugged-ish)
2013W2
1
Todays Outline
Constant-Time Dictionaries?
Getting to Hash Tables by Doing Everything Wrong
First Pass: Plain Vectors
Second Pass: A S
CS221: Algorithms and
Data Structures
Lecture #1
Complexity Theory and
Steve Wolfman
Asymptotic Analysis
2013W2
1
Todays Outline
Programming Project #1 and Forming Teams
Brief Proof Reminder
Asymptotic Analysis, Briefly
Silicon Downs and the SD Cheat Shee
CSE 221: Algorithms and
Data Structures
Lecture #9
Graphs (with no Axes to Grind)
Steve Wolfman
2011W2
1
Todays Outline
Topological Sort: Getting to Know Graphs with a Sort
Graph ADT and Graph Representations
Graph Terminology (a lot of it!)
More Graph Al
CPSC 221:
Algorithms and Data Structures
Lecture #0: Introduction
Alan J. Hu
(Borrowing some slides from Steve
Wolfman)
Webpage: http:/www.ugrad.cs.ubc.ca/~cs221
1
Rule #1: Ask questions!
Who I Am
Alan J. Hu (You can call me Alan or Prof. Hu.)
[email protected]
CS221: Algorithms and
Data Structures
Quick Review of Pointers
Alan J. Hu
(Borrowing some slides from Steve Wolfman)
1
Learning Goals
Get comfortable with C+ pointers, understand
the * and & operators.
Draw diagrams to help understand code that
manipula
CPSC 221:
Algorithms and Data Structures
ADTs, Stacks, and Queues
Alan J. Hu
(Slides borrowed from Steve Wolfman)
Be sure to check course webpage!
http:/www.ugrad.cs.ubc.ca/~cs221
1
Lab 1 is up!
Instructions for Lab 1 have been posted on course
webpage f
CPSC 221:
Algorithms and Data Structures
ADTs, Stacks, and Queues
Alan J. Hu
(Slides borrowed from Steve Wolfman)
Be sure to check course webpage!
http:/www.ugrad.cs.ubc.ca/~cs221
1
Lab 1 available very soon!
Instructions for Lab 1 will be posted on cour
CS221: Algorithms and
Data Structures
Asymptotic Analysis
Alan J. Hu
(Borrowing slides from Steve Wolfman)
1
Learning Goals
By the end of this unit, you will be able to
Define which program operations we measure in an
algorithm in order to approximate its
CPSC 221
Basic Algorithms and Data Structures
Priority Queues and Heaps
Textbook References:
Koffman: 8.5
Hassan Khosravi
January April 2015
CPSC 221
Priority Queues and Heaps
Page 1
Learning Goals
Provide examples of appropriate applications for
priorit
CPSC 221
Basic Algorithms and Data Structures
Balanced BST (AVL Trees)
Textbook References:
Koffman:11.1, 11.2
Hassan Khosravi
January April 2015
(Borrowing many slides from Alan Hu and Steve Wolfman)
CPSC 221
Balanced BST (AVL Trees)
Page 1
Learning goal
Department of Computer Science
Undergraduate Events
More details @ https:/my.cs.ubc.ca/students/development/events
EA Info Session
CS Speed Mentoring &
Townhall Event
Thurs., Jan 15
5:30 pm
Rm X860, ICICS/CS Bldg.
Mon.,
CPSC 221
Basic Algorithms and Data Structures
Binary Search Trees
Textbook References:
Koffman: 8.1 8.4
EPP 3rd edition:11.5
EPP 4th edition:10.5
Hassan Khosravi
January April 2015
Borrowing many slides from Steve Wolfman
CPSC 221
Binary Search Trees
Page
Unit Outline
Unit #1: Complexity Theory and Asymptotic
Analysis
I
Brief Proof Review
I
Algorithm Analysis: Counting the Number of Steps
I
Asymptotic Notation
Jan Manuch
I
Runtime Examples
2017S1: MayJune 2017
I
Problem Complexity
CPSC 221: Basic Algorithm
Addresses and Pointers
When implementing data structures in C+, we often need to consider
addresses and pointers.
You can think of addresses in memory in a way analogous to rooms in a
hotel, or houses in a city. Each room or house has a specific locatio
CPSC 221: Sample Final Exam Questions for Practice:
Solutions
Updated:
April 13, 2017 @ 01:20 Q5d: divide by 106+1 rather than 106 no change to final answer. Q1a: better
explanation.
April 12, 2017 @ 20:35 (divide by 2 in part of Question 3(b)s solution)