Chapter 7 Algorithm Design And Problem Solving: Unit 7.4: Standard Methods Of Solution Flashcards

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

What are the 5 standard methods of solution?

A

Totalling
Counting
Finding the max, min and average (mean) values
Searching using a linear search
Sorting using a bubble sort

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

Describe totalling.

A

Keeping a total that values are added to.

Example:
Total <– 0
FOR Counter <– 1 TO ClassSize
Total <– Total + StudentMark[Counter]
NEXT Counter

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

Describe counting.

A

Keeping a count of the number of times an action is performed.

Example:
PassCount <– 0
FOR Counter <– 1 TO ClassSize
INPUT StudentMark
IF StudentMark > 50
THEN
PassCount <– PassCount + 1
NEXT Counter
Count <– Count + 1

Can also be used to count down.

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

Describe finding the max, min and average (mean) values.

A

Finding the largest and smallest values in a list.

Example:
MaximumMark <– 0
MinimumMark <– 100
FOR Counter <– 1 TO ClassSize
IF StudentMark[Counter] > MaximumMark
THEN
MaximumMark <– StudentMark[Counter]
ENDIF
IF StudentMark[Counter] < MinimumMark
THEN
MinimumMark <– StudentMark[Counter]
ENDIF
NEXT Counter

Calculating the average (mean) of all values in a list is an extension of the totalling method.

Example:
Total <– 0
FOR Counter <– 1 TO ClassSize
Total <– Total + StudentMark[Counter]
NEXT Counter
Average <– Total / ClassSize

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

Describe linear search.

A

A search is used to check if a value is stored in a list, performed by systematically working through the items in the list. Linear search inspects each item in a list in turn to see if the item matches the value searched for.

Example:
OUTPUT “Please enter name to find “
INPUT Name
Found <– FALSE
Counter <– 1
REPEAT
IF Name = StudentName[Counter]
THEN
Found <– TRUE
ELSE
Counter <– Counter + 1
ENDIF
UNTIL Found OR Counter > ClassSize
IF Found
THEN OUTPUT Name, “ found at position “, Counter, “ in the list.”
ELSE
OUTPUT Name, “ not found.”
ENDIF

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

Describe bubble sort.

A

Each element is compared with the next element and swapped if the elements are in the wrong order, starting from the first element and finishing with the next-to-last element.

Example:
First <– 1
Last <– 10
REPEAT
Swap <– FALSE
FOR Index <– First TO Last - 1
IF Temperature[Index] > Temperature[Index + 1]
THEN
Temp <– Temperature[Index]
Temperature[Index] <– Temperature[Index + 1]
Temperature[Index + 1] <– Temp
Swap <– TRUE
ENDIF
NEXT Index
Last <– Last - 1
UNTIL (NOT Swap) OR Last = 1

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