Section 4 - Algorithms Flashcards

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

what are the 3 key techniques for computational thinking?

A

decomposition
algorithmic thinking
abstraction

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

what is decomposition?

A

breaking down a complex problem into smaller problems and solving each 1 individually

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

what is abstraction?

A

picking important bits of information from a problem, ignoring the specific details that don’t matter

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

what is algorithmic thinking?

A

a logical way of getting from the problem to the solution. if the steps you take 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
5
Q

what does pseudocode do?

A

it should follow a similar structure to programming language

it should show an algorithms steps without going into to much detail.

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

what are the advantages of pseudocode?

A

it is quick to write and can be easily converted to any programming language

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

how to carry out a binary search?

A
  1. find middle item in list
  2. if the item is the target, stop the search
  3. if not, compare target to middle item.
    if it is too high get rid of 2nd half of list
    if too low get rid of 1st half of list
  4. repeat steps 1 - 3 until item is found or until the list is gone then tell the user it is not in the list
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what does a binary search do?

A

it finds items in an ordered list

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

what does a linear search do?

A

it checks each item in a list until it finds it or it has checked every item

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

how to carry out a linear search?

A
  1. look at 1st item and compare with target
  2. if this item is the target stop the search
  3. if not, look at next item
  4. repeat steps 2 - 3 until the item is found or every item has been checked
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what are the advantages of a binary search over a linear search?

A

it is more efficient
it generally takes less steps than linear
it is suitable for large lists

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

what are the advantages of a linear search over a binary search?

A

it is much simpler
it can be used on any type of list, it doesn’t have to be ordered
usually used on small lists because it is inefficient

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

what does a bubble sort do?

A

it is used to sort an unordered list, it is simple but can take a while

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

how to carry out a bubble sort?

A
  1. compare first 2 items in list
  2. if they are in the right order do nothing if not swap them
  3. move to next pair (2 and 3) repeat step 2
  4. repeat step 3 until the end of the list, the last item is now in the right place so don’t include it in the next “pass”
  5. repeat steps 1-4 until there is no swaps in a pass
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what are the pros of bubble sorts?

A

simple algorithm, ca be easily implemented on a computer
its an efficient way to check if a list is in order because only 1 pass needs to be done
it doesn’t use much memory because all the sorting is done using the original list

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

what are the cons of bubble sorts?

A

inefficient way of sorting a list

it doesn’t cope well with a large list

17
Q

how to conduct a merge sort?

A
  1. split list in half
  2. keep repeating step 1 for all sub-lists until they only contain 1 item
  3. merge pairs of sub-lists, and sort the items in the right order each time they are merged
  4. repeat step 3 until all the sub-lists are merged together
18
Q

what are the pros of a merge sort?

A

its faster and more efficient for large lists than other sorting algorithms
it has a consistent running time

19
Q

what are the cons of a merge sort?

A

slower than other sorts for small lists
it still does the whole process even if the list is already sorted
it uses more memory than other algorithms because it creates separate lists

20
Q

how to carry out an insertion sort?

A
  1. look at 2nd item
  2. compare it to all items in front of it and insert it into the right place
  3. repeat step 2 for all other items in the list after the previous one until the last item has been inserted
21
Q

what are the pros of the insertion sort?

A

its intuitive and can be easily coded
its good with small lists
it doesn’t use much memory because all sorting happens in the original list
its quick to add items to an ordered list
its quick at checking a list is already sorted

22
Q

what are the cons of an insertion sort?

A

it doesn’t do well with large lists