MIN and MAX programs Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

what’s the difference between using a FOR loop and a WHILE loop for an algorithm to find the highest or lowest value

A
  • FOR loop: will iterate or loop a set number of times
  • WHILE loop: uses a condition statement (true or false) to find if the final index value is reached
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what is the FOR loop algorithm to find the lowest value from a array list

A

ages <– [99, 15, 25, 55, 61]
min <–100
FOR index <– 1 TO 5
IF ages[index] < min
THEN
min <– age[index]
ENDIF
NEXT index
OUTPUT “The lowest age is “, min

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is the WHILE loop algorithm that finds the lowest value in an array

A

ages <– [99, 15, 25, 55, 61]
min <– 100
count <– 1
WHILE count <= LENGTH(ages) DO
IF ages[count] < min
THEN
min <–age[index]
ENDIF
count = count + 1
END WHILE
OUTPUT “The lowest age is “, min //output the lowest age.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

FOR loop algorithm to find the highest value from a array list

A

ages <– [99, 15, 25, 55, 61]
max <– 0
FOR index <– 1 TO 5
IF ages[index] > max
THEN
max <– age[index]
ENDIF
NEXT index
OUTPUT “The highest age is “, max

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

WHILE loop algorithm that finds the highest value in an array

A

ages <– [99, 15, 25, 55, 61]
max <– 0
count <– 1
WHILE count <= LENGTH(ages) DO
IF ages[count] > max
THEN
max <– ages[index]
ENDIF
count = count + 1
ENDWHILE
OUPUT “ The highest age is”, max

How well did you know this?
1
Not at all
2
3
4
5
Perfectly