Software DD (Implementation: Standard Algorithms - Records)
No description yet. This curated deck is ready for daily study.
Card preview (17)
Find Min Value - Pseudocode
lowest = pupils[0].mark FOR counter FROM 1 to length(pupils) IF pupils[counter].mark < lowest Lowest = pupils [counter].mark END IF END FOR From RGC Aberdeen website
Find Min Value - Python
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)) From RGC Aberdeen website
Find Min Position - Pseudocode
minpos = 0 FOR counter FROM 1 to length(pupils) IF pupils[counter].mark < pupils[minpos].mark minpos = counter END IF END FOR From RGC Aberdeen website
Find Min Position - Python
def findMinPos(pupils): minpos = 0 for x in range(1,len(pupils)): if pupils[x].mark < pupils[minpos].mark : minpos = x return minpos lowpos = findMinPos(pupils) print(“The lowest mark was “ + pupils[lowpos].Mark + “ by “ + pupils[lowpos].Name) From RGC Aberdeen website
Find Max Value - Pseudocode
highest = array[0] FOR counter FROM 1 to length(pupils) IF pupils[counter].mark > highest highest = pupils [counter].mark END IF END FOR From RGC Aberdeen website
Find Max Value - Python
maximum = scores[0].mark for x in range(1,len(pupils)): if pupils[x].mark > maximum: maximum = pupils[x].mark print(“Highest mark is”, maximum) From RGC Aberdeen website
Find Max Position - Pseudocode
maxpos = 0 FOR counter FROM 1 to length(pupils) IF pupils[counter].mark > pupils[maxpos].mark maxpos = counter END IF END FOR From RGC Aberdeen website
Find Max Position - Python
def findmaxvalue(pupils): maxpos = 0 for x in range(1,len(pupils)): if pupils[x].mark > pupils[maxpos].mark : maxpos = x return maxpos From RGC Aberdeen website
Linear Search - Pseudocode
SearchName = Input from user FOR counter FROM 0 TO length(pupils) IF array[counter].name = SearchItem Display “Item found” END IF END FOR From RGC Aberdeen website
Linear Search - Python
choice = input(“Please enter the name to search for: “) for counter in range(len(pupils)): if pupils[counter].name == choice: print(“Item details: “,pupils[counter].name) From RGC Aberdeen website
Linear Search with Found Flag - Pseudocode
choice = Input from user found = FALSE FOR counter FROM 0 TO length(array) IF array [counter].mark = choice: found = TRUE position = counter END IF END FOR From RGC Aberdeen website
Linear Search with Found Flag - Python
found = False choice = input(“Please enter search name: “) for counter in range(len(pupils)): if pupils[counter].name == choice: found = True position = counter if found == False: print(“No pupil found in list”) else: print(“Pupil details: “,pupils[position].name) From RGC Aberdeen website
Linear Search Using a Conditional Loop - Pseudocode
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 From RGC Aberdeen website
Linear Search Using a Conditional Loop - Python
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) From RGC Aberdeen website
Linear Search - Conditional Loop/Function without Found flag
Another method useful for a linear search is to just return the found position, but using the value -1 as the default. That way you know that if the foundpos is still equal to -1 after you have finished traversing through the array then you haven’t found a match. def linearsearch(array): foundpos = -1 choice = input(“Please enter search name: “) while counter < len(pupils) and foundpos == -1: if pupils[counter].mark == choice: foundpos = counter counter += 1 return foundpos From RGC Aberdeen website
Counting occurrences - Pseudocode
SearchName = Input from user Total = 0 FOR counter = 0 TO Length(array).name IF array(counter).name = SearchName total = total +1 END IF END FOR From RGC Aberdeen website
Counting occurrences - Python
def countOccurences(pupils): occurences = 0 for counter in range(len(pupils)): if pupil[counter].mark >= 50: occurences += 1 return occurences amount = countOccurences(pupils) print(“There were” + str(amount) + “passes”) From RGC Aberdeen website