Trigonometry
Jun 23, 2015
Instant Trig
Trigonometry is math, so many people find it scary
Its usually taught in a one-semester high-school course
However, 95% of all the trig youll ever need to know
can be covered in 15 minutes
And thats what were going t

Spanning Trees
Spanning trees
Suppose you have a connected undirected graph
Connected: every node is reachable from every other node
Undirected: edges do not have an associated direction
.then a spanning tree of the graph is a connected
subgraph in which

Huffman Encoding
Jun 23, 2015
Entropy
Entropy is a measure of information content: the
number of bits actually required to store data.
Entropy is sometimes called a measure of surprise
A highly predictable sequence contains little actual
information
A com

Entropy
!
!
Huffman Encoding
Entropy is a measure of information content: the
number of bits actually required to store data.
Entropy is sometimes called a measure of surprise
!
A highly predictable sequence contains little actual
information
!
!
!
!
14-4

Shortest-path
!
!
Dijkstra s Algorithm
Suppose we want to find the shortest path from
node X to node Y
It turns out that, in order to do this, we need to find
the shortest path from X to all other nodes
!
!
!
Why?
If we don t know the shortest path from X

1. Topological sort
!
!
Some Graph Algorithms
!
Suppose a project involves doing a number of tasks, but
some of the tasks cannot be done until others are done
Your job is to find a legal order in which to do the tasks
For example, assume:
!
!
!
!
!
!
!
!

Some Graph Algorithms
1. Topological sort
Suppose a project involves doing a number of tasks, but
some of the tasks cannot be done until others are done
Your job is to find a legal order in which to do the tasks
For example, assume:
A must be done before

Dijkstras Algorithm
Shortest-path
Suppose we want to find the shortest path from
node X to node Y
It turns out that, in order to do this, we need to find
the shortest path from X to all other nodes
Why?
If we dont know the shortest path from X to Z, we mi

Effective Programming
Jun 23, 2015
Why test?
The new US stealth fighter, the F-22 Raptor, was deployed for
the first time to Asia earlier this month. On Feb. 11 [2007],
twelve Raptors flying from Hawaii to Japan were forced to turn
back when a software gl

Why test?
The new US stealth fighter, the F-22 Raptor, was deployed for
the first time to Asia earlier this month. On Feb. 11 [2007],
twelve Raptors flying from Hawaii to Japan were forced to turn
back when a software glitch crashed all of the F-22s onboa

Spanning trees
!
Suppose you have a connected undirected graph
!
!
Spanning Trees
!
Connected: every node is reachable from every other node
Undirected: edges do not have an associated direction
.then a spanning tree of the graph is a connected
subgraph i

Greedy Algorithms
1
A short list of categories
Algorithm types we will consider include:
Simple recursive algorithms
Backtracking algorithms
Divide and conquer algorithms
Dynamic programming algorithms
Greedy algorithms
Branch and bound algorithms
Brute f

A short list of categories
!
Algorithm types we will consider include:
!
!
Greedy Algorithms
!
!
!
!
!
!
Simple recursive algorithms
Backtracking algorithms
Divide and conquer algorithms
Dynamic programming algorithms
Greedy algorithms
Branch and bound al

Analysis of Algorithms II
Jun 23, 2015
Basics
Before we attempt to analyze an algorithm, we need to
define two things:
How we measure the size of the input
How we measure the time (or space) requirements
Once we have done this, we find an equation that
de

Recursive descent parsing
Jun 23, 2015
Abstract Syntax Trees (ASTs)
An AST is a way of representing a computer program
It is abstract because it throws away unnecessary information
(comments, whitespace, punctuation used only for
disambiguation, etc.)
It

Abstract Syntax Trees (ASTs)
!
An AST is a way of representing a computer program
!
Recursive descent parsing
!
It is abstract because it throws away unnecessary information
(comments, whitespace, punctuation used only for
disambiguation, etc.)
It represe

Quicksort I: Basic idea
!
!
!
Quicksort
!
!
Pick some number p from the array
Move all numbers less than p to the beginning of the array
Move all numbers greater than (or equal to) p to the end of the
array
Quicksort the numbers less than p
Quicksort the

Why study Heapsort?
!
!
Heapsort
It is a well-known, traditional sorting algorithm
you will be expected to know
Heapsort is always O(n log n)
Quicksort is usually O(n log n) but in the worst case
slows to O(n2)
! Quicksort is generally faster, but Heapsor

Quicksort
Quicksort I: Basic idea
Pick some number p from the array
Move all numbers less than p to the beginning of the array
Move all numbers greater than (or equal to) p to the end of the
array
Quicksort the numbers less than p
Quicksort the numbers gr

Priority queue
!
!
!
Priority Queues
A stack is first in, last out
A queue is first in, first out
A priority queue is least-first-out
!
The
!
!
!
smallest
element is the first one removed
(You could also define a largest-first-out priority queue)
The defi

Priority Queues
Priority queue
A stack is first in, last out
A queue is first in, first out
A priority queue is least-first-out
The smallest element is the first one removed
(You could also define a largest-first-out priority queue)
The definition of smal

Heapsort
Why study Heapsort?
It is a well-known, traditional sorting algorithm
you will be expected to know
Heapsort is always O(nlogn)
Quicksort is usually O(nlogn) but in the worst case
slows to O(n2)
Quicksort is generally faster, but Heapsort is bette

Algorithm classification
!
!
Types of Algorithms
!
!
Algorithms that use a similar problem-solving approach
can be grouped together
We ll talk about a classification scheme for algorithms
This classification scheme is neither exhaustive nor
disjoint
The p

Types of Algorithms
Algorithm classification
Algorithms that use a similar problem-solving approach
can be grouped together
Well talk about a classification scheme for algorithms
This classification scheme is neither exhaustive nor
disjoint
The purpose is

State spaces
!
A state space consists of
!
State-Space Searches
A (possibly infinite) set of states
! The start state represents the initial problem
!
!
!
Each state represents some configuration reachable from the start state
Some states may be goal stat

Two-player games
!
!
Alpha-Beta Search
!
!
!
The object of a search is to find a path from the starting
position to a goal position
In a puzzle-type problem, you (the searcher) get to
choose every move
In a two-player competitive game, you alternate moves

A short list of categories
!
Algorithm types we will consider include:
!
!
Randomized Algorithms
!
!
!
!
!
!
Simple recursive algorithms
Backtracking algorithms
Divide and conquer algorithms
Dynamic programming algorithms
Greedy algorithms
Branch and boun