retagged by
835 views
0 votes
0 votes

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
retagged by

1 Answer

Best answer
1 votes
1 votes

Ans:B

Program length (N)

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

  • \,N_{1} = the total number of operators
  • \,N_{2} = 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

selected by
Answer:

Related questions

1 votes
1 votes
1 answer
1
0 votes
0 votes
1 answer
2
Ishrat Jahan asked Nov 1, 2014
1,308 views
void swap(float* A1, float* A2) { float temp; if (*A1 = = *A2) return; temp = *A1; *A1 = *A2; *A2 = temp; return; }The program volume for the above module using Halstead'...
0 votes
0 votes
2 answers
3
Ishrat Jahan asked Nov 1, 2014
1,134 views
void swap(float* A1, float* A2) { float temp; if (*A1 = = *A2) return; temp = *A1; *A1 = *A2; *A2 = temp; return; }The program effort for the above module using Halstead'...
5 votes
5 votes
3 answers
4