Given the following algorithm for sorting an array X of N numbers: SUBROUTINE…

PYQ GATE 2007Modified — slightly modified from the official paper; see the solution

Given the following algorithm for sorting an array X of N numbers:

SUBROUTINE SORT(X,N)
    IF (N < 2)
        RETURN
    FOR (i = 2 TO N INCREMENT BY 1)
        FOR (j = 1 TO i INCREMENT BY 1)
            IF (X[i] > X[j])
                CONTINUE
            TEMP = X[i]
            X[i] = X[j]
            X[j] = TEMP
        END FOR
    END FOR
END SUBROUTINE

A good approximation of Halstead's estimated program length is

For counting distinct operators, treat each opening or closing delimiter as a separate operator; count the routine name and the closing constructs END FOR and END SUBROUTINE separately.

  1. A.

    20

  2. B.

    50

  3. C.

    80

  4. D.

    110

Attempted by 47 students.

Sign up free to check your answer

Sign up free

Explore the full course: Zero To Hero

Loading lesson…