Topic 6 - Algorithms Flashcards
1
Q
abstraction
A
- picking out the important bits of information from a problem
- removing unnecessary details
2
Q
decomposition
A
- breaking a complex problem into smaller problems and solving each one individually
3
Q
algorithmic thinking
A
- logical way of getting from problem to solution
- using steps and recycling them for similar questions
input, process, output
4
Q
2 search algorithms:
A
1) Linear
2) Binary
5
Q
linear search
A
- iterates throughout the list in order
- until item is found
6
Q
binary search
A
- checks middle item in list
- is it value? is it larger or smaller?
- if not it discards all items in 1st half or 2nd half of list
- until value is found
7
Q
linear pros
A
- much simpler
- good for short lists
- can be used on ordered or unordered lists
8
Q
binary pros
A
- more efficient
- generally takes fewer steps
- more suitable for larger lists
9
Q
bubble sort
A
- look at 1st 2 items in list
- if they are in right order do nothing but if in wrong order swap them
- move to next pair ( 2nd and 3rd ) and repeat step 2
- repeat step 3 until you get to end of list, this is a pass
- in next pass don’t include last item
- repeat process until there are no swaps in a pass
10
Q
bubble sort pros
A
- simple to check if an list is already ordered
- simple algorithm that can easily be implemented on computer
- doesn’t use much memory
11
Q
bubble sort cons
A
- inefficient way, worst case scenario n(n-1)/2 comparisons
- doesn’t cope with large list of items
12
Q
insertion sort
A
- starts with 2nd item in list
- checks if it is smaller than value before it
- if it it is, it is swapped with item on left
- continues until we find smaller item in sorted list
- moves to next item and starts process again
13
Q
insertion pros
A
- all sorting is done on the original list
- can be easily coded
- doesn’t require much additional memory
- quick for checking if list is already ordered
14
Q
insertion cons
A
- inefficient, worst case scenario same as bubble
- doesn’t cope well with large lists
15
Q
merge sort
A
- split the list in half into sub lists
- repeat until each list until contains one list
- merge lists sub-lists together, ordering them
- repeat until you only have one list
16
Q
merge pros
A
- more efficient and quicker
- more suitable for large lists
- consistent running time
17
Q
merge cons
A
- slower for small lists
- even if list is ordered it still goes through whole process
- uses more memory in order to create separate lists
18
Q
flowcharts
A
- uses symbols and arrows to show order of algorithm
- and different paths the program could take
- visual approach, easy to understand
19
Q
pseudocode
A
- not an actual programming language but should read like one
- it shows an algorithm’s steps clearly without using syntax of a language
20
Q
pros of using pseudocode
A
- quick to write
- easily understood by all programers
- can be converted into any language
21
Q
3 programming constructs
A
1) Sequence
2) Selection
3) Iteration
22
Q
sequence
A
order in which steps are carried out
23
Q
selection
A
using conditions so programs can take differnet poaths depending on input
24
Q
iteration
A
- repeating a process a certain amount of times ( count controlled) or until a condition is met ( condition controlled )