Topic 1: Computational thinking Flashcards
Name two ways that abstraction is used in running peripheral software (2).
- Virtualization - This is the process of creating a virtual version of a peripheral device, such as a printer or scanner, which can be accessed and used by multiple users.
- Drivers - Drivers are pieces of software that allow the operating system to communicate with the peripheral device. They provide an abstraction layer between the hardware and the software, allowing the user to interact with the device without needing to understand the underlying hardware.
Give three benefits using sub-programs in your code (3).
- Improved code readability: Sub-programs can help to break down complex tasks into smaller, more manageable chunks, making it easier to read and understand the code.
- Reusability: Sub-programs can be used multiple times throughout a program, reducing the amount of code that needs to be written and maintained.
- Increased efficiency: By breaking down tasks into smaller sub-programs, the code can be optimized to run faster and more efficiently.
Describe Selection, Sequencing, Counting, repetition(iteration), totalling and they uses (5).
Selection: Process of choosing the most appropriate option from a given set of alternatives. It is used in computer programming to determine which instructions should be executed based on certain conditions. For example, a program may have an if-else statement that checks the value of a variable and then executes different instructions depending on the value.
Sequencing: Process of arranging instructions in a specific order. It is used in computer programming to ensure that instructions are executed in the correct order. For example, a program may have a loop that executes a set of instructions multiple times. The instructions must be arranged in the correct order for the loop to work properly.
Counting: Process of keeping track of the number of times an event occurs. It is used in computer programming to keep track of the number of times a loop is executed or the number of times a certain condition is met. For example, a program may have a loop that counts the number of times a certain value is found in an array.
Repetition (Iteration): Repetition (also known as iteration) is the process of repeating a set of instructions multiple times. It is used in computer programming to execute a set of instructions multiple times until a certain condition is met. For example, a program may have a loop that executes a set of instructions until a certain value is found in an array.
Totalling: Process of adding up a set of numbers. It is used in computer programming to calculate the total of a set of numbers. For example, a program may have a loop that adds up the values in an array and stores the total in a variable.
Give an example of a constants and an example of two-dimensiona data (2)
Constants (data/variable):
x = 9 (Integer/Real)
x = // (Char/String)
x = 9.56456 (Float)
Two-dimensional Data: A 2D array of student grades, a 2D graph of temperature over time
Can you name all the operators used for writing code with Python?
Addition: +
Subtraction: -
Division: /
Multiplication: *
Modulus: %
Integer Division: \
Exponentiation: ^
Relational Operators: >, <, >=, <=, ==, !
What is the purpose of using a trace table when debugging a program?
Trace tables are used to help debug a program by providing a visual representation of the program’s execution. They are used to keep track of the values of variables and other data as the program runs, and can help identify errors in the program’s logic.
Algorithmic example:
Step 1: Create a trace table with columns for each variable and other data used in the program.
Step 2: Run the program and record the values of the variables and other data in the trace table after each step.
Step 3: Compare the values in the trace table to the expected values.
Step 4: If the values do not match the expected values, identify the source of the error and make the necessary corrections.
Step 5: Repeat steps 2-4 until the program runs correctly.
Give an algorithmic example
of types of errors that can occur in programs
(syntax, logic, runtime) (3)
Syntax Error:
…
Input: print “Hello World
Output: Syntax Error
…
Logic Error:
…
a = ‘Hello world’
Input: print(a)
Output: Goodbye World
…
Runtime Error:
…
for i in range(len(i)):
While i == True:
print(i)
Input: print(i)
Output:
Runtime Error: Program
crashed due to insufficient memory
…
Name and describe four types of algorithms (4)
Bubble Sort:
Given an array of numbers [5, 2, 7, 1, 3], the bubble sort algorithm would sort the array in the following steps:
Step 1: [2, 5, 7, 1, 3]
Step 2: [2, 5, 1, 7, 3]
Step 3: [2, 1, 5, 7, 3]
Step 4: [1, 2, 5, 7, 3]
Step 5: [1, 2, 5, 3, 7]
Merge Sort:
Given an array of numbers [5, 2, 7, 1, 3], the merge sort algorithm would sort the array in the following steps:
Step 1: Split the array into two halves: [5, 2, 7] and [1, 3]
Step 2: Sort each half: [2, 5, 7] and [1, 3]
Step 3: Merge the two sorted halves: [1, 2, 3, 5, 7]
Linear Search:
Given an array of numbers [5, 2, 7, 1, 3], the linear search algorithm would search for the number 7 in the following steps:
Step 1: Start at the beginning of the array and compare each element to the search value (7).
Step 2: If the element is not equal to the search value, move to the next element.
Step 3: If the element is equal to the search value, return the index of the element.
Binary Search:
Given an array of numbers [1, 2, 3, 5, 7], the binary search algorithm would search for the number 7 in the following steps:
Step 1: Find the middle element of the array (3).
Step 2: Compare the middle element to the search value (7).
Step 3: If the middle element is not equal to the search value, determine if the search value is greater or less than the middle element.
Step 4: If the search value is greater than the middle element, repeat the process on the upper half of the array.
Step 5: If the search value is less than the middle element, repeat the process on the lower half of the array.
Step 6: If the element is equal to the search
Which sorting algorithm is the most efficient bubble sort, merge sort, linear search or binary search?
The most efficient sorting algorithm is Merge Sort. It has a time complexity of O(n log n), which is much better than Bubble Sort (O(n^2)) and Linear Search (O(n)). Binary Search is not a sorting algorithm, but a searching algorithm with a time complexity of O(log n).
Demonstrate these logical operators AND, OR, NOT in truth tables and there outcomes
“””
Truth Table 1
Input A | Input B | Input C |
Output
AND | OR | NOT |
0 | 0 | 0 | 0
0 | 0 | 1 | 0
0 | 1 | 0 | 0
0 | 1 | 1 | 0
1 | 0 | 0 | 0
1 | 0 | 1 | 1
1 | 1 | 0 | 1
1 | 1 | 1 | 0
Truth Table 2
Input A | Input B | Input C | Output
AND | OR | NOT |
0 | 0 | 0 | 0
0 | 0 | 1 | 1
0 | 1 | 0 | 0
0 | 1 | 1 | 1
1 | 0 | 0 | 0
1 | 0 | 1 | 0
1 | 1 | 0 | 1
1 | 1 | 1 | 0