Dark Mode

593 views

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

- 20
- 50
- 80
- 110

1 vote

Best answer

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