02 Section 4 - Algorithms Flashcards

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

What are the three 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

Define decomposition:

A

Breaking a complex problem down into smaller problems and solving each one individually

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

Define abstraction:

A

Picking out the important bits of information from the 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

Define Algorithmic thinking:

A

A logical way of getting from the problem to the solution. If the steps you take to solve a problem 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 is pseudocode?

A

Not an actual programming language but it should follow a similar structure and roughly read like one
-shows the algorithm’s steps, without worrying about the specific syntax of a programming language

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

What are the features of pseudocode?

A
  • quick to write
  • can be easily converted into any programming language
  • different ways to write pseudocode, priority is that the person reading it can follow and understand it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are aspects and rules to follow for pseudocode?

A
  • VARIABLES -are named at the start
  • INDENTATION -makes it more readable
  • USE CAPITAL LETTERS FOR COMMAND AND KEY WORDS (e.g. PRINT, IF, ELSE, INPUT…)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the symbol used for start/stop for flow diagrams?

A

The beginning and end of the algorithm are put into boxes with rounded corners

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

What is the symbol used for inputs/outputs for flow diagrams?

A

Anything that is put into or taken out of the algorithm goes into a parallelogram box`

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

What is the symbol used for processes for flow diagrams?

A

General instructions, processes and calculations go in rectangular boxes

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

What is the symbol used for decisions for flow diagrams?

A

Decisions, often a ‘yes’ or ‘no’ question, are put in diamond boxes

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

What is the symbol used for sub routines for flow diagrams?

A

Sub routines are like sub programs, they reference other flow diagrams
-a rectangle with extra lines at either end (splitting it up into a small vertical rectangle, a large horizontal rectangle then another small vertical rectangle)

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

What is the symbol used for showing directions for flow diagrams?

A

Arrows connect boxes and show the direction you should follow. Some boxes might have multiple arrows coming in or going out of them

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

What are the different ways you can write algorithms?

A

Pseudocode

Flow diagrams

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

What are the three ways which a program can be written or features that they can contain?

A

Sequence
Selection
Iteration

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

What is sequence?

A

When there is only one way from start to end

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

What is selection?

A

When there are multiple ways to get from start to stop

18
Q

What is iteration?

A

When a program contains a loop that allows you to repeat a task

19
Q

What does a binary search do?

A

A binary search looks for items in an ordered list

20
Q

How do you find the middle item of a list?

A

(n + 1) / 2

-in a list of n items

21
Q

What is a binary search algorithm?

A

1) find the middle item in an ordered list
2) if this is the item you’re looking for, stop the search you have found it
3) if not, compare the item you’re looking for to the middle item. If it comes before the middle item get rid of the second half of the list, if it comes after get rid of the first half of the list
4) you’ll be left with a list half the size of the original list, repeat steps 1-3 on the smaller list until you find the item you are looking for

22
Q

What does a linear search do?

A

A linear search checks every item in an unordered list to see if it’s the correct one, it stops either when it finds the item or has checked every item

23
Q

What is a linear search algorithm?

A

1) look at the first item in the unordered list
2) if this is the item you’re looking for, stop the search
3) if not look at the next item in the list
4) repeat steps 2-3 until you find the item that you’re looking for or you have checked every item

24
Q

What are the pros and cons of linear search?

A

PROS
-simpler
-can be used on any type of list (no order needed)
-easy to code
CONS
-less efficient (worst case scenario, checking every item in list)
-not suitable for larger lists

25
Q

What are the pros and cons of binary search?

A
PROS
-more efficient (takes fewer steps to find what you're looking for)
-suitable for larger lists
CONS
-list has to be ordered
-harder to code
26
Q

What searching algorithms are there?

A

Binary search

Linear search

27
Q

What sorting algorithms are there?

A

Bubble sort
Merge sort
Insertion sort

28
Q

What is bubble sort?

A

Bubble sort compare pairs of items and is used to sort unordered lists of items

29
Q

What is a bubble sort algorithm?

A

1) look at the first two items in a list
2) if they are in the right order, leave them. if they are in the wrong order, swap them
3) move onto the next pair of items(2nd and 3rd items) and repeat step 2
4) repeat step 3 until you get to the end of the list (this is called ONE PASS), the last item will now be in the correct place, so don’t include it in the next pass
5) repeat steps 1-4 until there are no swaps in a pass

30
Q

What are the pros of bubble sort?

A
  • simple algorithm that can be easily implemented on a computer
  • efficient way to check if a list is already in order, a list of n items,only have to do one pass of n-1 comparisons
  • doesn’t use much memory, as all sorting is done using the original list
31
Q

What are the cons of bubble sort?

A
  • an inefficient way to sort a list, for a list of n items the worst case scenario is (n(n+1))/2 comparisons
  • due to being inefficient, it does not cope with large lists of items well
32
Q

What is merge sort?

A

Merge sort is a divide and conquer algorithm that takes advantage of the fact the smaller lists are easier to sort and it is easier to merge two ordered lists than two unordered lists

33
Q

What is a merge sort algorithm?

A

1) split the list in half(small list are called sub-lists), the second sub-list should start with the middle item
2) repeat step 1 until all sub-lists only contain one item
3) merge pairs of sub-lists, and sort them into the right order each time you merge the sub-lists
4) repeat step 3 until all the sub-lists are together

34
Q

What are examples of where merge sort is used?

A

Due to its efficiency it is used by many programming languages such as Java, Python and Perl as the primary sorting algorithm

35
Q

What are the pros of merge sort?

A
  • much more efficient and quicker the bubble or insertion for large lists
  • very consistent running time regardless of how ordered the items in the original list are
36
Q

What are the cons of merge sort?

A
  • slower than other algorithms for small lists
  • even if a list is already sorted it still goes through the whole splitting and merging process
  • uses more memory than the other sorting algorithms in order to create separate lists
37
Q

What is insertion sort?

A

A sorting algorithm that takes each item in turn and puts it in the right place using the first item in the list as a starting point

38
Q

What is a insertion sort algorithm?

A

1) look at the 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 until you have the last number inserted into the correct place

39
Q

What are the pros of insertion sort?

A
  • intuitive way of sorting things and can be easily coded
  • copes well with small lists
  • doesn’t require much additional memory (as all sorting is done on the original list)
  • very quick to add items to an already sorted list
  • quick at checking that a list is already sorted
40
Q

What are the cons of insertion sort?

A

-doesn’t cope very well with large lists
(best case scenario - (n-1) comparisons)
(worst case scenario - (n(n-1))/2 comparisons)