CS109A Notes for Lecture 1/24/96
Proving Recursive Programs Work
When a program is recursive, we can often
nd a natural inductive proof that it works.
The induction is often on the number of
recursiv
CS109A Notes for Lecture 3/4/96
Priority Queues
1. Model = set with priorities associated with
elements.
Priorities are comparable by a < operator, e.g., priorities could be real numbers.
2. Operation
CS109A Notes for Lecture 2/7/96
Analysis of Mergesort
Input size n = length of list to be sorted; Tms(n)
= running time of mergesort.
1. Call split on list of length n; takes O(n) time
(in book).
2. T
CS109A Notes for Lecture 1/19/96
Recursive Denition of Expressions
Expressions with binary operators can be dened
as follows.
Basis: An operand is an expression.
An operand is a variable or constant.
CS109A Notes for Lecture 1/17/96
Simple Inductions
Three pieces:
1. A statement ( ) to be proved.
The statement must be about an integer
parameter .
2. A basis for the proof. This is the statement
( )
CS109A Notes for Lecture 2/12/96
Assignments With Replacements
We are given n \items," to each of which we
must assign one of k \values."
Each value may be used any number of
times from 0 up.
Let W (
CS109A Notes for Lecture 2/23/96
Probability Space
Set of points, each with an attached probability
(nonnegative, real number), such that the sum of
the probabilities is 1.
We simplify in two ways:
a
CS109A Notes for Lecture 1/10/96
Major Theme: Data Models
Data model = A way of representing (some
kinds of) information in a computer.
Static part : represents the information.
Dynamic part : operat
CS109A Notes for Lecture 2/28/96
Binary Trees
Every binary tree has two \slots" for children; it
may have none, either one, or both.
Empty (0-node) binary tree is possible.
Equivalently, a node has
CS109A Notes for Lecture 1/31/96
Measuring the Running Time of Programs
Fix a measure of the \size" n of the data to which
a program is being applied.
Example: For integer arguments, the value is
ofte
CS109A Notes for Lecture 2/26/96
Rooted Trees
Collection of nodes, one of which is the root.
Nodes 6= root have unique parent node.
Each nonroot can reach the root by following
parent links one or m
CS109A Notes for Lecture 1/12/96
The Essence of Proof
Mathematical proof is essentially persuasive prose.
Like an essay, it is eective if it convinces the
listener.
Also like an essay, we can learn
CS109A Notes for Lecture 2/5/96
Programs with Function Calls
Establish a size measure for each function.
Let f ( ) be the running time of function .
When evaluating a simple or compound staten
T
n
CS109A Notes for Lecture 2/14cfw_16/96
Orders With Some Equivalent Items
Suppose we have a Scrabble rank of 7 tiles, which
are STAAEEE . How many dierent 7-letter
words could we make?
As before, we're
CS109A Notes for Lecture 1/26/96
Running Time
A program or algorithm has a running time ( ),
where is the measure of the size of the input.
( ) is the largest amount of time the program takes on any