Tracing successor deletion in a linked list
Arrays & Linked Lists

Answer & solution
Official answer: 5
Approach: Notice that the tested node is ptr1’s successor, not ptr1 itself. On deletion the pointer stays still, so the replacement successor is tested next.
Initially ptr1 points to the head value 1. Its successor 7 is not in L2, so advance to 7. The next value 12 is in L2, so bypass it, leaving 7 pointing to 3. Keep ptr1 at 7, test 3, and then advance to 3 because it is absent from L2.
Delete successor 9, retain and advance to 5, then delete 11 and 15 in consecutive iterations while ptr1 remains at 5. Finally retain 8 and stop because its next pointer is NULL.
The resulting list is 1→7→3→5→8, so five nodes remain. Although head value 1 also occurs in L2, it is never tested as a successor and is not removed. Advancing ptr1 after a deletion would incorrectly skip a candidate such as 15. The code unlinks nodes without calling free; the question asks reachability in L1, not the count of still-allocated memory objects.








![Question 5, GATE 2005: Read 500 integer scores in [0, 100] and print frequencies of scores above 50. Best frequency storage? A array of 50 numbers; B array of 100; C array of 500; D dynamically allocated array of 550.](../../../assets/questions/CS-2005-Q5-1.webp)



![Question 15(a), 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. GateForum calls set(7); set(3); set(9). Find count, q[1..3], p[7],p[3],p[9].](../../../assets/questions/CS-2000-Q77-1.webp)
![Question 15(a), 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. GateForum calls set(7); set(3); set(9). Find count, q[1..3], p[7],p[3],p[9].](../../../assets/questions/CS-2000-Q77-2.webp)
![Question 15(a), 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. GateForum calls set(7); set(3); set(9). Find count, q[1..3], p[7],p[3],p[9].](../../../assets/questions/CS-2000-Q77-3.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-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)
![Question 15(c), 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. Prove is_set(i) returns false if set(i) has never been called, regardless of the initial p[i].](../../../assets/questions/CS-2000-Q79-1.webp)
![Question 15(c), 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. Prove is_set(i) returns false if set(i) has never been called, regardless of the initial p[i].](../../../assets/questions/CS-2000-Q79-2.webp)
![Question 15(c), 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. Prove is_set(i) returns false if set(i) has never been called, regardless of the initial p[i].](../../../assets/questions/CS-2000-Q79-3.webp)


![Question 2.14, GATE 1998: A[1…10][1…15] is stored in row-major order, uses one memory location per integer, and A[1][1] is at 100. Find address A[i][j].](../../../assets/questions/CS-1998-Q49-1.webp)



![Question 8, GATE 1997: A singly linked list L=(a1,…,an), n≥0, has nodes with fields next:^list and val:integer. Swap adjacent pairs a_(2i−1),a_(2i), 1≤i≤floor(n/2), by filling the four boxes:
1 function change(p:^list):^list;
2 var q,t:^list;
3 begin
4 if p=nil then change:=p
5 else if p^.next=nil then change:=[B5]
6 else begin
7 q:=p^.next;
8 [B8]:=q;
9 t:=q^.next;
10 [B10]:=p;
11 [B11]:=change(t)
12 end
13 end](../../../assets/questions/CS-1997-Q53-1.webp)









![Question 14(a), GATE 1996: An n×n integer array is intended to increase along every row and every column. Where is its minimum? The reproduction quantifies both inequalities only for i,j∈[1,n−1], which is narrower than full row/column sorting.](../../../assets/questions/CS-1996-Q71-1.webp)
![Question 14(a), GATE 1996: An n×n integer array is intended to increase along every row and every column. Where is its minimum? The reproduction quantifies both inequalities only for i,j∈[1,n−1], which is narrower than full row/column sorting.](../../../assets/questions/CS-1996-Q71-2.webp)
![Question 14(b), GATE 1996: Delete the smallest element of an n×n row- and column-increasing array. Insert x, smaller than every item of the last row and last column, in O(n) time. Complete: i:=1;j:=1;A[i,j]:=x; while (x>blank or x>blank) do if A[i+1,j]<blank then begin A[i,j]:=A[i+1,j];i:=i+1 end else begin blank end; A[i,j]:=blank. Assume the intended full monotonicity and distinct inserted value.](../../../assets/questions/CS-1996-Q72-1.webp)
![Question 14(b), GATE 1996: Delete the smallest element of an n×n row- and column-increasing array. Insert x, smaller than every item of the last row and last column, in O(n) time. Complete: i:=1;j:=1;A[i,j]:=x; while (x>blank or x>blank) do if A[i+1,j]<blank then begin A[i,j]:=A[i+1,j];i:=i+1 end else begin blank end; A[i,j]:=blank. Assume the intended full monotonicity and distinct inserted value.](../../../assets/questions/CS-1996-Q72-2.webp)
![Question 14(b), GATE 1996: Delete the smallest element of an n×n row- and column-increasing array. Insert x, smaller than every item of the last row and last column, in O(n) time. Complete: i:=1;j:=1;A[i,j]:=x; while (x>blank or x>blank) do if A[i+1,j]<blank then begin A[i,j]:=A[i+1,j];i:=i+1 end else begin blank end; A[i,j]:=blank. Assume the intended full monotonicity and distinct inserted value.](../../../assets/questions/CS-1996-Q72-3.webp)
![Question 4(b), GATE 1995: An N×N integer array A (1<N≤20) is transposed by: for I:=1 to N−1 do for J:=1 to N do begin TMP:=A[I,J]; A[I,J]:=A[J,I]; A[J,I]:=TMP end. Find and correct the error.](../../../assets/questions/CS-1995-Q53-1.webp)














