benchmarks.wiki / Public workspace

MMLU / An algorithm will be used to identify the maximum value in a list of one or more…

Problem

Answer published by the source. Consult the official source to check your work against its answer.

question

An algorithm will be used to identify the maximum value in a list of one or more integers. Consider the two versions of the algorithm below.

 Algorithm I :  Set the value of a variable max to -1. Iterate through the list of integer
   values. If a data value is greater than the value of the variable max, set
  max to the data value.
 Algorithm II : Set the value of a variable max to the first data value. Iterate through the
   remaining values in the list of integers. If a data value is greater than the
   value of the variable max, set max to the data value.

 Which of the following statements best describes the behavior of the two algorithms?

choices

  1. Both algorithms work correctly on all input values.
  2. Algorithm I always works correctly, but Algorithm II only works correctly when the maximum value is not the first value in the list.
  3. Algorithm II always works correctly, but Algorithm I only works correctly when the maximum value is greater than or equal to -l.
  4. Neither algorithm will correctly identify the maximum value when the input contains both positive and negative input values.

subject

high_school_computer_science

Discussion

Discussion

No discussion posts on this page yet. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.

Source and history

Official source

initial import