Inductive Proof - Computational Concepts in Biological Sciences - Lecture Note, Lecture notes of Computer Science

Main points of this lecture are: Inductive Proof, Inductive Hypothesis, Complexity, Linear Search, Binary Search, Hash Search, Space Complexity, Time Complexity, Trading Space and Time, Value of Preparation, Measuring Time, Concepts of Time and Space

Typology: Lecture notes

2012/2013

Uploaded on 04/23/2013

ashwini
ashwini 🇮🇳

4.5

(18)

167 documents

1 / 28

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Complete the following inductive proof:
Theorem: any set S of natural numbers has a largest
element.
Basis case: n=________13________. Then S = {x} and x
x. Thus x is the largest element of {x}=S.
If y>x, then y is the largest element of S.
If x>y, then x is the largest element of S.
Inductive step: Assume true for n. Choose S with |S|=n+1.
Choose x
S. Let T=S ________14________ {x}. Then
|T|=________15________ so the inductive hypothesis
applies and ________16________ has a largest element y.
Then there are two cases,
Thus in either case, there is a largest element of S. and the
inductive hypothesis is true with |S|=n+1.
Thus the whole theorem is true by induction.
Pasted from <http://www.cs. tufts.edu/comp/14/exams/q01.html>
Quiz 1 quandary
12:52 PM
Complexity Page 1
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download Inductive Proof - Computational Concepts in Biological Sciences - Lecture Note and more Lecture notes Computer Science in PDF only on Docsity!

Complete the following inductive proof:

Theorem: any set S of natural numbers has a largest

element.

Basis case: n=________ 13 ________. Then S = {x} and x

≤ x. Thus x is the largest element of {x}=S.

• If y>x, then y is the largest element of S.

• If x>y, then x is the largest element of S.

Inductive step: Assume true for n. Choose S with |S|=n+1.

Choose x

S. Let T=S ________ 14 ________ {x}. Then

|T|=________ 15 ________ so the inductive hypothesis

applies and ________ 16 ________ has a largest element y.

Then there are two cases,

Thus in either case, there is a largest element of S. and the

inductive hypothesis is true with |S|=n+1.

Thus the whole theorem is true by induction.

Pasted from

Quiz 1 quandary

Monday, October 04, 2010 12:52 PM Docsity.com

We have developed a precise language for discussing

computation

We have developed some skill in a powerful

computer language.

So far,

It is time to do some real computer science.

It is time to engage in the grand dance of time, space,

and complexity.

Now,

Complexity

Saturday, October 02, 2010 5:40 PM Docsity.com

or die "can't read the dictionary: $!"; open(DICT, ") { chomp; push(@words, $_); } print "Enter words to look up: "; while () { chomp; my @line = split(/\s+/,$_); foreach my $word (@line) { my $found = &FALSE; for (my $i=0; $i<@words; $i++) { if ($words[$i] eq $word) { $found = &TRUE; last; } } if ($found) { print "'$word' is in the dictionary\n"; } else { print "'$word' is not in the dictionary\n"; } } print "Enter words to look up: "; } Pasted from

Linear search

Saturday, October 02, 2010 5:48 PM Docsity.com

or die "can't read the dictionary: $!"; open(DICT, ") { chomp; push(@words, $_); } @words = sort (@words); print "Enter words to look up: "; while () { chomp; my @line = split(/\s+/,$_); foreach my $word (@line) { my $found = &FALSE; my $low = 0; my $high = @words-1; while ($high-$low>1) { my $mid = ($high + $low)/2; if ($word gt $words[$mid]) { $low=$mid; # rule out #$words[$low]-$words[$mid-1] } elsif ($word lt $words[$mid]) { $high=$mid; # rule out #words[$mid+1]-$words[$high] } else { # found it: end $found=&TRUE; last; } } if ($found) { print "'$word' is in the dictionary\n"; } else { print "'$word' is not in the dictionary\n"; } } print "Enter words to look up: "; } Pasted from

Binary search

Saturday, October 02, 2010 6:28 PM Docsity.com

Not a trivial question.

Time to do things (time complexity)

Space to store things (space complexity)

Each approach requires

How can we measure these?

Which one is better?

Which one of these should we utilize?

Which broomstick?

Saturday, October 02, 2010 6:35 PM Docsity.com

Hashing is optimally fast, but takes more space (for

complex reasons). This is an example of trading space

for time.

Storing something in an array is space-efficient, but

takes a lot more time. This is an example of trading

time for space.

Sorting an array takes time, but then, searching is

faster. This is an example of the value of preparation.

There is more preparation than search time.

These involve space/time tradeoffs:

Trading space and time

Saturday, October 02, 2010 6:37 PM Docsity.com

read my own memory usage from the proc table

It is a line of the form "VmSize: size" in status

sub readmemory { open(PROC, ") { chomp; my ($key, $value)=split(/[\s:]+/); close PROC; if ($key eq 'VmSize') { return $value } } return undef; } $mem1 = &readmemory; for ($i=0; $i<100000; $i++) { $a[$i]=$i; } $mem2 = &readmemory; $diff = $mem2 - $mem1; print "mem1=$mem1 mem2=$mem2 diff=$diff kbytes\n"; See and run http://www.cs.tufts.edu/comp/14/examples/Complexity/space.perl Caution : not subtracting $mem1 would count the size of perl itself!

Measuring space used

Sunday, October 03, 2010 2:49 PM Docsity.com

Worst-case time (or space) : an upper bound on how

much time (or space) is taken to compute something.

How slow can it be?

Best-case time : a lower bound. How fast can it run?

Average-case time : on average, how long (or how much

memory) does it take? Depends upon input!

Concepts of time and space

Sunday, October 03, 2010 2:58 PM Docsity.com

How can we characterize the time spent in a

program?

How can we distinguish between different

approaches to solving the same problem?

Concentrate on worst-case behavior.

For today, our goal is to concentrate upon time.

For today

Sunday, October 03, 2010 3:06 PM Docsity.com

We define some concept of a "program step". Then we "count the steps". How long does a program take? If we define a step as a program statement, then for ($i=0; $i<100; $i++) { $sum+=$i; } takes 302 steps. Example: for ($i=0; $i<100; $i++) { $sum += $i; } Reasoning: is equivalent with $i=0; # 1 step while ($i<100) { # 1 step, TRUE 100 times, then FALSE $sum+=$i; # 1 step $i++; # 1 step } So the total is 1+(1+1+1)*100 +1 =302 total steps.

"Steps"

Saturday, October 02, 2010 7:05 PM Docsity.com

The concept of a step can differ greatly depending

upon who defines it.

Our general strategy: arrange things so the definition

of the size of a step does not matter.

This is painful!

Concentrate on the relationship between size of

input and computation time.

Discuss bounds rather than actual times.

Two parts to our strategy:

Wow, this is confusing

Saturday, October 02, 2010 7:11 PM Docsity.com

We start by defining some size of input, e.g., n things.

We don't care what units one uses as long as they're

consistent: bytes, records, etc.

Size of input

Saturday, October 02, 2010 7:12 PM Docsity.com

Let n be some measure of input size. C is a multiplicative constant that represents a change in units N is a boundary condition that determines how large n has to be for the change in units to work. We say that a program takes O(n) time (or space) if there are constants C and N such that if n>N, the time (or space) required < Cn.

Order notation

Saturday, October 02, 2010 7:14 PM Docsity.com

A picture of linear time

Sunday, October 03, 2010 4:14 PM Docsity.com