subject

Use the loop invariant (I) to show that the code below correctly computes n P−1 k=0 2k
(this sum represents the sum of the first n even integers where n ≥ 1).
Algorithm 1 evenSum(int n)
1: p = 2(n − 1)
2: i = n − 1
3: while i > 0 do
4: //(I) p = nP−1 k=i 2k
5: i − −
6: p = p + 2i
7: end while
8: return p
Prove the Base case of the loop invariant (I):

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 04:30
There is a simple pattern for determining if a binary number is odd. what is it and why does this pattern occur? how many bits would you need if you wanted to have the ability to count up to 1000? how high could you count in binary if you used all 10 of your fingers as bits? (finger up means 1, finger down means 0)
Answers: 3
question
Computers and Technology, 22.06.2019 11:30
One subtask in the game is to roll the dice. explain why is roll the dice an abstraction.
Answers: 3
question
Computers and Technology, 23.06.2019 02:50
There’s only one game mode that stars with the letter ‘e’ in cs: go. which of the options below is it?
Answers: 1
question
Computers and Technology, 23.06.2019 12:50
Which syntax error in programming is unlikely to be highlighted by a compiler or an interpreter? a variable name misspelling a missing space a comma in place of a period a missing closing quotation mark
Answers: 1
You know the right answer?
Use the loop invariant (I) to show that the code below correctly computes n P−1 k=0 2k
(this...
Questions
question
Chemistry, 19.10.2019 10:30
Questions on the website: 13722362