Software DD (Implementation: Standard Algorithms - Parallel Arrays) Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Find Min Value - Pseudocode

A

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

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

Find Min Value - Python

A

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

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

Find Min Position - Pseudocode

A

minpos = 0
FOR counter FROM 1 to length(array)
IF array[counter] < array[minpos]
minpos = counter
END IF
END FOR

From RGC Aberdeen Website

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

Find Min Position - Python

A

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

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

Find Max Value - Pseudocode

A

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

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

Find Max Value - Python

A

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

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

Find Max Position - Pseudocode

A

maxpos = 0
FOR counter FROM 1 to length(array)
IF array[counter] > array[maxpos]
maxpos = counter
END IF
END FOR

From RGC Aberdeen Website

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

Find Max Position - Python

A

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

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

Linear Search - Pseudocode

A

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

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

Linear Search - Python

A

def LinearSearch(items,goal):
for counter in range(len(items)):
if items[counter] == goal:
print(“Found at position”,counter)

From RGC Aberdeen Website

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

Linear Search with Found Flag - Pseudocode

A

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

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

Linear Search with Found Flag - Python

A

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

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

Linear Search using a Conditional Loop - Pseudocode

A

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

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

Linear Search using a Conditional Loop - Python

A

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

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

Linear Search - Conditional Loop/Function without Boolean value

A

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

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

Counting Occurences - Pseudocode

A

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

17
Q

Counting Occurences - Python

A

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