9.3 Programming Flashcards
What is an algorithm?
A set of instructions the computer follows in sequence?
What is a sequence?
The order the program runs in.
What is a variable?
A location in memory that stores one piece of data. It can change as the program runs.
What is iteration?
When a block of code repeats/loops?
What are the two iteration loops used in Python
A for loop is count controlled, whereas a while loop is condition controlled.
Why is iteration used in a program?
To make the program more efficient, e.g. less lines of code so the program runs faster.
What does selection mean?
The user has a choice and the program has different routes to follow based on the choice
What are the key terms you would expect to see when reading a selection statement?
If/elif/else
What is the purpose of indentation
The code belongs to the specific selection statement
Write a print statement
print(‘A print statement’)
Write an input statement for to user entering their name
name = input(‘Enter your name: ‘)
How do the four types of malware get into the computer system:
Virus, worm, trojan and ransomware?
Virus - attaches
Worm - duplicates
Trojan - pretends
Ransomware - locks
What is a list?
A location in memory that stores multiple elements under one name
What is the difference between a variable and a list?
A variable can only store one element whereas a list stores multiple elements.
How is a list defined in Python?
listName = [] (square brackets)
What are the numbers in the binary number line?
128 64 32 16 8 4 2 1
When converted to denary, the binary number 1001 is:
8 + 1 = 9
When converted to binary the denary number 29 is:
29 - 16 = 13
13 - 8 = 5
5 - 4 = 1
11101
Describe how an insertion sort is carried out
An insertion sort is where the numbers are inserted into the correct position. It is the quickest kind of sorting.
Describe how a merge sort is carried out
A merge sort is where we divide and conquer - octo (8) - quads (4) - pairs (2) then sort pairs (2) - quads (4) - octo (8)
Describe how bubble sort is carried out.
In the bubble sort, you sort the pairs:
1st pass - start at 1st item
2nd pass - start at 2nd item
3rd pass - start at 1st item
4th pass - start at 2nd item etc….
Describe how an linear search is carried out
A linear search is where each item in the list is checked until the correct item is found. This can be a slow process if the list is long.