SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Anany Levitin
Chapter:
Fundamentals Of The Analysis Of Algorithm Efficiency
Exercise:
2.1 Exercise
Question:10 | ISBN:9780132316811 | Edition: 3

Question

Invention of chess
a. According to a well-known legend, the game of chess was invented many centuries ago in northwestern India by a certain sage. When he took his invention to his king, the king liked the game so much that he offered the inventor any reward he wanted. The inventor asked for some grain to be obtained as follows: just a single grain of wheat was to be placed on the first square of the chessboard, two on the second, four on the third, eight on the fourth, and so on, until all 64 squares had been filled. If it took just 1 second to count each grain, how long would it take to count all the grain due to him?
b. How long would it take if instead of doubling the number of grains for each square of the chessboard, the inventor asked for adding two grains?

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

a.

In the classic chessboard problem, the number of grains placed on each square doubles compared to the previous square. This forms a geometric progression with a common ratio of 2. To find out how long it would take to count all the grain due to him, you can calculate the total number of grains placed on the chessboard and then convert it to seconds:

The number of grains on each square is given by 2(n-1), where n is the square number (ranging from 1 to 64).

So, the total number of grains on the chessboard is: 20 + 21 + 22 + ... + 262 + 263

This is a geometric progression with 64 terms. To calculate the sum of a geometric progression, you can use the formula:

Sum = a * (1 - rn) / (1 - r)

In this case:

  • a is the first term, which is 1 (20).
  • r is the common ratio, which is 2.
  • n is the number of terms, which is 64.

Plugging these values into the formula:

Sum = 1 * (1 - 264) / (1 - 2)

Sum = (1 - 264) / (-1)

Sum =264- 1

Now, you have the total number of grains on the chessboard, which is 264 - 1. To count each grain takes 1 second, so the total time it would take to count all the grains is:

Time = (264- 1) seconds

This is an enormous number:

Time ≈ 18,446,744,073,709,551,615 seconds

To put it in perspective, this is billions of times longer than the estimated age of the universe, making it practically impossible to count that many grains of wheat by hand.

b.

If the inventor asked for adding two grains to each square instead of doubling, then you simply need to calculate the sum of the arithmetic progression, where each square has 2 grains more than the previous square.

The total number of grains in this case is: 1 + (1 + 2) + (1 + 2 + 2) + ... + (1 + 2 + 2 + ... + 2)

This is an arithmetic progression with 64 terms. You can use the formula for the sum of an arithmetic progression:

Sum = (n/2) * (2a + (n-1)d)

In this case:

  • n is the number of terms, which is 64.
  • a is the first term, which is 1.
  • d is the common difference, which is 2.

Plugging these values into the formula:

Sum = (64/2) * (2*1 + (64-1)*2) Sum = 32 * (2 + 126) Sum = 32 * 128 Sum = 4,096

So, there would be a total of 4,096 grains in this case. Since it takes 1 second to count each grain, the total time it would take to count all the grains is:

Time = 4,096 seconds

This is a much more manageable amount of time compared to the previous scenario, and it would take approximately 68 minutes and 16 seconds to count all the grains.

0 0

Discussions

Post the discussion to improve the above solution.