WorksheetsReview Quiz
Total questions: 24
Worksheet time: 12mins
What is a stack?
a. a type of map
b. a FIFO (First In, First Out) data structure
c. a LIFO (Last In, First Out) data structure
d. None of the above
Which function adds an element to the top of a stack?
a. push()
b. pop()
c. top()
d. insert()
What does 'count()' do in a map?
a. Counts the number of maps
b. Checks if a key exists
c. Counts the number of values
d. Returns the size of the map
Which of the following has the BEST time complexity for searching?
a. Linear Search
b. Binary Search
c. Selection Sort
d. Insertion Sort
In recursion, what is the base case?
a. The case that repeats
b. The case that calls itself
c. The initial call to the function
d. The case that ends the recursion
How do you access the value in a map using a key?
map[key]
map.value(key)
map.get(key)
map.find(key)
What is the Big O time complexity of a binary search?
a. O(n)
b. O(nlogn)
c. O(n^2)
d. O(2^n)
Which pointer operation is used to access the value at a memory address?
&
[]
*
->
What is the time complexity of selection sort?
O(n)
O(nlogn)
O(n^2)
O(2^n)
What does the keyword 'throw' do in C++?
a. Declares an exception
b. Catches an exception
c. Raises an exception
d. Non of the above
Which of the following correctly describes Big O notation?
a. It measures the best-case complexity for an algorithm
b. It measures the worst-case complexity for an algorithm
c. It measures the average-case complexity for an algorithm
d. It measures the exact number of operations for an algorithm
In a linked list, what does each node contain?
Data and a pointer to the next node
Only data
Data and a pointer to the previous node
A pointer to the previous and next node
What is the purpose of 'assert' in debugging?
a. To catch exceptions
b. To print debugging information
c. To test assumptions and stopping the program if they're false
d. To handle exceptions that were caught
How do you declare a pointer to an integer in C++?
int ptr
int* ptr
int &ptr
int[] ptr
What does the keyword 'new' do in C++?
Allocates memory
Deallocates memory
Initializes a variable
Creates an object
Which of the following is an example of a runtime error in C++?
a. Missing semicolon
b. Type in variable name
c. Division by zero
d. Syntax error
What is the time complexity of searching for an element in a linked list?
a. O(1)
b. O(logn)
c. O(n)
d. O(n^2)
What is the difference between a recursive function and a iterative function?
A recursive function uses arrays, an iterative function uses arrays
A recursive function calls itself, an iterative function uses loops
A recursive function uses loops, an iterative function uses two loops
There is no difference
Why would you not want to use a binary search?
It is the slowest search algorithm
It takes a lot of memory to use
It takes too long to write
It requires a sorted data set
What does the keyword 'delete' do in C++?
Allocates memory
Deallocates memory
Initializes a variable
Creates an object
What is the advantage of using a linked list over an array?
Faster sorting
It's simpler to write
Dynamic sizing
Accessing elements is faster
What is the main drawback of using recursion?
High memory usage
Increased time complexity
Cannot solve complex problems
There is no drawback
How is dynamic programming primarily used?
a. Solving problems by recursion
b. Solving problems by iteration
c. Solving problems by splitting and combining sub-problems
d. Solving problems by multithreading
What is the difference between a class and a struct?
Classes cannot have member functions
Structs cannot have member functions
Classes can inherit, structs cannot
By default, members of a class are private, members of a struct are public
