Software DD (Implementation: Standard Algorithms - Records) Flashcards

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

Find Min Value - Pseudocode

A

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

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

Find Min Value - Python

A

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

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(pupils)
IF pupils[counter].mark < pupils[minpos].mark
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 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

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(pupils)
IF pupils[counter].mark > highest
highest = pupils [counter].mark
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

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

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(pupils)
IF pupils[counter].mark > pupils[maxpos].mark
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 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

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

Linear Search - Pseudocode

A

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

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

Linear Search - Python

A

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

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].mark = 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

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

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(pupils) AND found = FALSE
IF array [counter].name = 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

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

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

Linear Search - Conditional Loop/Function without Found flag

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 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

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

Counting occurrences - Pseudocode

A

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

17
Q

Counting occurrences - Python

A

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