1 - Fundamentals of algorithms Flashcards

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

What is an algorithm?

A

a sequence of steps that can be followed to complete a task

note that a computer program is just an implementation of an algorithm, and an algorithm is NOT a computer program

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

What is decomposition?

A

breaking a problem down into several sub-problems, so each sub-problem accomplishes an identifiable task, which might be further subdivided

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

What is abstraction?

A

the process of removing unnecessary detail from a problem to make it easier to solve/see the solution

eg the London Underground map

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

What is a trace table used for?

A

used for following an algorithm through by hand to demonstrate its effects on the data contained by certain variables

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

What are the rules for completing a trace table?

A

-work through the table by putting values in from left to right, and don’t go backwards ever

-don’t put anything in the space if the variable doesn’t change

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

How does the linear search algorithm operate?

A

-starts with the first value in the list
-checks all values in the list in order from start to end until the desired item is found

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

What are the pros and cons of the linear search algorithm?

A

-simple to code
-works on both ordered and unordered lists

-inefficient/slow

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

How does the binary search algorithm work?

A

-find midpoint of list of numbers and see if it is equal to the desired value
-if not, check if it is greater/less than the desired value
-discard the side of the list that isn’t where the desired item is
-repeat with the other half of the list

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

Give some pros and cons for the binary search algorithm:

A

-more efficient as list size increases (discards half each time)

-data must be ordered
-harder to code

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

How does the bubble sort algorithm work?

A

-compares 1st and 2nd item, swap if needed
-repeat with 2nd and 3rd, and again until you reach the end of the list
one pass completed
-do more passes until nothing has been swapped in a pass

the larger values “bubble” to the top (or smaller values, depending on if it is descending or ascending order)

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

Give some pros and cons of the bubble sort algorithm:

A

-simple to code
-efficient way to check if the list is already ordered

-inefficient
-slower with larger lists

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

When given a question on the bubble sort like below, how should you complete it?

A

-make one switch per line
-don’t go back to the beginning for each swap, continue from where you left off in the previous switch and keep going

you forgot this in the end of year 10 exam and you could’ve got 100%

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

Explain how the merge sort algorithm operates:

A

-subdivide list into smaller lists until each item is in its own list
-compare adjacent values and swap if needed, join into several lists of 2 values
-compare first values in adjacent lists, then first and second, then second and second, add all values to new list of 4
-repeat until there is only one ordered list

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

Give the pros and cons of the merge sort algorithm:

A

-faster + more efficient with large lists
-consistent run time, regardless of how unordered the list already is

-harder to code
-it will still run through the whole process even if it is already ordered

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