Algorithms Flashcards

(90 cards)

1
Q

Computers can be used to help…

A

solve problems. However, before a problem can be tackled, the problem itself, and the ways in which it could be solved, needs to be understood.

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

What does computational thinking allow us to do?

A

It allows us to take a complex problem, understand what the problem is and develop possible solutions. These solutions can then be presented in a way that a computer, a human, or both, can understand.

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

Three important elements of computational thinking…

A
  • decomposition
  • abstraction
  • algorithmic thinking
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Computational thinking involves…

A

taking a complex problem and breaking it down into a series of small, more manageable problems. Each of these smaller problems can then be looked at individually.

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

Algorithm

A

Identified simple steps to fix a complex problem that a computer carries out

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

Decomposition involves…

A

breaking down a complex problem or system into smaller parts that are more manageable and easier to understand.

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

If a problem is not decomposed…

A

It is much harder to solve

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

Algorithmic thinking is

A

the ability to create a step-by-step solution. It involves designing clear instructions (algorithms) that allow for a task to be solved

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

Why is algorithmic thinking important?

A

It helps:

  • to design clear instructions that computers and humans can easily follow
  • to spot patterns and repetition, which can make solutions more efficient
  • to test and improve solutions, ensuring that they work in all scenarios
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Algorithmic thinking involves other key computational skills, like…

A
  • logical reasoning
  • abstraction
  • decomposition
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Abstraction is…

A

the process of filtering out - essentially ignoring - the characteristics of problems that are not needed in order to concentrate on those that are needed. It is also the filtering out of specific details. From this, an idea of what is to be solved can be created.

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

Abstraction allows us to

A

create a general idea of what the problem is and how to solve it. The process instructs us to remove all specific detail and any patterns that will not help us solve our problem. This helps us form our idea of the problem. This idea is known as a ‘model’.

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

Casting

A

Converting one data type to another, for example converting an integer to a real number

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

Input sanitisation

A

Cleaning up data entered by removing non-standard characters

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

Binary search key points

A

• List must be sorted
• Divide and Conquer algorithm

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

Order this list with a binary search:

Ali Ben Carl Joe Ken Lara Mo

We are looking for the name Mo.

A

Ali Ben Carl Joe Ken Lara Mo
Examine the middle (Joe)
Joe != Mo
Mo is above Joe in the alphabet, so look at the ones above Joe
Ken Lara Mo
Lara is the middle, but Lara != Mo
However, Mo is above Lara in the alphabet
So look at any items above Lara.

There is only one item left, and it is Mo.

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

How many times do you have to make a comparison in a binary search with 16 items in the worst and best case scenario?

A

Best: 1 (if it’s in the middle)
Worst: 5 (n+1), where n is number of times we can halve 16

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

In a linear search…

A

You look at every item one by one, going through the list, until you find the first of the desired item and it will stop, not looking for more.

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

What is the max number of comparisons to be made in a linear search of 10 items?

A

10 (n)

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

How complex is a binary search compared to linear search, in terms of the algorithm and programming?

A

It is longer and more complex

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

If a binary search has no middle what do you do?

A

You pick the leftmost option

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

What if the item is not in the list?

A

It will not be found or error.

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

Advantages and disadvantages of binary search compared to linear

A

Advantages:
- it is a shorter process usually

Disadvantages:
- it is complex to code
- the list must be sorted

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

What symbol is: +

A

Add

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What symbol is: -
Subtract
26
What symbol is: /
Divide (it will be a decimal)
27
What symbol is: *
Multiply
28
What symbol is: ^
Exponent
29
What symbol is: MOD
Modulo (remainder)
30
What symbol is: DIV
Integer division
31
What is a variable?
A variable is a location in memory in which you can temporarily store a value such as a string or number
32
How to assign a variable
bob = …
33
Top tip about variable (hint:spaces)
Never leave a space between letters or numbers in the variable name. You will be PENALISED. Like: num 2 ❌ num2 ✅
34
Top tip about variable names
If they give you variable names in a question, such as X and Y, use them, don’t change them to like bob and bob1
35
Draw the line symbol in a flowchart
N/a
36
Draw the process symbol in a flowchart
N/a
37
Draw the input/output symbol in a flowchart
N/a
38
Draw the decision symbol in a flowchart
N/a
39
Draw the sub program symbol in a flowchart
N/a
40
Draw the terminal symbol in a flowchart
N/a
41
Because paper 1 and 2 let you use python/pseudo, which do you use
Python
42
When is the == used?
For if selections
43
When is the = used?
For assigning values to variables
44
Integers and strings are stored as…
Binary
45
Sub programs are used when
you wish to call another procedure or function
46
There are three basic programming constructs used to control the flow of a program:
• Sequence • Selection • Iteration (repetition)
47
Sequence
• A sequence is a series of steps which are completed one after the other • In a flow diagram they are shown as process, input or output symbols shown one after the other
48
Selection
• Selection is the ability to choose different paths through a program • In flowcharts, decision symbols are used for selection
49
Iteration
• Iteration means repeating a part of a program • It is also referred to as repeating or looping • In flowcharts, iteration is shown by using arrows that repeat a section of the flowchart • A decision will control whether more iterations are required
50
< is
Less than
51
<= is
Less than or equal to
52
> is
Greater than
53
>= is
Greater than or equal to
54
== is
Equal to
55
= is
Assignment
56
!= is
Non equal to
57
+ can also be used for
String concatenation
58
if elseif and else is
Branch depending on conditions
59
switch case default is
Branch depending on case
60
input() is
Get user input
61
print() is
Output to the user
62
for (variable name) = (range, with - in between) is
Repeat a set number of times
63
while is
Repeat while a condition is true
64
do until is
Do a loop until a condition is true
65
str() is
Convert to a string (but you don’t use this is pseudo)
66
int() is
Convert to an integer (not used in pseudo)
67
What do you put at the end of an if statement?
endif
68
What do you put at the end of a for loop?
next (variable)
69
What do you put at the end of a while loop?
endwhile
70
What do you put at the end of a do until loop?
until (condition)
71
An integer is
A whole number eg. 1475, 0, -5
72
A real is
A number with a decimal point eg. 56.75, 6.0, -2.456, 0.0
73
A Boolean is
Either TRUE or FALSE eg. TRUE, FALSE
74
A character is
A single alphabetic or numeric character eg. ‘a', 'K', '4', '@', '%'
75
A string is
A sequence of one or more characters eg. “Jo Hobson", "123"
76
A Boolean expression evaluates to…
True or false
77
The switch case is used…
if there are several possible options to be tested
78
Example of switch case
switch optionChosen: case 1: print("You chose option 1") case 2: print("You chose option 2") case 3: print("You chose option 3") default: print("Please select a valid choice") endswitch
79
Bubble sort explained
• Compares each pair of adjacent elements. • If they’re in the wrong order, swap them. • Repeats this process until no swaps are needed (list is sorted).
80
Bubble sort on 5, 3, 8, 4
• Compare 5 and 3 → swap → [3, 5, 8, 4] • Compare 5 and 8 → no swap → [3, 5, 8, 4] • Compare 8 and 4 → swap → [3, 5, 4, 8] • Next pass: [3, 4, 5, 8] (sorted).
81
Advantages and disadvantages of bubble sort
Advantages: • Very simple to understand and implement. • Good for small datasets. Disadvantages: • Very inefficient for large lists. • Performs unnecessary comparisons even if list is nearly sorted.
82
Insertion sort explanation
• Builds a sorted list one item at a time. • Takes the next element and “inserts” it into the correct position among the already-sorted items.
83
Do an insertion sort on 5, 3, 8, 4
• Start with [5] (already sorted). • Insert 3 → [3, 5]. • Insert 8 → [3, 5, 8]. • Insert 4 → [3, 4, 5, 8].
84
Why to be careful about the question for sorting algorithms?
They sometimes trick you by saying they want the numbers or strings in descending order
85
Advantages and disadvantages of insertion sort
Advantages: • Efficient for small lists and nearly sorted data (best case O(n)). • Simple and easy to code. • Works well for online data (you can sort as you receive items). Disadvantages: • Still slow on large lists. • Not as efficient as Merge Sort for big datasets.
86
Merge sort explanation
• Divide the list into halves until each sublist has one element. • Merge the sublists back together in sorted order.
87
Do a merge sort on 5, 3, 8, 4
• Split → [5, 3] and [8, 4]. • Split again → [5] [3] and [8] [4]. • Merge [5] and [3] → [3, 5]. • Merge [8] and [4] → [4, 8]. • Merge [3, 5] and [4, 8] → [3, 4, 5, 8].
88
Advantages and disadvantages of merge sort
Advantages: • Very efficient for large datasets. • Guarantees good performance regardless of initial order. • Works well with linked lists and external sorting (like sorting files on disk). Disadvantages: • Requires extra memory for merging. • More complex to implement compared to bubble or insertion sort.
89
Do some of worksheet 6 to practice trace tables
N/a
90
A syntax error is a…
Spelling error (not the same as a logic or rundown error)