unit 1 - fundamentals of algorithms Flashcards

1
Q

what is an algorithm?

A

a set of instructions for solving a problem or completing a task

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

what is abstraction?

A

removing unnecessary detail from a problem so that you can focus on the essentials

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

what is decomposition

A

breaking down a large problem into smaller sub-tasks, which can then be further broken down until each small task is manage

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

arithmetic operators

A

+ add
- subtract
/ divide
* multiply
^ exponent
MOD division with a remainder
DIV integer division

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

what is a variable?

A

is a location in memory where you can temporarily store text or numbers

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

what are two tools to plan and write algorithms?

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

what are the three programming constructs?

A
  • sequence
  • selection
  • iteration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

data types

A

integer - a whole number
real - a number with a decimal point
boolean - can only be TRUE or FALSE
character - a single alphabetic or numeric character
- string - one or more characters enclosed in quote marks

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

boolean operators

A

> greater than
< less than
= greater than or equal to
<= less than or equal to
= equal (== in python)
/= not equal (!= in python)

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

what is sequence?

A

the statements are executed in the order that they are written

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

what is selection?

A
  • an IF statement in a selection statement
  • the next statement to be executed depends on whether the condition tested is TRUE or FALSE
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what is pseudocode?

A
  • a structured english for describing algorithms
  • allows the designer to focus on the logic on the algorithm without being distracted by the syntax
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

how to assign a value to a variable in pseudocode?

A

total <- 0
cost <- adult * child
counter <- counter + 1

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

how to write an input/output in pseudocode?

A

firstname <- USERINPUT
OUTPUT (“enter a value”)

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

what does iteration mean?

A
  • repetition of a certain block of code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what are the three different types of iteration statements?

A
  • FOR…ENDFOR
  • WHILE…ENDWHILE
  • REPEAT…UNTIL
17
Q

what is the FOR…ENDFOR loop used for?

A

when you want to execute the loop a specific number of times

18
Q

what is the WHILE…ENDWHILE loop used for?

A

when you want to execute the loop while a certain condition is true
the condition is checked at the start of the loop

19
Q

what is the REPEAT…UNTIL loop used for?

A
  • when you want to execute the loop until a certain condition is true
  • the condition is tested at the end of the loop
  • usually has an IF statement to test the condition at the end
20
Q

what is a flowchart?

A

means of defining an algorithm using shapes and arrows. each shape has a specific meaning that corresponds to an action/decision

21
Q

flowchart shapes and what they signify

A

tablet > marks the start and end of the code
diamond > a decision (asks if a condition is true or not)
parallelogram > input/outputs
rectangle/box > process (each contains a single instruction)

22
Q

what is a trace table?

A

a table used to keep track of variables that change throughout the algorithm

23
Q

what is searching?

A

determining whether a specific item of data exists within a data structure

24
Q

what is a linear search?

A

a search algorithm that begins at one end of the data and checks each item methodically if and until the required item is found or the end of the structure is reached

25
Q

what are the two types of search algorithms?

A
  • linear search
  • binary search
26
Q

what is binary search?

A

a search algorithm that begins in the middle of the data structure and eliminates half the structure with each pass
- the data must be sorted in ascending order before the search can take place

27
Q

linear search vs binary search

A

linear search:
+ functions on unsorted data
- is more time consuming than a binary search
- only really works on smaller data structures

binary:
+ far more time efficient
- data has to be sorted first

28
Q

what is sorting?

A

putting the data into order (ascending or descending)

29
Q

what is bubble sort?

A
  • each item in a list is compared to the one next to it, and if it is greater then they swap places
  • the initial pass doesn’t do anything
  • at the end of the first pass through the list, the largest item is at the end of the list
  • this is repeated until the items have been sorted
30
Q

what is merge sort?

A
  • divide the unsorted list into n sublists, each containing one element
  • repeatedly merge two sublists at a time to produce new sorted sublists until there is only one sublist remaining - the sorted list
31
Q

bubble sort vs merge sort

A

bubble sort:
+ straightforward to program
+ doesn’t use much extra memory space whilst the sort is in progress
- often slow and inefficient compared to merge sort
- cannot sort long data structures

merge sort:
+ much more efficient in terms of time
- more complex to program
- requires a lot of memory space whilst it runs (quite bad with large data structures)