GATE | GATE CS 1996 | Question 62

A two dimensional array A[1…n][1…n] of integers is partially sorted if

i, j ∈ [1...n−1], A[i][j] < A[i][j+1] and A[i][j] < A[i+1][j]

Fill in the blanks:

a) The smallest item in the array is at A[i][j] where i=………………and j=………………….
b) The smallest item is deleted. Complete the following O(n) procedure to insert item x (which is guaranteed to be smaller than any item in the last row or column) still keeping A partially sorted.

procedure insert (x: integer);
var i,j: integer;
begin
    i:=1; j:=1, A[i][j]:=x;
    while (x > ...... or x > ......) do
        if A[i+1][j] < A[i][j] ......... then begin
            A[i][j]:=A[i+1][j]; i:=i+1;
        end
        else begin
            ............
        end
    A[i][j]:= .............
end
.


Answer:

Explanation:

Quiz of this Question
Please comment below if you find anything wrong in the above post



My Personal Notes arrow_drop_up


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.