Algorithms
R OBERT S EDGEWICK  K EVIN W AYNE
K RUSKAL ' S A LGORITHM 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
Kruskal's algorithm dem
Algorithms
R OBERT S EDGEWICK  K EVIN W AYNE
P RIM ' S A LGORITHM D EMO
Prim's algorithm
lazy implementation
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.p
Text Compression
Given a string X, efficiently encode X into a
smaller string Y
Saves memory and/or bandwidth
A good approach: Huffman encoding
Compute frequency f(c) for each character c.
Encode high
Prims/Jarniks Algorithm
Idea: Pick an arbitrary vertex and grow the minimum spanning tree
from there.
At each step, pick the vertex outside the spanning tree with the
minimum edge connecting it to t
Recitation 2 Recurrences
Parallel and Sequential Data Structures and Algorithms, 15210 (Fall 2013)
September 4, 2013
1
Announcements
HW1 is due on Monday, September 9. Hopefully you have all started
CS 234
Data Types and Structures
Spring 2015
Instructors:
Martin Derka, Safaa Bedawi
Slides based on notes and slides from L. Case, J.P. Pretti,
K. Lanctot with additions by M. Derka and S. Bedawi.
Ma
Growthrate Functions
O(1) constant time, the time is independent of n,
e.g. array lookup
O(log n) logarithmic time, usually the log is base
2, e.g. binary search
O(n) linear time, e.g. linear search
Splay Trees
6
v
8
3
z
4
2013 Goodrich, Tamassia, Goldwasser
Splay Trees
1
Splay Trees are Binary Search Trees
all the keys in the blue
region are 20
(20,Z)
note that two keys of
equal value may be we
Graphs
What do the following problems have in common?
Traveling Salesman Problem: Given a list of cities and
the distances between them, find the shortest tour that
visits all cities and returns to th
Spanning Trees
Subgraph of a graph G = (V,E) is any graph that can be obtained by
removing edges and/or vertices from G
Spanning subgraph of G is a connected subgraph of G which contains
all vertice
Wrapping Things Up
What Weve Learned about Programming
Languages
What Weve Learned about Data Structure
What Weve Learned about
Programming Languages
Object based programming: Organize
around objec
Shortest Paths
A
8
B
8
2
2013 Goodrich, Tamassia, Goldwasser
Shortest Paths
2
7
5
E
C
3
0
2
4
1
9
D
8
F
3
5
1
Weighted Graphs
In a weighted graph, each edge has an associated numerical
value, called
Spanning Trees
Subgraph of a graph G = (V,E) is any graph that can be obtained by
removing edges and/or vertices from G
Spanning subgraph of G is a connected subgraph of G which contains
all vertice
Graphs
What do the following problems have in common?
Traveling Salesman Problem: Given a list of cities and
the distances between them, find the shortest tour that
visits all cities and returns to th
Algorithms
R OBERT S EDGEWICK  K EVIN W AYNE
D IJKSTRA ' S A LGORITHM 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
Dijkstra's algorithm d
Lecture 2 Notes
CS234
What is the cost of an algorithm?

Test it out, see how it performs.
Different hardware you get different performance
Depends on the language C will be faster than python
My be
CS 234 Style Guide
1
Introduction
This document specifies the style required for Python programs written for the
course. It assumes familiarity with the design recipe, as discussed in detail in CS
115
CS 234
Naomi Nishimura
Python review
The sections below indicate Python material, the degree to which it will be used in the
course, and various resources you can use to review the material. You are n
CS 234
Module 7
November 3, 2016
CS 234 Module 7
Digital data and average case analysis
1 / 22
Terminology
A hash table consists of a bucket array (where the number of buckets is
the capacity) and a h
CS 234
Module 5
October 18, 2016
CS 234 Module 5
ADTS with items related by structure
1 / 15
Case study
Problem: When colour is applied to a part of a web page, what other parts
of the page will obtai
CS 234
Module 6
October 25, 2016
CS 234 Module 6
ADT Dictionary
1 / 22
Case study
Problem: Find a way to store student records for a course, with unique IDs
for each student, where records can be acce
CS 234
Module 9
November 17, 2016
CS 234 Module 9
ADT Graph
1/8
Case study
Problems:
Given flight information for all the airlines you trust, determine
whether it is possible to fly from point A to p
Supplementary Slides
for Module 9
2D Arrays/Matrices
(Figure from textbook: Rance Necaise, Data
Structures and Algorithms using Python)
2D Arrays/Matrices
array of arrays
linear array
(Figure from
Instructions
Answer all questions on this booklet.
You have 1 hour and 50 minutes to
complete this exam.
This exam has 25 marks.
No aids (textbooks, calculators, etc)
are allowed.
All solutions must b
CS234 MIDTERM REVIEW SPRING 2016
Professor: Saeed Mehrabi
_DEFINITIONS_
separating properties of an object (Software down to Hardware implementation)
programmer defined DT specified by a domain set of
CS 234  Notes
Lecture 1: CS 234
Abstraction:
Hardware Machine language High level Languages Libraries User
ADT: Example Card game: ADT (Deck)
Data hiding The cards in the deck
Module 4:
if you were i
Supplemental Slides for
Module 2
(Including material from Section 4.1)
Counting arithmetic operations
Number of operations depends on input size
(Figure from textbook: Rance Necaise, Data Structures
CS 234 Assignment 4
Name: Zhaoen Liu
Student ID: 20618246
W1.
FindMinInMaxHeap(heap):
Index = HeapArray[array.size /2]
If index = 0:
Return HeapArray[index]
Else:
temp = HeapArray[index+1]
for item in