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
recursive calls that must be made by a
given call to the recurs
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. Operations:
a) Insert an element with a given priority.
b) Delet
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. Then, mergesort calls itself on two lists of size
n=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.
Induction:
1. If 1 and 2 are expressions, and is a bin
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
( ) for some integer . Often = 0 or = 1.
3. An inductive s
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 (n; k) be the number of ways.
How many dierent ways may
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) Number of points is nite, .
b) Probability of each po
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 : operations on the information.
Section 1.3 discusses example
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 left and right subtrees. Either or both may be null.
Da
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
often a good size measure. For strings: the length.
Comput
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 more times.
Important Denitions
If node p is the parent
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 certain rhetorical tricks, e.g. \proof by induction" or
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
f
ment, include the running times of any function calls
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 not concerned with
whether the word is \legal."
Simil
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 input of size .
Example: For a sorting algorithm, we no