Question: Consider the pseudocode below for the unranking algorithm presented in lecture 9 . The input is P : the rank or position of the string

Consider the pseudocode below for the unranking algorithm presented in lecture 9 . The input is P : the rank or position of the string that we would like to unrank, n : the length of the string, and k : the number of ones or density of the binary string. The output is a list of distinct integers pk,pk1,p2,p1 in decreasing order, such that P=i=1k(pii).n and k are both positive integers with kn, and P is an integer between 0 and (nk)1, inclusive. procedure Unrank ( P: rank or position string, n : length of string, k: number of ones (density)) 1. r=P// remainder term 2. i=k 3. x=n 4. prevIndex =n+1 5. p= vector of size k// initialized to 1s 6. while (i>0) 7. previndex =x// index of previous 1 in string, or k if no 1 s have been placed 8. x= largest integer such that (xi)r 9. p[i]=x 10. r=r(xi) 11. i=i1 12. return p (a) (5 points) Use induction to prove the following loop invariant, where rt is the remainder term after t iterations: After t iterations, P=rt+m=k+1tk(p[m]m) (b) (5 points) Use induction to prove the following loop invariant: After t iterations, rt
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
