Algorithms (PAPER 2) Flashcards

1
Q

What are the three key techniques for computational thinking
- Give a brief description of each

A
  • Decomposition
  • breaking a complex problem into smaller problems and solving each individually
  • Abstraction
  • picking out important information and ignore the specifics that do not matter
  • Algorithmic Thinking
  • a logical way of getting from the problem to the solution. If the steps taken follow an algorithm then they can be reused and adapted to solve similar problems in the future
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is pseudocode

A

code that is not an actual programming language but follows a similar structure

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

Why is using pseudocode helpful (2)

A
  • don’t have to worry about syntax (finer details)
  • easy to convert into code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why should pseudocode not be vague

A

so that it can be converted into code easily

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

What are boxes with rounded corners used for in flow charts

A

terminals - beginning and end

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

What are parallelogram boxes used for in flow charts

A

anything that is taken out or put into the algorithm

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

What are rectangular boxes used for in flow charts

A

general instructions, processes and calculations

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

What are diamond boxes used for in flow charts

A

decisions, usually yes or no questions

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

What are arrows used for in flow charts

A

connects boxes and show the direction that should be followed

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

What are sub programs in flow charts

A

references to other flow charts

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

What is a sequence in a flow chart

A

a way to get from start to finish

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

What is a selection in a flow chart

A

when there are multiple ways to get from start to finish

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

What is an iteration

A

a loop that allows you to repeat a task

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

What are the two common types of search algorithm
- do the terms have to be sorted or not

A

Binary Search - the terms must be sorted
Linear Search - the terms can be sorted or unsorted

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

How does a binary search work

A
  • find the middle item ( (n + 1) / 2 )
  • If this is the item then stop
  • If not compare the terms - if it is after, then delete the first half and vice versa
  • repeat until the item is found
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How does a linear search work

A
  • look at first item
  • if this is the item then stop
  • else look at the next term
  • repeat until item is found
17
Q

What are the three common types of sorting algorithm

A
  • Insertion Sort
  • Bubble Sort
  • Merge Sort
18
Q

What are the steps to bubble sorting

A

1 - Look at first two items
2a - If they are in the right order, leave them.
2b - If they are in the wrong order, swap them
3 - Move to the next pair and repeat step 2

4 - Repeat step 3 until the end of the list (1 pass)

5 - Repeat 1-4 until there are no swaps in a pass

19
Q

What is a pass

A

when you reach the end of a list during a bubble sort

20
Q

What are the pros of using bubble sort (3)

A
  • simple algorithm that can be easily implemented on a computer
  • efficient way to check if a list is already in order
  • Doesn’t use much memory as all sorting is done using the original list
21
Q

What are the cons of using bubble sort (2)

A
  • inefficient way to sort a list
  • does not cope well with a large list of items
22
Q

What is the largest amount of comparisons that must be done when bubble sorting a list of ‘n’ items

A

n ( n - 1 ) / 2

23
Q

What two facts does merge sort capitalise on

A
  • small lists are easier to sort than large lists
  • It is easier to merge two sorted lists than two unsorted lists
24
Q

What are the steps to merge sorting

A

1 - Split the list in half (sub-lists)
2 - Keep repeating step 1 until all the lists have only 1 item
3 - Merge pairs of sub-lists so that each sub-list has twice as many items. Sort the items into the right order each time

4 - Repeat step 3 until all the sub-lists have formed one list

25
Q

In merge sorting, if a list has 9 items, how many items will be in each sub-list

A

4 in 1st
5 in 2nd

26
Q

What are the pros of using merge sort (2)

A
  • much more efficient and quicker than bubble sort and insertion sort for large lists
  • consistent running time regardless of how ordered the items are originally
27
Q

What are the cons of using merge sort (3)

A
  • slower than other algorithms for small lists
  • Even if the list is already sorted it still goes through the whole process
  • uses more memory than the other algorithms to create separate lists
28
Q

Which sorting algorithm is used by many programming languages such as Java, Python and Perl

A

merge sort

29
Q

How does insertion sort

A

1 - look at second item in a list
2 - Compare it to all items before it and insert the number into the right place
3 - Repeat step 2 for all remaining items until the last number has been inserted into the correct place

30
Q

What are the benefits and drawbacks of using a linear search over a binary search

A

BENEFITS - can be used on an unsorted list, much simpler

DRAWBACKS - much less efficient, poor with large lists,

31
Q

What are the pros of using insertion sort (5)

A
  • Easy to code
  • Copes well with small lists
  • does not require much additional memory
  • quick to add items to an already ordered list
  • quick at checking that a list is already sorted
32
Q

What is the main disadvantage of using insertion sort

A

doesn’t cope well with large lists ( n ( n + 1 ) / 2 )