# ℹ️ standard algorithms

The standard algorithms are a set of well-known steps for getting results from a list of values.

count the occurrences of a value (how many times does a value appear in a list).

find maximin, find minimum (what is the largest, or smallest, value in a list.

search for to locate or check for the presence of a target value in a list.

### data array

`47`

`56`

`44`

`50`

`61`

`39`

how many values are above 50 (count) what is the largest value (find max) what is the lowest value (find min) does the value 50 appear (linear search) ### count algorithm

`1 set count to 0`

`2 loop for each value`

`3 if next value matches target condition`

`4 add 1 to count`

`5 end if`

`6 end loop`

`7 display count`

count values above 50 result: 2

### find max algorithm

`1 set max to -1`

`2 loop for each value`

`3 if next value is larger than max`

`4 set max to next value`

`5 end if`

`6 end loop`

`7 display max`

result : 61

### find min algorithm

`1 set min to 999`

`2 loop for each value`

`3 if next value is smaller than min`

`4 set min to next value`

`5 end if`

`6 end loop`

`7 display min`

result : 39

### linear search algorithm

`1 set found to false`

`2 loop for each value`

`3 if value matches search target`

`4 set found to true`

`. (display position)`

`5 end if`

`6 end loop`

`7 display found`

search for 50 result: true

re-using a standard algorithm design

# ℹ️ algorithms remix

count, multiple counts/ conditions

max and position

min and position

search and stop, report position

search without flag

### data array

`47`

`50`

`44`

`50`

`61`

`39`

how many values are above 50, how many are below 45 (count) what is the largest value and what position is it in the list (find max) what is the lowest value and what position is it in the list (find min) does the value 50 appear and at what position (linear search) ### count algorithm

` 1 set countA to 0`

` 2 set countB to 0`

` 3 loop for each value`

` 4 if next value matches first target condition`

` 5 add 1 to countA`

` 6 end if`

` 7 if next value matches second target condition`

` 8 add 1 to countB`

` 9 end if`

`10 end loop`

`11 display countA, countB`

count values above 50 and those below 45 result: 2

### find max algorithm

remix:

report the location of the max value `1 set max to first value`

`2 set maxPosition to 0`

`3 loop for each value starting at the second value`

`4 if next value is larger than max`

`5 set max to next value`

`6 set maxPosition to position of next value`

`7 end if`

`8 display max`

`9 display maxPosition`

result : 61 at position 4

### find min algorithm

remix:

report the location of the min value `1 set min to first value`

`2 set minPosition to 0`

`3 loop for each value starting at the second value`

`4 if next value is smaller than min`

`5 set min to next value`

`6 set minPosition to position of next value`

`7 end if`

`8 display min`

`9 display minPosition`

result : 39 at position 5

### linear search algorithm

remix:

stop searching as soon a value is located, ` 1 set found to -1`

` 2 set position = 0`

` 3 loop while found = 0 and position < length of data array`

` 4 if value at position matches search target`

` 5 set found to position of next value`

` 6 end if`

` 7 add 1 to position`

` 8 end loop`

` 9 if found = 0`

`10 display not present`

`11 else`

`12 display value located at found`

`13 end if`

search for 50 result: true

# ℹ️ algorithm mashup

sequence of algorithms

integration of algorithms

find max and min on a single traverse