WorksheetsY12 CS PC1
Total questions: 104
Worksheet time: 1hrs 3mins
How do I import the pygame library?
import pygame
pygame.init()
surface = pygame.display.set_mode((400,300))
pygame.display.flip()
How do I initialize the pygame?
import pygame
pygame.init()
surface = pygame.display.set_mode((400,300))
pygame.display.flip()
How do I initialize the surface?
import pygame
pygame.init()
surface = pygame.display.set_mode((400,300))
pygame.display.flip()
How do I update the screen?
import pygame
pygame.init()
surface = pygame.display.set_mode((400,300))
pygame.display.flip()
What does display.flip() do?
will update the contents of the entire display
allows to update a portion of the screen, instead of the entire area of the screen
What does display.update() do?
will update the contents of the entire display
allows to update a portion of the screen, instead of the entire area of the screen
How can I check for an event if a user has pushed any event in the queue?
run = False
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = True
run = True
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
for event in pygame.event.pos():
Draw a Rectangle
surface = pygame.display.set_mode((400,300))
pygame.draw.rect(surface, color, [30, 30, 60, 60])
pygame.draw.line(surface, color, [20, 50], [180, 50], 3)
pygame.draw.circle(surface, color, [300, 300], 200, 3)
Draw a Circle
pygame.draw.arc(surface, color, [50, 50, 200, 200], 0, pi, 2)
pygame.draw.rect(surface, color, [30, 30, 60, 60])
pygame.draw.circle(surface, color, [20, 50], [180, 50], 3)
pygame.draw.circle(surface, color, [300, 300], 200, 3)
Draw a Polygon
pygame.draw.arc(surface, color, [50, 50, 200, 200], 0, pi, 2)
pygame.draw.rect(surface, color, [30, 30, 60, 60])
pygame.draw.polygon(surface, color, [[300, 100], [100,500], [500,500]], width = 3)
pygame.draw.polygon(surface, color, [300, 300], 200, 3)
What does the following code do?
screen.blit(surface1, (0,0))
place the surface on the screen
create a surface
update the screen
check whether the circle pos. reached at the end
What does the following code do?
surface1 = pygame.Surface((300, 500))
place the surface on the screen
create a surface
update the screen
check whether the circle pos. reached at the end
What does the following code do?
if x >= 500: x = 0
x += 3
surface.fill((255, 255, 255))
circle = pygame.draw.circle(surface, (0, 0, 255), (x, y), 15)
pygame.display.update()
move the circle to right
create a surface
set initial position of the circle
check whether the circle pos. reached at the end
What does the following code do?
color = (random.randint(0,255), random.randint(0,255), random.randint(0,255))
choose a random color
fill the surface with random color
change the background color according to the key pressed
What does the following code do?
clock = pygame.time.Clock()
set framerate
check whether the circle pos. reached at the end
create a clock to track the amount time
Set image background
bg1 = pygame.image.load("back1.jpg")
surface.blit(bg1, (0, 0))
bg1 = pygame.image.load("back1.jpg")
surface = pygame.display.set_mode((800,500))
bg1 = pygame.image.load("back1.jpg")
pygame.display.set_caption("Animation")
Mouse events
MOUSEBUTTONDOWN
MOUSEBUTTONUP
MOUSEMOTION
MOUSEEVENT
What is this function following the code?
event.button = 3
pressing the left button
pressing the right button
scrolling forward
scrolling back
What is this function following the code?
event.button = 4
pressing the left button
pressing the right button
scrolling forward
scrolling back
Allows you to get a tuple of two coordinates of the cursor location (x, y).
event.pos
event.button
event.get
event.type
left, middle, right = pygame.mouse.get_pressed()
if left:
print("Left Mouse Key is being pressed")
The above code, as long as the mouse is being held down, it will keep printing
Returns the coordinates of the mouse cursor on the screen
The above code changes the type of cursor that appears on the screen
Draw how ready you are to write a SAU.

What is a class (in python)?
A user-defined prototype for an object that defines a set of attributes that characterize any object of this. The attributes are data members and methods, accessed via dot notation.
A special kind of function that is defined in a class definition.
The assignment of more than one behavior to a particular function. The operation performed varies by the types of objects or arguments involved.
the system of ordering a society in which people are divided into sets based on perceived social or economic status.
What does function overloading mean (in python)?
An individual object of a certain class. An object obj that belongs to a class Circle, for example, is an instance of the class Circle.
A user-defined prototype for an object that defines a set of attributes that characterize any object of the class. The attributes are data members (class variables and instance variables) and methods, accessed via dot notation.
the function overloads and kills the computer
The assignment of more than one behavior to a particular function. The operation performed varies by the types of objects or arguments involved.
What does inheritance mean in python?
The transfer of the characteristics of a class to other classes that are derived from it.
A variable that is defined inside a method and belongs only to the current instance of a class
The creation of an instance of a class.
It is what you sometimes get when a relative passes away
What is an instance in python?
A special kind of function that is defined in a class definition.
The creation of an instance of a class.
An individual object of a certain class. An object obj that belongs to a class Circle, for example, is an instance of the class Circle.
A moment in time
What is instantiation in python?
The creation of an instance of a class.
The transfer of the characteristics of a class to other classes that are derived from it.
A variable that is defined inside a method and belongs only to the current instance of a class.
A unique instance of a data structure that's defined by its class. An object comprises both data members (class variables and instance variables) and methods.
What is a method in python?
a way of doing something
a special kind of function that is defined in a class definition
the creation of an instance of a class
orderliness of thought or behavior; systematic planning or action
What is an object in python?
A unique instance of a data structure that's defined by its class. An object comprises both data members (class variables and instance variables) and methods.
A special kind of function that is defined in a class definition.
The assignment of more than one function to a particular operator.
An individual object of a certain class. An object obj that belongs to a class Circle, for example, is an instance of the class Circle.
What term is used to describe data passed into a function?
Variable
Loop
Constant
Parameter
How many parent nodes are there?
4
5
6
7
How many leaf nodes are there?
4
5
6
7
Which of the following is TRUE about this tree?
This tree is a binary tree only
This tree is a binary search tree
This is a non-binary tree
What traversal gives out the letters in alphabetical order?
In-order traversal
Pre-order traversal
Post-order traversal
What is the order of nodes traversed in a pre-order traversal of this tree?
A, B, C, D, E, F, G, H, I, J
E, B, A, C, D, G, F, I, H, J
A, D, C, B, F, H, J, I, G, E
B, A, C, D, G, F, I, H, J, E
What is the order of nodes traversed in a post-order traversal of this tree?
A, B, C, D, E, F, G, H, I, J
E, B, A, C, D, G, F, I, H, J
A, D, C, B, F, H, J, I, G, E
B, A, C, D, G, F, I, H, J, E
Traversing this tree, the arithmetic expression obtained is a×b + c÷d.
What type of traversal was performed?
In-order
Pre-order
Post-order
Traversing this tree, the arithmetic expression obtained is + ×ab ÷ cd. What type of traversal was performed?
In-order
Pre-order
Post-order
Which of the following statements is true?
A graph is also a tree.
A tree can have both directed and undirected edges.
A tree can have a connection between two child nodes.
A tree is a special case of a connected graph with only undirected edges and no cycles.
Which of the following is TRUE about a binary search tree?
(Select All That Apply)
Each parent node has a maximum of two child nodes.
The value in a left child node is less than the value in the parent node.
The value in the right child node is greater than the value in the parent node.
Which of following data structure is more appropriate for
implementing quick sort iteratively?
Deque
Priority queue
Stack
Queue
Which of the following data structure is linear type?
Binary Tree
Stack
Graph
Trees
The complexity of Binary search algorithm is
O(n)
O(n log n)
O(n2)
O(log n)
The complexity of Bubble sort algorithm is
O(n2)
O(n)
O(log n)
O(n log n)
What will the output of the following code snippet?
void solve() {
int a[] = {1, 2, 3, 4, 5};
int sum = 0;
for(int i = 0; i < 5; i++) {
if(i % 2 == 0) {
sum += *(a + i);
}
else {
sum -= *(a + i);
}
}
cout << sum << endl;
}
15
syntax error
3
2
What are the components of a node in a linked list?
Only data
Data and a pointer
Only a pointer
Data and an index
What is a linked list?
A static data structure using only arrays
A type of function in computer programming
A dynamic abstract data structure implemented as an array and pointers
A basic variable type in programming
What does the 'start' pointer in a linked list do?
Points to the middle node of the list
Identifies the first node in the list
Shows the last node in the list
Indicates the size of the list
What happens to the memory location when an item is deleted from a dynamic list?
It is duplicated
It is freed up and returned to the heap
It is permanently deleted
It is archived for future use
Which operation is not typically supported efficiently by linked lists?
Adding an element at the beginning of the list.
Accessing an element at a specific position.
Removing an element from the end of the list.
Traversing the elements in the list.
Which list operation is used to remove and return the last item in the list?
pop()
remove(item)
len()
index(item)
What is the purpose of the "count(item)" operation in a list?
Add a new item at position pos
Return the position of item
Return the number of occurrences of item in list
Test for empty list
How does the "isEmpty()" function operate on a list?
Removes an item from a specific position
Tests if the list has no items
Adds an item to the list
Returns the total number of items in the list
Is a function like 'isFull' necessary when implementing a queue using a list?
Yes, to prevent adding more items than the list can handle.
No, because the list can dynamically expand.
Yes, but only in fixed-size data structures.
No, 'isFull' is irrelevant in dynamic structures like lists.
What does the function "isFull()" return?
True if the queue is empty.
False if the queue is not full.
True if the queue has reached its maximum size.
False if the queue has items.
What does the function "isEmpty()" check in the context of the queue?
If the queue has reached its maximum size.
If the queue has no items.
If the queue can accept more items.
If the queue is being processed.
What is the primary purpose of the insertion sort algorithm?
To quickly sort large data sets
To insert each item into its correct position in a data set one at a time
To create a new list from an existing one
To compare each item with all other items
At what index does the outer for loop start in the insertion sort algorithm?
1
0
2
-1
What happens if the items are out of order in the insertion sort?
The items are moved up one space
The items are swapped
The algorithm stops
The algorithm restarts
What is stored in the 'current' variable in the insertion sort algorithm?
The initial unsorted list
The index of the next item
The value of the item being sorted
The final sorted list
What condition must be met to enter the inner while loop in the insertion sort?
There are no more items to sort
The list is fully sorted
Index is greater than zero and the previous item is greater than the current item
The current item is the smallest
What is the role of 'index 2' in the insertion sort algorithm?
It holds the value of the current item
It tracks the current position in the list
It determines when to exit the inner while loop
It stores the length of the list
What type of data structure is initially used to store the items in the insertion sort example?
Queue
Stack
Array
Linked list
What is a major inefficiency of the insertion sort when dealing with large data sets?
The need for recursive calls
Having to update pointers
Requiring additional memory space
Having to move all items to insert a single item
What alternative data structure could potentially improve the efficiency of insertion sort?
Array
Linked list
Binary tree
Graph
What does the final step of the outer for loop in the insertion sort do?
It shuffles the items randomly
It resets the loop counter
It checks if the list is sorted
It places the current item into its final location
What is the primary function of a bubble sort algorithm?
To reduce the size of a data set
To merge two sorted lists into one
To find the maximum value in a list
To order an unordered list of items by comparing and swapping them if necessary
Which of the following best describes the efficiency of the bubble sort algorithm?
Least efficient sorting algorithm
Efficient for data sets that are already partially sorted
Efficient only for large data sets
Most efficient sorting algorithm
What condition must be met for the bubble sort's main while loop to continue executing?
The list is empty
All items are already sorted
At least one swap has occurred
No swaps are needed
In bubble sort, what happens when two items are out of order?
They are left as is
They are immediately moved to the correct position
They are swapped
A new list is created
What is the purpose of the 'swapped' boolean variable in the bubble sort algorithm?
To track the number of iterations
To count the number of swaps
To indicate whether a swap has occurred
To stop the algorithm
How does the bubble sort algorithm determine when the sorting process is complete?
When the list has been iterated through once
When the list is in ascending order
When no more swaps can be made
When all elements are equal
What is the initial setting of the 'swapped' variable at the start of the bubble sort algorithm?
Undefined
Null
True
False
Which of the following is NOT a step in the bubble sort algorithm?
Swapping items if they are out of order
Repeating the process until no swaps are needed
Comparing each item with the next one
Selecting the smallest item and moving it to the start
What does the bubble sort algorithm do each time through the while loop?
Leaves 'n' unchanged
Decreases the value of 'n' by one
Increases the value of 'n' by one
Resets 'n' to the length of the list
Which of the following is a correct statement about the bubble sort algorithm?
It is ideal for very large data sets due to its efficiency
It is often used because it is easy to implement and understand
It does not require any comparisons between list items
It sorts items in random order to increase unpredictability
What is meant by the term 'Computational Thinking'?
Steps that can be taken to find the best solution to a complex problem
Behaving like a robot
Thinking in binary
A logical way of getting from the problem to a solution
What is meant by the term 'Abstraction'?
Picking out important bits of information and ignoring the bits that don't matter
Dealing with something as a concept rather than a physical entity
Painting
Breaking a complex problem down into smaller problems
What is meant by the term 'Decomposition'?
Picking out important bits of information and ignoring the bits that don't matter
The process of an organism breaking down over time
A logical way of getting from the problem to the solution
Breaking a complex problem down into smaller problems
What is meant by the term 'Algorithmic Thinking'?
Picking out important bits of information and ignoring the bits that don't matter
Thinking in hexadecimal
A logical way of getting from the problem to the solution
Instructions are used to solve a problem
What is meant by the term 'Algorithm'?
Breaking a complex problem down into smaller problems
It is a type of programming language
A logical way of getting from the problem to the solution
A set of instructions used to solve a problem
Select the 2 most important pieces of information a software developer should know when writing a console-based application for a company
The purpose of the application
How much time the developer gets for lunch
What programming language/framework should be used
Which graphics card the client devices will use
What are the 3 key techniques for Computational Thinking?
Decomposition
Abstraction
Algorithmic Thinking
Programming
Which of the following is an example of computational thinking?
Writing in binary
Programming
Compiling a list of instructions to solve a complex task
Creating new hardware
