Algorithms - 2.1 Flashcards

1
Q

What are the 3 key techniques for computational thinking?

A

Decomposition
Abstraction
Algorithmic thinking

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

What is decomposition (2)?

A

Breaking a complex problem down into smaller problems
Solving each one individually

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

What is abstraction (2)?

A

Picking out the important details from a problem
Ignoring the specific details

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

What is algorithmic thinking (2)?

A

A logical way of getting the answer to a problem
Sequence of instructions which are followed step-by-step

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

What are the different searches?

A

Binary search
Linear search

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

What is an algorithm?

A

Set of instructions for solving a problem

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

What are the different ways an algorithm can be written?

A

Pseudocode
Flowcharts

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

What is pseudocode (4)?

A

Not an actual programming language but follows a similar structure
Clearly shows an algorithm’s steps without worrying about the finer details of a programming language e.g. syntax
Quick to write
Easily converted

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

What is a flowchart (2)?

A

Used to represent an algorithm
Can represent sequences, selections and interations

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

What does a flowchart do (4)? How is it presented (2)?

A

Shows the data that is input and output
Shows the processes
Shows the decisions
Shows the repetitions
Arrows show the flow of control, each shape has a different function

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

What are the 5 different shapes and functions?

A

Start/stop - beginning or end of program = box with rounded corners (terminals)
Inputs/outputs - anything that’s put into or taken out of the algorithm = parallelogram
Processes - general instructions, calculations = rectangle
Decisions - yes/no = diamond
Sub program - reference to other flowcharts = box with lines

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

What are the searching algorithms?

A

Binary search
Linear search

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

When is a binary search used? How is it performed (4)?

A

With an ordered list
1. Look for middle term (n+1/2)
2. If this is the wanted item stop the search
3. If not, compare the middle value and see if it comes before or after the wanted item. If before remove second half if after remove first half
4. Repeat steps 1-4 with smaller list

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

How is a linear search done?

A

Looks at each time on the list, stops when it’s found the term or has checked every item
1. Look at first item
2. If this is the item then stop the search
3. If not look at the next item
4. Repeat steps 2 - 3 until item is found or every item is checked

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

Pros (2) & cons (1) of binary search:

A

More efficient
Suitable for larger lists

List needs to be ordered

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

Pros (2) & cons (2) of a linear search:

A

Simpler
Can be done on any type of list

Inefficient
Suitable for only smaller lists

17
Q

What are the different sorts?

A

Bubble sort
Insertion sort
Merge sort

18
Q

How does a bubble sort work?

A
  1. Look at first two items in list
  2. If they’re in the right order keep the same
    If they’re in the wrong order, swap them
  3. Move onto the next pair of items (2nd and 3rd) and repeat step 2
  4. Repeat steps 3 until you reach the end of the list, this is called one pass
  5. Repeat steps 1-4 until there are no swaps

Example:
66 21 38 15 89 49
21 66 38 15 89 49
21 38 66 15 89 49
21 38 15 66 89 49
21 38 15 66 89 49
21 38 15 66 49 89
End of first pass

19
Q

Pros (3) & cons (2) of bubble sort:

A

Simple algorithm to implement on computer
Efficient way to check, if list is already in order
Doesn’t use much memory

Inefficient way to sort a list
Not good for long lists

20
Q

How does an insertion sort work?

A
  1. Look at second item in the list
  2. Compare it to all items before it and insert the number into the right place
  3. Repeat step 2 for the third, fourth, fifth until last number has been inserted

5|3412
35|412
345|12
1345|2
12345|

21
Q

Pros (4) & cons (1) of an insertion sort:

A

Easily coded
Copes well with small lists
Doesn’t require much memory
Quick to add items and check

Not good with larger lists

22
Q

How does a merge sort work?

A

Splits a list apart then merges it back together
1. Split the list in half
2. Keep repeating step 1 until all lists only contain 1 item
3. Then merge pairs of one by one so each list has twice the amount
4. Repeat step 3 until all lists are merged back together

23
Q

Pros (2) & cons (3) of a merge sort:

A

More efficient
Good for larger list

Slower than algorithms for smaller lists
Even if list is sorted it will still do the merge sort
Uses more memory to separate lists