Standard Algorithms Flashcards

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

Find maximum.

A
SET maximum TO array [0]
FOR counter FROM 1 to 9 DO
   IF array [counter] > maximum THEN 
       SET maximum TO array [counter]
   END IF
END FOR
SEND “The maximum value was” and maximum to display
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Find minimum.

A
SET minimum TO array[0]
FOR counter FROM 1 to 9 DO
   IF array [counter] < minimum THEN
       SET minimum TO array [counter]
   END IF
END FOR 
SEND “ The minimum value was” and minimum value TO DISPLAY
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Count occurrences.

A
SET occurrence TO 0
RECEIVE target FROM (INTEGER) KEYBOARD
FOR counter FROM 0 TO 9 DO
   IF array [counter] = target THEN
      SET occurrence TO occurrence + 1
   END IF
END FOR 
SEND “There were “ and occurrence and “of” and target TO DISPLAY
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Linear search.

A
SET item_found TO FALSE
SET counter TO 0
RECEIVE target FROM(STRING)KEYBOARD
REPEAT
  IF target = array[counter]THEN
      SET item_found TO TRUE
      SEND “The program found” and target and “at position” and counter TO DISPLAY
  ELSE
     SET counter TO +1
   END IF
UNTIL counter = 10 OR item_found = TRUE
IF item_found = FALSE THEN
     SEND “ The program did not find a match for” and target TO DISPLAY 
END IF
How well did you know this?
1
Not at all
2
3
4
5
Perfectly