The Art of Computer Programming (2nd ed.): Mathematical Induction [closed] - taocp

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
In 1.2.1 Mathematical Induction section, Knuth presents mathematical induction as a two steps process to prove that P(n) is true for all positive integers n:
a) Give a proof that P(1) is true;
b) Give a proof that "if all P(1), P(2),..., P(n) are true, then P(n+1) is also true";
I have serious doubt about that. Indeed, I believe that point b) should be:
b) Give a proof that "if P(n) is true, then P(n+1) is also true". The major difference here is that you are only assuming that P(n) is true, not P(n-1), etc.
However, these books are old and have been read by many people (most of them being much more clever than I am^^).
So what is my confusion here?

The entire point here is that the choice of n is arbitrary. Since P(n) implies P(n+1) is the conerstone of induction, then all the intermediate values between 1 and n will also hold under the assumption of P(n). You are supposed to show that if P(0) implies P(1) and P(n) implies P(n+1) then all conditions hold by the nature of n being arbitrary.

Related

How to make correct function in dynamic programming [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have the following problem in dynamic programming.
A person has time machine and he can move in time either 1 year or 2. At the beginning he is at year 0 and he wants to reach year 100. Every step he does (1 or 2 years) he is paying some fixed fees. There is an array with 100 integers represents the fee he needs to pay if he went threw the specific year.
I need to find the minimum amount the person can pay to go from year 0 to year 100 using dynamic programming.
From what i have done so far i think that there should be something like
minCost(i) = min{A[i-1], A[i-2]}
and the base cases are years 1 and 2 which costs A[1], A[2] respectively. But i think this approach has more of greedy algorithm rather than dynamic programming.
I saw the bin packing algorithm of dynamic programming and i understood it and the matrix that represents it.
How should the matrix of the shown problem above look like?
And how should i build the function and the pseudo code for this problem?
You are almost there.
Think about how will you reach the i th year from i-1 th year and i-2 th year. There is a fee which you are forgetting to take into consideration.
MinCostToReachYear(i) = min( MinCostToReachYear(i-1) + fee(i-1), MinCostToReachYear(i-2) + fee(i-2) )
You already know the base cases year 1 and year 2. Can you think of extrapolating with the use of a for loop or more easily with a recursive function which you already know as mentioned above? I leave it as an exercise for you.

What are typical lengths of chat message and comment in database? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I need to create a column in SQL Server database. Entries for that column will contain messages from chat. Previously such messages has been stored as comments.
My main quetion is:
What is typical text length for chat message and comment?
By the way:
What would happen if I used varchar(max)? How would it impact database size and performance? Is better to use powers of 2 or powers of 10 (e.g. 128 instead of 100) while considering text lengths?
Using VARCHAR(MAX) has a disadvantage: you can not define an index over this column.
Generally, your application should impose a maximum length for a chat message. How big that limit is depends very much on what the application is used for. But anything more than 1000 byte is probably less a legitimate message but an attempt to disrupt your service.
If your maximum value is a power of 2, or a power of ten or any other value has no influence on the performance as long as the row fits in one (8KB) page.
Short answer - it doesn't matter.
From MSDN:
The storage size is the actual length of the data entered + 2 bytes.
So VARCHAR(10) and VARCHAR(10000) will consume the same amount of data if the values don't exceed 10 characters.
Definitely use N/VARCHAR(MAX), it can grow to be 2GB (if I remember correctly). It will grow as required though, so it is very efficient with regards to space unless you are only storing very small amounts of data.

This is very easy but i am struck with one [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
This is findind limit calculus one. This would be very easy but i never factor high degrees. can anyone show me how to factor it.
lim((x^5-32)/(x-2),x=2)
lim((x^5-2^5)/(x-2),x=2)
As John suggested in the comments above: when x-->2 we handle a limit of type 0/0. In order to calculate it we use the derivative of the numerator and a derivative of the denominator:
f'(X^5-2^5) = 5x^4
---------- ----
f'(x-2) = 1
if we'll substitute x with 2 we'll get:
5*2^4
----- = 80
1

Why is the key space for a substitution cipher Factorial N [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm taking a crypto course, and we're going over substitution ciphers and their Key space.
per the instructor, the key space is 26! (approx 2^88) for the English alphabet. there is no reference to key length, probably because a subst cipher's length would be a function of the length of the alphabet, just as the number of options would.
per wikipedia the keyspace is the set of all possible keys of a certian length, and is calculated in the same way brute force try counts would be options^length or in this case 26^26.
so what am I not getting here?
That's a bit misleading, both your instructor and Wikipedia are correct.
Generally, key of 26 english letters defines a key space sized 2626.
For substitution ciphers over english alphabet 26! is the correct number representing the key space. That's because for substitution cipher the key is defined as a unique replacement of each letter with another one, e.g. A -> D, B -> M, C -> Y, etc. 26 letters --> key can be any permutation of 26-letter set --> 26!. Due to the uniqueness required for substitution, the key space is effectively smaller than the maximal 2626, because some (most) of the keys aren't possible - e.g., you can't map both A and B to D.
If your key is a set of digits, options^length is correct. Every digit may occur several times.
If your key is an alphabet, Factorial N is correct. Say, you want to place the A first. You have 26 options. After that, you have only 25 options for the B because A already occupies one. 24 For the C and so on.
26*25*24*...*1 = 26!

Lehmann Test for prime numbers [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I learn cryptography at my university, and I need to make an application for testing numbers as prime numbers.
I must to do it using Lehmann Test, but I don't know anything about it. Please, describe me the algorithm or give me an example (Java, C#, C++, etc). Thank you for helping.
Let's call PP your Potential Prime.
(1) Choose a random number a less than PP.
(2) Calculate a^(p-1)/2 mod PP.
(3) If a^(PP-1)/2 /= 1 or -1 (mod PP), then PP is not prime.
(4) If a^(PP-1)/2 = 1 or -1 (mod PP), then the probability that PP is not prime is less than 50%.