593 views

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

 SUBROUTINE SHORT (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 SUBROUTINE

A good  approximation of Halstead`s estimated program length is

1. 20
2. 50
3. 80
4. 110

## Program length (N)

The program length (N) is the sum of the total number of operators and operands in the program:
N = N1 + N2

•  = the total number of operators
•  = the total number of operands

Operators are

 Operator Occurences IF 2 RETURN 1 FOR 2 TO 2 INCREMENT 2 BY 2 CONTINUE 1 END 1 () 4 [] 6 < 1 > 1 = 5

N1=30

 OPERAND OCCURENCES N 2 i 5 j 4 TEMP 2 2 2 1 3 X 2

N2=20

Program Length= 20+30=50

1 vote
1
1,347 views