subject

Proving the correctness of the cocktail shaker sorting algorithm: for (int i = 0; i < (n+1)/2; i++){ for (int j = i; j < n-i-1; j++) if (a[j] > a[j+1]) swap(a[j],a[j+1]); for (int j = n-i-2; j > i; if (a[j] < a[j-1]) swap(a[j],a[j-1]); } (a) the input to the algorithm is an array of n integers that are unsorted a and after the algorithm runs the array will be sorted. state the loop invariant of the outer loop of the cocktail shaker algorithm. (it may be to trace the algorithm on small input to see what it does.) (b) prove the loop invariant using induction over the number of iterations, i. e. i may be used. (c) show how the correctness of the loop invariant shows the correctness of the algorithm.

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 05:10
Suppose we have a byte addressable computer that has a 32-byte cache with 8 bytes per block. the memory address is 8 bits long. the system accesses memory addresses (in hex) in this exact order: 6e, b9, 17, e0, 4e, 4f, 50, 91, a8, ab, ad, 93, and 94. (a) assuming the cache is direct mapped, what memory addresses will be in cache block 2 after the last address has been accessed? (b) assuming the cache is direct mapped, what is the hit ratio for the entire memory reference sequence given, assuming the cache is initially empty? (c) assuming the cache is 2-way set associative with a lru replacement policy, what is the hit ratio?
Answers: 3
question
Computers and Technology, 22.06.2019 08:00
Two technicians are discussing the common u-joint. technician a says its input and output speeds should be equal. technician b says that it normally has two yokes. which technician is correct?
Answers: 1
question
Computers and Technology, 25.06.2019 03:00
What judgment would you make about open systems interconnect? not useful that it is a technology that it is a model that it does not pertain to technology
Answers: 1
question
Computers and Technology, 25.06.2019 10:00
Why does delete questions and i checked today and me and my friends comments were deleted so was all my questions
Answers: 2
You know the right answer?
Proving the correctness of the cocktail shaker sorting algorithm: for (int i = 0; i < (n+1)/2;...
Questions
question
Geography, 31.08.2019 23:30
question
Mathematics, 31.08.2019 23:30
question
Mathematics, 31.08.2019 23:30
question
History, 31.08.2019 23:30