Software DD (Implementation: Standard Algorithms - Parallel Arrays)
No description yet. This curated deck is ready for daily study.
Card preview (17)
Find Min Value - Pseudocode
Lowest = array[0] FOR counter FROM 1 to length(array) IF array[counter] < lowest SET Lowest = array [counter] END IF END FOR From RGC Aberdeen Website
Find Min Value - Python
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) From RGC Aberdeen Website
Find Min Position - Pseudocode
minpos = 0 FOR counter FROM 1 to length(array) IF array[counter] < array[minpos] minpos = counter END IF END FOR From RGC Aberdeen Website
Find Min Position - Python
def findminvalue(times): minpos = 0 for counter in range(1,len(times)): if times[counter] < times[minpos]: minpos = counter return minpos fastestPos = FindMin(times) print (“Fastest time is”+ times[fastestPos] + “by” + names[fastestPos]) From RGC Aberdeen Website
Find Max Value - Pseudocode
highest = array[0] FOR counter FROM 1 to length(array) IF array[counter] > highest highest = array [counter] END IF END FOR From RGC Aberdeen Website
Find Max Value - Python
def FindMax(scores): highscore = scores[0] for counter in range(1,len(scores)): if scores[counter] > highscore: highscore = scores[counter] return highscore highestScore = FindMax(scores) print (“Highest Score is”, highestScore) From RGC Aberdeen Website
Find Max Position - Pseudocode
maxpos = 0 FOR counter FROM 1 to length(array) IF array[counter] > array[maxpos] maxpos = counter END IF END FOR From RGC Aberdeen Website
Find Max Position - Python
def FindMax(scores): highpos = 0 for counter in range(1,len(scores)): if scores[counter] > scores[highpos] : highpos = counter return highpos highPos = FindMax(scores) print (“Highest Score is” + str(scores[highPos]) + “ by “ + names[highPos]) From RGC Aberdeen Website
Linear Search - Pseudocode
SearchItem = Input From User FOR counter FROM 0 TO length(array) IF array[counter] = SearchItem DISPLAY “Item found” END IF END FOR From RGC Aberdeen Website
Linear Search - Python
def LinearSearch(items,goal): for counter in range(len(items)): if items[counter] == goal: print(“Found at position”,counter) 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] = choice: found = TRUE position = counter END IF END FOR From RGC Aberdeen Website
Linear Search with Found Flag - Python
def LinearSearch(items,goal): found = False choice = input(“Please enter search item: “) for counter in range(len(items)): if items[counter] == choice: found = True position = counter if found == False: print("No item found in list”) else: print(“Item details: ",items[position]) For some reason Brainscape made the text weird From RGC Aberdeen Website
Linear Search using a Conditional Loop - Pseudocode
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 From RGC Aberdeen Website
Linear Search using a Conditional Loop - Python
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]) From RGC Aberdeen Website
Linear Search - Conditional Loop/Function without Boolean value
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 foundpos = -1 then a match was not found in the list. This is an import consideration as a Linear Search may not always find a match. def LinearSearch(items,goal): position = -1 for counter in range(len(items)): if items[counter] == goal: position = counter return position goal = input(“Enter the item to search for: “) foundpos = LinearSearch(searcharray,goal) if found == -1: print(“No item found in list”) else: print(“Item details: “,searcharray[foundpos]) From RGC Aberdeen Website
Counting Occurences - Pseudocode
SearchItem = Input from USER Total = 0 FOR counter = 0 TO Length(array) IF array(counter) = SearchItem Total = total +1 END IF END FOR From RGC Aberdeen Website
Counting Occurences - Python
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”) From RGC Aberdeen Website