49
Counting Ngày 16 tháng 11 năm 2012 () Counting Ngày 16 tháng 11 năm 2012 1/1

Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

Counting

Ngày 16 tháng 11 năm 2012

() Counting Ngày 16 tháng 11 năm 2012 1 / 1

Page 2: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

QuestionWhat do we count?

QuestionWhy do we count?

QuestionHow do we count?

To answer these questions we shall start practicing counting usingcommon sense.A list of counting problems can be found in the file Let Us Count.pdf.

() Counting Ngày 16 tháng 11 năm 2012 1 / 1

Page 3: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

QuestionWhat do we count?

QuestionWhy do we count?

QuestionHow do we count?

To answer these questions we shall start practicing counting usingcommon sense.A list of counting problems can be found in the file Let Us Count.pdf.

() Counting Ngày 16 tháng 11 năm 2012 1 / 1

Page 4: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

QuestionWhat do we count?

QuestionWhy do we count?

QuestionHow do we count?

To answer these questions we shall start practicing counting usingcommon sense.A list of counting problems can be found in the file Let Us Count.pdf.

() Counting Ngày 16 tháng 11 năm 2012 1 / 1

Page 5: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

QuestionWhat do we count?

QuestionWhy do we count?

QuestionHow do we count?

To answer these questions we shall start practicing counting usingcommon sense.A list of counting problems can be found in the file Let Us Count.pdf.

() Counting Ngày 16 tháng 11 năm 2012 1 / 1

Page 6: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

QuestionWhat do we count?

QuestionWhy do we count?

QuestionHow do we count?

To answer these questions we shall start practicing counting usingcommon sense.A list of counting problems can be found in the file Let Us Count.pdf.

() Counting Ngày 16 tháng 11 năm 2012 1 / 1

Page 7: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

QuestionWhat do we count?

QuestionWhy do we count?

QuestionHow do we count?

To answer these questions we shall start practicing counting usingcommon sense.A list of counting problems can be found in the file Let Us Count.pdf.

() Counting Ngày 16 tháng 11 năm 2012 1 / 1

Page 8: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

QuestionWhat do we count?

QuestionWhy do we count?

QuestionHow do we count?

To answer these questions we shall start practicing counting usingcommon sense.

A list of counting problems can be found in the file Let Us Count.pdf.

() Counting Ngày 16 tháng 11 năm 2012 1 / 1

Page 9: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

QuestionWhat do we count?

QuestionWhy do we count?

QuestionHow do we count?

To answer these questions we shall start practicing counting usingcommon sense.A list of counting problems can be found in the file Let Us Count.pdf.

() Counting Ngày 16 tháng 11 năm 2012 1 / 1

Page 10: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

Làm thế nào nhiều trứng được vận chuyển trên các xe gắn máy trongảnh?

() Counting Ngày 16 tháng 11 năm 2012 2 / 1

Page 11: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

How many students are attending this class?

() Counting Ngày 16 tháng 11 năm 2012 3 / 1

Page 12: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

How many green disks are in this picture?

() Counting Ngày 16 tháng 11 năm 2012 4 / 1

Page 13: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

Can you count now?

() Counting Ngày 16 tháng 11 năm 2012 5 / 1

Page 14: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

And how about now?

() Counting Ngày 16 tháng 11 năm 2012 6 / 1

Page 15: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

1 Counting, especially of a large collection ofobjects, can be hard.

2 If a collection can be “organized” (physically orconceptually, for example the “green” rectangulararray) it can help us count the number of objectsin the collection.

3 If the collection can be partitioned into “smaller”collections, in particular if every smaller collectionhas the same number of objects, it may again helpus count.

() Counting Ngày 16 tháng 11 năm 2012 7 / 1

Page 16: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

1 Counting, especially of a large collection ofobjects, can be hard.

2 If a collection can be “organized” (physically orconceptually, for example the “green” rectangulararray) it can help us count the number of objectsin the collection.

3 If the collection can be partitioned into “smaller”collections, in particular if every smaller collectionhas the same number of objects, it may again helpus count.

() Counting Ngày 16 tháng 11 năm 2012 7 / 1

Page 17: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

1 Counting, especially of a large collection ofobjects, can be hard.

2 If a collection can be “organized” (physically orconceptually, for example the “green” rectangulararray) it can help us count the number of objectsin the collection.

3 If the collection can be partitioned into “smaller”collections, in particular if every smaller collectionhas the same number of objects, it may again helpus count.

() Counting Ngày 16 tháng 11 năm 2012 7 / 1

Page 18: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

Why count?

You are a mathematician. Your friend, a programmer asks you:

QuestionI have an array with 10,000,000 integers. The weight of a segment(ai ,ai+1 . . . ,aj) is :

∑ji=0 ai .

I need to find the largest segment in the array.

This problem looks very simple to answer:

1 Generate all segments.2 Calculate the weight of each segment.3 Compare with the current largest weight, replace if the current

weight is bigger.4 Return the largest weight.

() Counting Ngày 16 tháng 11 năm 2012 8 / 1

Page 19: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

Why count?

You are a mathematician. Your friend, a programmer asks you:

QuestionI have an array with 10,000,000 integers. The weight of a segment(ai ,ai+1 . . . ,aj) is :

∑ji=0 ai .

I need to find the largest segment in the array.

This problem looks very simple to answer:

1 Generate all segments.2 Calculate the weight of each segment.3 Compare with the current largest weight, replace if the current

weight is bigger.4 Return the largest weight.

() Counting Ngày 16 tháng 11 năm 2012 8 / 1

Page 20: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

Why count?

You are a mathematician. Your friend, a programmer asks you:

QuestionI have an array with 10,000,000 integers. The weight of a segment(ai ,ai+1 . . . ,aj) is :

∑ji=0 ai .

I need to find the largest segment in the array.

This problem looks very simple to answer:

1 Generate all segments.2 Calculate the weight of each segment.3 Compare with the current largest weight, replace if the current

weight is bigger.4 Return the largest weight.

() Counting Ngày 16 tháng 11 năm 2012 8 / 1

Page 21: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

Why count?

You are a mathematician. Your friend, a programmer asks you:

QuestionI have an array with 10,000,000 integers. The weight of a segment(ai ,ai+1 . . . ,aj) is :

∑ji=0 ai .

I need to find the largest segment in the array.

This problem looks very simple to answer:

1 Generate all segments.2 Calculate the weight of each segment.3 Compare with the current largest weight, replace if the current

weight is bigger.4 Return the largest weight.

() Counting Ngày 16 tháng 11 năm 2012 8 / 1

Page 22: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

Why count?

You are a mathematician. Your friend, a programmer asks you:

QuestionI have an array with 10,000,000 integers. The weight of a segment(ai ,ai+1 . . . ,aj) is :

∑ji=0 ai .

I need to find the largest segment in the array.

This problem looks very simple to answer:

1 Generate all segments.2 Calculate the weight of each segment.3 Compare with the current largest weight, replace if the current

weight is bigger.4 Return the largest weight.

() Counting Ngày 16 tháng 11 năm 2012 8 / 1

Page 23: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

Why count?

You are a mathematician. Your friend, a programmer asks you:

QuestionI have an array with 10,000,000 integers. The weight of a segment(ai ,ai+1 . . . ,aj) is :

∑ji=0 ai .

I need to find the largest segment in the array.

This problem looks very simple to answer:1 Generate all segments.

2 Calculate the weight of each segment.3 Compare with the current largest weight, replace if the current

weight is bigger.4 Return the largest weight.

() Counting Ngày 16 tháng 11 năm 2012 8 / 1

Page 24: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

Why count?

You are a mathematician. Your friend, a programmer asks you:

QuestionI have an array with 10,000,000 integers. The weight of a segment(ai ,ai+1 . . . ,aj) is :

∑ji=0 ai .

I need to find the largest segment in the array.

This problem looks very simple to answer:1 Generate all segments.2 Calculate the weight of each segment.

3 Compare with the current largest weight, replace if the currentweight is bigger.

4 Return the largest weight.

() Counting Ngày 16 tháng 11 năm 2012 8 / 1

Page 25: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

Why count?

You are a mathematician. Your friend, a programmer asks you:

QuestionI have an array with 10,000,000 integers. The weight of a segment(ai ,ai+1 . . . ,aj) is :

∑ji=0 ai .

I need to find the largest segment in the array.

This problem looks very simple to answer:1 Generate all segments.2 Calculate the weight of each segment.3 Compare with the current largest weight, replace if the current

weight is bigger.

4 Return the largest weight.

() Counting Ngày 16 tháng 11 năm 2012 8 / 1

Page 26: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

Why count?

You are a mathematician. Your friend, a programmer asks you:

QuestionI have an array with 10,000,000 integers. The weight of a segment(ai ,ai+1 . . . ,aj) is :

∑ji=0 ai .

I need to find the largest segment in the array.

This problem looks very simple to answer:1 Generate all segments.2 Calculate the weight of each segment.3 Compare with the current largest weight, replace if the current

weight is bigger.4 Return the largest weight.

() Counting Ngày 16 tháng 11 năm 2012 8 / 1

Page 27: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

You get a phone call in the middle of the night. Your friend is on theline. He is panicked.

I implemented your solution and ran it. It started 30 hours ago and thecomputer is still running! What is wrong?

Hmmm, you decide to analyze your solution: count how manyadditions the computer is executing.

1 You have n − 1 subarrays of length 2(a1,a2), (a2,a3), . . . , (an−1,an) each requires one addition.

2 You have n − 2 subarrays of length 3(a1,a2,a3), (a2,a3,a4), . . . , (an−2,an−1,an) each requires 2additions.

3 In general, you have n − j subarrays of length j + 1 each requires jadditions.

4 So the total number of additions required by this solution is:5

∑n−1i=1 j × (n − j)

6 Calculate:∑n−1

i=1 j × (n − j) = 16(n

3 − n)

() Counting Ngày 16 tháng 11 năm 2012 9 / 1

Page 28: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

You get a phone call in the middle of the night. Your friend is on theline. He is panicked.

I implemented your solution and ran it. It started 30 hours ago and thecomputer is still running! What is wrong?

Hmmm, you decide to analyze your solution: count how manyadditions the computer is executing.

1 You have n − 1 subarrays of length 2(a1,a2), (a2,a3), . . . , (an−1,an) each requires one addition.

2 You have n − 2 subarrays of length 3(a1,a2,a3), (a2,a3,a4), . . . , (an−2,an−1,an) each requires 2additions.

3 In general, you have n − j subarrays of length j + 1 each requires jadditions.

4 So the total number of additions required by this solution is:5

∑n−1i=1 j × (n − j)

6 Calculate:∑n−1

i=1 j × (n − j) = 16(n

3 − n)

() Counting Ngày 16 tháng 11 năm 2012 9 / 1

Page 29: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

You get a phone call in the middle of the night. Your friend is on theline. He is panicked.

I implemented your solution and ran it. It started 30 hours ago and thecomputer is still running! What is wrong?

Hmmm, you decide to analyze your solution: count how manyadditions the computer is executing.

1 You have n − 1 subarrays of length 2(a1,a2), (a2,a3), . . . , (an−1,an) each requires one addition.

2 You have n − 2 subarrays of length 3(a1,a2,a3), (a2,a3,a4), . . . , (an−2,an−1,an) each requires 2additions.

3 In general, you have n − j subarrays of length j + 1 each requires jadditions.

4 So the total number of additions required by this solution is:5

∑n−1i=1 j × (n − j)

6 Calculate:∑n−1

i=1 j × (n − j) = 16(n

3 − n)

() Counting Ngày 16 tháng 11 năm 2012 9 / 1

Page 30: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

You get a phone call in the middle of the night. Your friend is on theline. He is panicked.

I implemented your solution and ran it. It started 30 hours ago and thecomputer is still running! What is wrong?

Hmmm, you decide to analyze your solution: count how manyadditions the computer is executing.

1 You have n − 1 subarrays of length 2(a1,a2), (a2,a3), . . . , (an−1,an) each requires one addition.

2 You have n − 2 subarrays of length 3(a1,a2,a3), (a2,a3,a4), . . . , (an−2,an−1,an) each requires 2additions.

3 In general, you have n − j subarrays of length j + 1 each requires jadditions.

4 So the total number of additions required by this solution is:5

∑n−1i=1 j × (n − j)

6 Calculate:∑n−1

i=1 j × (n − j) = 16(n

3 − n)

() Counting Ngày 16 tháng 11 năm 2012 9 / 1

Page 31: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

You get a phone call in the middle of the night. Your friend is on theline. He is panicked.

I implemented your solution and ran it. It started 30 hours ago and thecomputer is still running! What is wrong?

Hmmm, you decide to analyze your solution: count how manyadditions the computer is executing.

1 You have n − 1 subarrays of length 2(a1,a2), (a2,a3), . . . , (an−1,an) each requires one addition.

2 You have n − 2 subarrays of length 3(a1,a2,a3), (a2,a3,a4), . . . , (an−2,an−1,an) each requires 2additions.

3 In general, you have n − j subarrays of length j + 1 each requires jadditions.

4 So the total number of additions required by this solution is:5

∑n−1i=1 j × (n − j)

6 Calculate:∑n−1

i=1 j × (n − j) = 16(n

3 − n)

() Counting Ngày 16 tháng 11 năm 2012 9 / 1

Page 32: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

You get a phone call in the middle of the night. Your friend is on theline. He is panicked.

I implemented your solution and ran it. It started 30 hours ago and thecomputer is still running! What is wrong?

Hmmm, you decide to analyze your solution: count how manyadditions the computer is executing.

1 You have n − 1 subarrays of length 2(a1,a2), (a2,a3), . . . , (an−1,an) each requires one addition.

2 You have n − 2 subarrays of length 3(a1,a2,a3), (a2,a3,a4), . . . , (an−2,an−1,an) each requires 2additions.

3 In general, you have n − j subarrays of length j + 1 each requires jadditions.

4 So the total number of additions required by this solution is:5

∑n−1i=1 j × (n − j)

6 Calculate:∑n−1

i=1 j × (n − j) = 16(n

3 − n)

() Counting Ngày 16 tháng 11 năm 2012 9 / 1

Page 33: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

You get a phone call in the middle of the night. Your friend is on theline. He is panicked.

I implemented your solution and ran it. It started 30 hours ago and thecomputer is still running! What is wrong?

Hmmm, you decide to analyze your solution: count how manyadditions the computer is executing.

1 You have n − 1 subarrays of length 2(a1,a2), (a2,a3), . . . , (an−1,an) each requires one addition.

2 You have n − 2 subarrays of length 3(a1,a2,a3), (a2,a3,a4), . . . , (an−2,an−1,an) each requires 2additions.

3 In general, you have n − j subarrays of length j + 1 each requires jadditions.

4 So the total number of additions required by this solution is:

5∑n−1

i=1 j × (n − j)6 Calculate:

∑n−1i=1 j × (n − j) = 1

6(n3 − n)

() Counting Ngày 16 tháng 11 năm 2012 9 / 1

Page 34: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

You get a phone call in the middle of the night. Your friend is on theline. He is panicked.

I implemented your solution and ran it. It started 30 hours ago and thecomputer is still running! What is wrong?

Hmmm, you decide to analyze your solution: count how manyadditions the computer is executing.

1 You have n − 1 subarrays of length 2(a1,a2), (a2,a3), . . . , (an−1,an) each requires one addition.

2 You have n − 2 subarrays of length 3(a1,a2,a3), (a2,a3,a4), . . . , (an−2,an−1,an) each requires 2additions.

3 In general, you have n − j subarrays of length j + 1 each requires jadditions.

4 So the total number of additions required by this solution is:5

∑n−1i=1 j × (n − j)

6 Calculate:∑n−1

i=1 j × (n − j) = 16(n

3 − n)

() Counting Ngày 16 tháng 11 năm 2012 9 / 1

Page 35: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

You get a phone call in the middle of the night. Your friend is on theline. He is panicked.

I implemented your solution and ran it. It started 30 hours ago and thecomputer is still running! What is wrong?

Hmmm, you decide to analyze your solution: count how manyadditions the computer is executing.

1 You have n − 1 subarrays of length 2(a1,a2), (a2,a3), . . . , (an−1,an) each requires one addition.

2 You have n − 2 subarrays of length 3(a1,a2,a3), (a2,a3,a4), . . . , (an−2,an−1,an) each requires 2additions.

3 In general, you have n − j subarrays of length j + 1 each requires jadditions.

4 So the total number of additions required by this solution is:5

∑n−1i=1 j × (n − j)

6 Calculate:∑n−1

i=1 j × (n − j) = 16(n

3 − n)() Counting Ngày 16 tháng 11 năm 2012 9 / 1

Page 36: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

Your friend tells you that his computer can execute 10,000,000,000(1010) additions per second.

The array has 10,000,000 (107) integers.

So we need to execute 16(1021 − 107) > 1020 additions.

So the computer will need more than 1010 seconds.

Question

How long is 1010 seconds?

There are 86400 seconds per day. So your friend’s computer will runabout: 1010

864000 seconds. Which is:

MORE THAN 27 YEARS!

() Counting Ngày 16 tháng 11 năm 2012 10 / 1

Page 37: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

Your friend tells you that his computer can execute 10,000,000,000(1010) additions per second.

The array has 10,000,000 (107) integers.

So we need to execute 16(1021 − 107) > 1020 additions.

So the computer will need more than 1010 seconds.

Question

How long is 1010 seconds?

There are 86400 seconds per day. So your friend’s computer will runabout: 1010

864000 seconds. Which is:

MORE THAN 27 YEARS!

() Counting Ngày 16 tháng 11 năm 2012 10 / 1

Page 38: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

Your friend tells you that his computer can execute 10,000,000,000(1010) additions per second.

The array has 10,000,000 (107) integers.

So we need to execute 16(1021 − 107) > 1020 additions.

So the computer will need more than 1010 seconds.

Question

How long is 1010 seconds?

There are 86400 seconds per day. So your friend’s computer will runabout: 1010

864000 seconds. Which is:

MORE THAN 27 YEARS!

() Counting Ngày 16 tháng 11 năm 2012 10 / 1

Page 39: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

Your friend tells you that his computer can execute 10,000,000,000(1010) additions per second.

The array has 10,000,000 (107) integers.

So we need to execute 16(1021 − 107) > 1020 additions.

So the computer will need more than 1010 seconds.

Question

How long is 1010 seconds?

There are 86400 seconds per day. So your friend’s computer will runabout: 1010

864000 seconds. Which is:

MORE THAN 27 YEARS!

() Counting Ngày 16 tháng 11 năm 2012 10 / 1

Page 40: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

Your friend tells you that his computer can execute 10,000,000,000(1010) additions per second.

The array has 10,000,000 (107) integers.

So we need to execute 16(1021 − 107) > 1020 additions.

So the computer will need more than 1010 seconds.

Question

How long is 1010 seconds?

There are 86400 seconds per day. So your friend’s computer will runabout: 1010

864000 seconds. Which is:

MORE THAN 27 YEARS!

() Counting Ngày 16 tháng 11 năm 2012 10 / 1

Page 41: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

Your friend tells you that his computer can execute 10,000,000,000(1010) additions per second.

The array has 10,000,000 (107) integers.

So we need to execute 16(1021 − 107) > 1020 additions.

So the computer will need more than 1010 seconds.

Question

How long is 1010 seconds?

There are 86400 seconds per day. So your friend’s computer will runabout: 1010

864000 seconds. Which is:

MORE THAN 27 YEARS!

() Counting Ngày 16 tháng 11 năm 2012 10 / 1

Page 42: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

Your friend tells you that his computer can execute 10,000,000,000(1010) additions per second.

The array has 10,000,000 (107) integers.

So we need to execute 16(1021 − 107) > 1020 additions.

So the computer will need more than 1010 seconds.

Question

How long is 1010 seconds?

There are 86400 seconds per day. So your friend’s computer will runabout: 1010

864000 seconds. Which is:

MORE THAN 27 YEARS!

() Counting Ngày 16 tháng 11 năm 2012 10 / 1

Page 43: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

Your friend tells you that his computer can execute 10,000,000,000(1010) additions per second.

The array has 10,000,000 (107) integers.

So we need to execute 16(1021 − 107) > 1020 additions.

So the computer will need more than 1010 seconds.

Question

How long is 1010 seconds?

There are 86400 seconds per day. So your friend’s computer will runabout: 1010

864000 seconds. Which is:

MORE THAN 27 YEARS!

() Counting Ngày 16 tháng 11 năm 2012 10 / 1

Page 44: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

So now you know why you need to count!

So what are you going to do next?

Tell your friend to buy a faster computer?

Or design a faster algorithm (an algorithm thatexecutes a lot less additions).

Can it be done?

ABSOLUTELY. ACTUALLY AN ALGORITHM THATWILL SOLVE THE SAME PROBLEM IN A FEWSECONDS CAN BE DESIGNED

SO NOW YOU KNOW WHY WE NEED TO LEARNHOW TO COUNT!

() Counting Ngày 16 tháng 11 năm 2012 11 / 1

Page 45: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

So now you know why you need to count!

So what are you going to do next?

Tell your friend to buy a faster computer?

Or design a faster algorithm (an algorithm thatexecutes a lot less additions).

Can it be done?

ABSOLUTELY. ACTUALLY AN ALGORITHM THATWILL SOLVE THE SAME PROBLEM IN A FEWSECONDS CAN BE DESIGNED

SO NOW YOU KNOW WHY WE NEED TO LEARNHOW TO COUNT!

() Counting Ngày 16 tháng 11 năm 2012 11 / 1

Page 46: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

So now you know why you need to count!

So what are you going to do next?

Tell your friend to buy a faster computer?

Or design a faster algorithm (an algorithm thatexecutes a lot less additions).

Can it be done?

ABSOLUTELY. ACTUALLY AN ALGORITHM THATWILL SOLVE THE SAME PROBLEM IN A FEWSECONDS CAN BE DESIGNED

SO NOW YOU KNOW WHY WE NEED TO LEARNHOW TO COUNT!

() Counting Ngày 16 tháng 11 năm 2012 11 / 1

Page 47: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

So now you know why you need to count!

So what are you going to do next?

Tell your friend to buy a faster computer?

Or design a faster algorithm (an algorithm thatexecutes a lot less additions).

Can it be done?

ABSOLUTELY. ACTUALLY AN ALGORITHM THATWILL SOLVE THE SAME PROBLEM IN A FEWSECONDS CAN BE DESIGNED

SO NOW YOU KNOW WHY WE NEED TO LEARNHOW TO COUNT!

() Counting Ngày 16 tháng 11 năm 2012 11 / 1

Page 48: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

So now you know why you need to count!

So what are you going to do next?

Tell your friend to buy a faster computer?

Or design a faster algorithm (an algorithm thatexecutes a lot less additions).

Can it be done?

ABSOLUTELY. ACTUALLY AN ALGORITHM THATWILL SOLVE THE SAME PROBLEM IN A FEWSECONDS CAN BE DESIGNED

SO NOW YOU KNOW WHY WE NEED TO LEARNHOW TO COUNT!

() Counting Ngày 16 tháng 11 năm 2012 11 / 1

Page 49: Counting - faculty.washington.edufaculty.washington.edu/moishe/Hanoi-2012/DM-2012...Ngày 16 tháng 11 năm 2012 Counting Ngày 16 tháng 11 năm 2012 1 / 1. Question What do we count?

So now you know why you need to count!

So what are you going to do next?

Tell your friend to buy a faster computer?

Or design a faster algorithm (an algorithm thatexecutes a lot less additions).

Can it be done?

ABSOLUTELY. ACTUALLY AN ALGORITHM THATWILL SOLVE THE SAME PROBLEM IN A FEWSECONDS CAN BE DESIGNED

SO NOW YOU KNOW WHY WE NEED TO LEARNHOW TO COUNT!

() Counting Ngày 16 tháng 11 năm 2012 11 / 1