standard algarithms Flashcards
find min pseudocode (parallel arrays)
SET Lowest = array[0]
FOR counter FROM 1 to length(array)
IF array[counter] < lowest
SET Lowest = array [counter]
END IF
END FOR
find min python (parallel arrays)
def FindMin(times):
minimum = times[0]
for counter in range(1,len(times)):
if times[counter] < minimum:
minimum = times[counter]
return minimum
fastestTime = FindMin(times)
print (“Fastest time is”, fastestTime)
linear search pseudocode (parallel arrays)
choice = input from USER
found = FALSE
counter = 0
WHILE counter <len(names) AND found = FALSE
IF array [counter] = choice: found = TRUE position = counter
END IF
counter = counter +1
END WHILE
linear search python (parallel arrays)
def LinearSearch(items,goal):
found = False
choice = input(“Enter search item: “)
while counter < len(items) and found == False:
if items[counter] == choice:
found = True
position = counter
counter += 1
if found == False: print("No item found in list”) else: print(“Item details: ",items[position])
counting occurrences pseudocode (parallel arrays)
GET SearchItem FROM KEYBOARD
Total = 0
FOR counter = 0 TO Length(array)
IF array(counter) = SearchItem
Total = total +1
END IF
END FOR
counting occurrences python (parallel arrays)
def CountOccurences(passes):
occurences = 0
for counter in range(len(passes)):
if passes[counter] == “Pass”:
occurences += 1
return occurences
amount = CountOccurences(passes)
print(“There were” + str(amount) + “ of passes”)
find min pseudocode (records)
SET lowest = pupils[0].mark
FOR counter FROM 1 to length(pupils)
IF pupils[counter].mark < lowest
SET Lowest = pupils [counter].mark
END IF
END FOR
find min/max python (records)
def FindMin(pupils):
minimum = pupils[0].mark
for x in range(1,len(pupils)):
if pupils[x].mark < minimum:
minimum = pupils[x].mark
return minimum
lowmark = LinearSearch(pupils)
print(“Lowest mark is “ + str(lowmark))
linear search pseudocode (records)
choice = input from USER
found = FALSE
counter = 0
WHILE counter <len(pupils) AND found = FALSE
IF array [counter].name = choice: found = TRUE position = counter
END IF
counter = counter +1
END WHILE
linear search python (records)
found = False
choice = input(“Enter search Name: “)
while counter < len(pupils) and found == False:
if pupils[counter].name == choice:
found = True
position = counter
counter += 1
if found == False:
print(“No pupil found in list”)
else:
print(“Pupil details: “,pupils[position].name)
record structure python
from dataclasses import dataclass
@dataclass
class pupil:
name : str = “”
mark : float = 0.0
create a data structure called pupils for 40 records called pupil
pupils = pupil * 40