3.1 Funadmentals Of Algorithms Flashcards

1
Q

Algorithm

A

Step by step sequence of instructions to achieve a goal.

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

Algorithm design

A

• Unambiguous. Clear, concise, not open to misinterpretation.
• Works correctly of all possible inputs and executes in a finite amount of time.

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

Flowcharts

A

• Alternative to pseudocode
• Must start/stop with the terminator
• Operation - assigning values, doing calculations etc
• Decisions - True of false only
• Connectors - help us split flowcharts into smaller sections.

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

Decomposition

A

Repeated breaking down of problems into smaller problems, or sub problems.

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

Benefits of decomposition?

A

• Coding tasks are kept small and manageable
• Coding tasks can be solved independently
• Subroutines can be tested independently
• Subroutines can be updated without affecting the wider program (providing its inputs and outputs aren’t changed)

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

Abstraction

A

Removing unnecessary details from a problem.
Subroutines allow abstraction:
• Once written they are just called by their name.
• The complex code in them is hidden. All we need to know is how to use them.

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

Benefits of abstraction?

A

• Removal of complexity.
• Easier to understand what is needed.
• Focus is on the relevant details.

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

Linear search

A

Scans each item in an unsorted collection one at a time.
Stops when the item is found or when the end of the collection is reached.
The average time for a search is:
Number of elements / 2

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

Binary search

A

Scans each item in a sorted collection one at a time.
Find the middle of the collection.
Compare the value with the value you are looking for.
If found, finish.
Otherwise, you know now which half the item you want is in.
Repeat the halving until found, or you have no values left to search.

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

Comparison between linear and binary search

A

• The binary search will be much quicker than a linear search.
• Linear search can work on unordered lists but binary can’t.
• Linear search is inefficient at searching large lists but binary is efficient.

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

Bubble sort

A

Given a list of values, the computer compares the adjacent pairs of elements and swaps them if they are not in the right order. It will make several passes of the list until the data is in sorted order.

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

Merge sort

A

1) Split the list into 2 sub-lists.
2) Repeat step 1 on each sub-list until all sub-lists only contain one item.
3) Merge pairs of sub lists back together. Each time you merge 2 sub-lists, sort the items into the right order.

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

Merge sort pros and cons

A

+ Efficient on large lists.
+ Running time unaffected by order of items in original list.
- Slower on small lists.
- Uses more memory in order to create sub-lists.
- Goes through whole process even if list is already sorted

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

Bubble sort pros and cons

A

+ Simple and easy to implement
+ Quick to check if a list is already sorted
+ Doesn’t need much memory, sorting only uses original list.
- Inefficient on large lists.

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