Arrays & Linked Lists
![Question 15(b), GATE 2000: Arrays p[1..N] and q[1..N] initially contain arbitrary values; count=0. Pseudocode:
set(i) { count=count+1; q[count]=i; p[i]=count; }
is_set(i) { if (p[i]<=0 or p[i]>count) return false; if (q[p[i]]!=i) return false; return true; }
Assume valid indices and no capacity overflow. Fill: The first count elements of ____ contain values i such that set(____) has been called.](../../assets/questions/CS-2000-Q78-1.webp)
![Question 15(b), GATE 2000: Arrays p[1..N] and q[1..N] initially contain arbitrary values; count=0. Pseudocode:
set(i) { count=count+1; q[count]=i; p[i]=count; }
is_set(i) { if (p[i]<=0 or p[i]>count) return false; if (q[p[i]]!=i) return false; return true; }
Assume valid indices and no capacity overflow. Fill: The first count elements of ____ contain values i such that set(____) has been called.](../../assets/questions/CS-2000-Q78-2.webp)
![Question 15(b), GATE 2000: Arrays p[1..N] and q[1..N] initially contain arbitrary values; count=0. Pseudocode:
set(i) { count=count+1; q[count]=i; p[i]=count; }
is_set(i) { if (p[i]<=0 or p[i]>count) return false; if (q[p[i]]!=i) return false; return true; }
Assume valid indices and no capacity overflow. Fill: The first count elements of ____ contain values i such that set(____) has been called.](../../assets/questions/CS-2000-Q78-3.webp)
Answer & solution
Answer: q; i (no official key was published)
The completed sentence is: The first count elements of q contain values i such that set(i) has been called. Each invocation appends its argument to q at the new count and records that position in p. Hence q[1..count] is a dense log of calls, in invocation order. It contains no uninitialized holes because count starts at zero and increases by exactly one before each write. Repeated set(i) calls may put repeated copies of i into q, while p[i] records the latest position. The claim is about values that have been set, not necessarily distinct values.