Standard Algorithms Flashcards

Suitable for Python Users

1
Q

What are the four standard algorithms required at Higher?

A
Count Occurrence
Linear Search
Finding Minimum
Finding Maximum
(Input Validation)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe how a count occurrence works?

A

It uses a fixed loop to count how many times a certain value is repeated

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

Write a Linear Search Algorithm in pseudocode

A

Set up array
Set up value to look for
Set found to false
Loop until array is finished or found = true:
Compare current value of array to value
If they are the same:
Set found to true
Set location as position in array
Drop out of loop

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

Write a Count Occurrence Standard Algorithm in Python

A
array = [1, 4, 6, 8, 7, 4, 3, 4]
value = 4
count = 0
for i in range(8):
    if array[i] = value
    count = count + 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Write a Finding Minimum Standard Algorithm in Python

A
array = [2, 3, 5, 4, 1, 8, 2]
minimum = array[0]
for i in range(7):
    if array[i] < minimum:
         minimum = array[i]
print(minimum)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What changes would you have to make to a finding minimum algorithm to make it a finding maximum?

A

minimum variable name = maximum variable name

< would be swapped for >

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

Does a finding the maximum use a fixed loop or a conditional loop?

A

Fixed loop

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

How would you set up a record storing athlete as name, age, club, race, PB

A

RECORD athlete IS{STRING name, INTEGER age, STRING club, INTEGER race, REAL pb}

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

Is count occurrence a procedure or a function?

A

It is a function since it returns a VALUE (number of times a value repeats in the array)

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