WorksheetsExploring Data Structures
Total questions: 110
Worksheet time: 2hrs 45mins
What is a data structure?
A data structure is a programming language.
A data structure is a type of computer program.
A data structure is a specialized format for organizing, processing, and storing data.
A data structure is a method for writing code.
Name three types of linear data structures.
Arrays, Linked Lists, Queues
Stacks
Trees
Graphs
What is the difference between an array and a linked list?
An array can only store integers, while a linked list can store any data type.
An array allows for fast access and fixed size, while a linked list allows for dynamic size and easier insertions/deletions.
An array is always larger than a linked list.
A linked list has a fixed size and allows for fast access.
Explain the concept of a stack and its operations.
A stack can only hold integer values and has no operations.
A stack is a FIFO data structure with operations: enqueue and dequeue.
A stack is a LIFO data structure with operations: push, pop, peek, and isEmpty.
A stack is a data structure that allows random access to elements.
What is a queue and how does it differ from a stack?
A queue is a FIFO data structure, while a stack is a LIFO data structure.
A queue is a LIFO data structure, while a stack is a FIFO data structure.
A queue is a data structure that only allows insertion at the front.
A queue allows random access, while a stack does not.
Define a binary tree and its properties.
A binary tree is a data structure where each node has at most two children.
A binary tree is a type of graph that can have cycles.
A binary tree is a linear data structure with a single parent node.
A binary tree is a data structure where each node can have any number of children.
What is a hash table and how does it work?
A hash table is a physical table used in restaurants for serving food.
A hash table is a type of database used for storing large amounts of data.
A hash table is a data structure that uses a hash function to map keys to values for efficient data retrieval.
A hash table is a programming language used for web development.
Explain the concept of a graph and its types.
A graph is a type of chart used for statistical data.
Graphs only consist of points without any connections.
A graph is a collection of vertices connected by edges, with types including directed, undirected, weighted, unweighted, cyclic, and acyclic.
A graph is a linear sequence of numbers without any structure.
What are the advantages of using a linked list over an array?
Slower access time for elements
Fixed size allocation
Advantages of linked lists over arrays include dynamic size, efficient insertions/deletions, and ease of implementing complex data structures.
More memory overhead for storage
Describe the time complexity of accessing an element in an array.
O(n)
O(1)
O(log n)
O(n^2)
Which sorting algorithm makes one swap per pass (possibly swapping an element with itself)?
Selection Sort
Bubble Sort
Insertion Sort
Which sorting algorithm may make multiple swaps per pass?
Bubble Sort
Selection Sort
Insertion Sort
Which sorting algorithm shifts elements instead of swapping elements if needed in each pass.
Bubble Sort
Selection Sort
Insertion Sort
The following lists represent 3 passes of a sorting algorithm. Which algorithm is being used to sort the list?
4 8 6 2 5 7
4 8 6 2 5 7
4 6 8 2 5 7
Bubble Sort
Selection Sort
Insertion Sort
We are sorting the following list in ascending order:
1 4 2 9 3 8 5
What does the list look like after one pass of the bubble sort algorithm.
1 2 4 3 8 5 9
1 4 2 5 3 8 9
4 2 9 3 8 5 1
Time complexity of bubble sort in best case is
a) θ (n)
b) θ (nlogn)
c) θ (n2)
d) θ (n(logn) 2)
Which of these algorithms sorts items by first splitting the list of items down into smaller and smaller groups?
Bubble sort
Merge sort
Linear search
Binary search
What algorithm does this image represent?
Bubble sort
Merge sort
Linear search
Binary search
Which type of sort algorithm is this?
Insertion
Merge
Bubble
Partition a list A[] into two non-empty parts.
in left part the values should be:
A [ ] <= pivot
A [ ] > pivot
A[] >= pivot
A [ ] < pivot
Partition a list A[] into two non-empty parts.
in right part the values should be:
A [ ] > pivot
A [ ] >= pivot
A [ ] < pivot
A [ ] <= pivot
Which algorithm matches this description: "a sorting algorithm that repeatedly partitions the input into low and high parts (each part unsorted), and then recursively sorts each of those parts."
Selection Sort
Insertion Sort
Shell Sort
Quicksort
Which of the following is a max-heap?
Consider a binary max-heap implemented using an array. Which one of the following array represents a binary max-heap?
25,12,16,13,10,8,14
25,12,16,10,13,8,14
25,14,16,13,10,8,12
25,14,12,13,10,8,16
The elements 32, 15, 20, 30, 12, 25, 16 are inserted one by one in the given order into a Max Heap. The resultant Max Heap is.
Consider a max heap, represented by the array: 40, 30, 20, 10, 15, 16, 17, 8, 4. Now consider that a value 35 is inserted into this heap. After insertion, the new heap is
40, 30, 20, 10, 15, 16, 17, 8, 4, 35
40, 35, 20, 10, 30, 16, 17, 8, 4, 15
40, 30, 20, 10, 35, 16, 17, 8, 4, 15
40, 35, 20, 10, 15, 16, 17, 8, 4, 30
Given a binary-max heap. The elements are stored in an arrays as 25, 14, 16, 13, 10, 8, 12. What is the content of the array after two delete operations?
14,13,8,12,10
14,12,13,10,8
14,13,12,8,10
14,13,12,10,8
The 2 properties of a min heap are _____.
Tree must be full.
Tree must be complete.
Node values are always smaller than their children's values.
Node values are always greater than their children's values.
How many swaps are made in the min heap when inserting the value 18?
0
1
2
3
When removing the root from a min heap, what is the first step?
Replace the root with the next smallest value from the tree
Replace the root with the leaf furthest to the left on the bottom level of the tree
Replace the root with the leaf furthest to the right on the bottom level of the tree
Replace the root with the smallest of its children
When adding a value to a min heap, the first step is to ______.
Add the new node at the next open leaf.
Replace the root's value with the new value.
Replace the roots smallest child with the new value.
Add the new node as far right as possible on the bottom level of the tree.
Select the best description to explain what a linear search algorithm is.
Put the elements in order, check each item in turn.
Put the elements in order, compare with the middle value, split the list in order and repeat.
Elements do not need to be in order, check each item in turn.
Elements do not need to be in order, compare to the middle value, split the list in order and repeat
Select the best description to explain what a binary search algorithm is.
Put the elements in order, check each item in turn.
Put the elements in order, compare with the middle value, split the list in order and repeat.
Elements do not need to be in order, check each item in turn.
Elements do not need to be in order, compare to the middle value, split the list in order and repeat
A linear search is to be performed on the list:
12 6 8 1 3
How many comparisons would it take to find number 1?
1
2
3
4
A binary search is to be performed on the list:
3 5 9 10 23
How many comparisons would it take to find number 9?
0-1
2-3
4-5
I can't find the number 9
A binary search is to be performed on the list:
1 5 10 13 48 68 100 101
How many comparisons would it take to find number 101?
0-1
1-2
3-4
4-5
Describe an advantage of a binary search algorithm
Data does not need to be in order.
Performs well over large ordered lists.
Can only work on an ordered list. If unordered must use a linear search.
Slow with large data sets.
int nums[ ] =
{2, 3, 5, 8, 9, 11};
How would you access the fourth element in nums
nums[8]
nums[3]
nums(4)
nums(3)
Which of the following is NOT a Type of Data Structures?
Arrays
Tables
Stacks
Trees
A FIFO structure implemented as a ring where the front and rear pointers can wrap around the end of the start of the array.
Linear Queue
Circular Queue
Priority Queue
LIFO stands for
List of Outputs
Last in First Out
First in Last Out
None of them
Act of adding values into a stack is called
Popping
Polling
Pushing
None
If the elements “A”, “B”, “C” and “D” are placed in a stack and are deleted one at a time, in what order will they be removed?
ABCD
DCBA
DCAB
ABDC
In some languages, arrays are also called ___
groups or arrows
roots or leaves
lists or vectors
lines or strings
A data type that can be used to group items of possibly different types into a single type is called ___
a root
a struct
a tree
a pointer
A flexible data structure that can store many nodes is called ___
a tree
a linked list
a pointer
a queue
When linked lists are used as stacks, what kind of behaviour is implemented?
First-In First-Out, or FIFO
First-In Last-Out, or FILO
Last-In Last-Out, or LILO
Last-In First-Out, or LIFO
In a tree data structure, the top most node is called ___
the peak
the apex
the crown
the root
In a tree data structure, any nodes that hang from other nodes are called ___
branched nodes
leaf nodes
children nodes
daughter nodes
In a tree data structure, any nodes that have no children (where the tree ends) are called ___
boundary nodes
leaf nodes
orphan nodes
terminal nodes
What is the value of the ROOT node in this Tree?
35
24
42
20
Root
data structure similar to a graph, with no loops.
an object in a graph also known as a vertex
a join of relationship between nodes - also know as an arc
the starting node in a rooted tree structure from which all other nodes branch off./
Tree
data structure similar to a graph, with no loops.
an object in a graph also known as a vertex
a join of relationship between nodes - also know as an arc
the starting node in a rooted tree structure from which all other nodes branch off./
How many leaf are there in the tree?
1
3
4
7
Which Time and Space Complexity uses the O(n2) notation?
Quadratic
Linear
Exponential
Logarithmic
What is the time complexity of this code
int a = 0, i = N;
while (i > 0)
{
a += i;
i /= 2;
}
O(N)
O(Sqrt(N))
O(N / 2)
O(log N)
The complexity of Binary search algorithm is
O(n)
O(log n)
O(n2)
O(n log n)
What is the time complexity of following code:
int a = 0;
for (i = 0; i < N; i++) {
for (j = N; j > i; j--) {
a = a + i + j;
}
}
O(N)
O(N*log(N))
O(N * Sqrt(N))
O(N*N)
What is the time complexity of following code:
int i, j, k = 0;
for (i = n / 2; i <= n; i++) {
for (j = 2; j <= n; j = j * 2) {
k = k + n / 2;
}
}
O(n)
O(nLogn)
O(n^2)
O(n^2Logn)
A linear function takes the form
f(n) = an + b
f(n) = an2 +bn + c
f(n) = alog2n
f(n) = a + b
Find the slowest algorithm:
O (n)
O (n^2)
O (n!)
O (2^n)
The number of executions grows extremely quickly as the size of the input increases
Exponential Time
Linear Time
Polynomial Time
Constant Time
What does it mean when we say that an algorithm X is asymptotically more efficient than Y?
X will be a better choice for all inputs
X will be a better choice for all inputs except possibly small inputs
X will be a better choice for all inputs except possibly large inputs
Y will be a better choice for small inputs
What is the worst case running time of the above pseudo code?
O(n)
O(n log n)
O(n2)
O(n3)
asymptotic notations represents
space complexity of algo
time complexity of algo
both a and b
none of the above
Big
Ω defineslower bound
upper bound
middle bound
none of the above
What is the worst case complexity of selection sort?
O(n log n)
O(log n)
O(n)
O(n2)
The stack is also known as?
Last in first out
First in last out
First in first out
.none of these
define the name of the process in which items are added at one end and removed from another side?
stack
Queue
List
Tree
Define the value of r in a circular queue?
r=r+1
r=(r+1)%[QUEUE_SIZE=1]
r=(r+1)% QUEUE_SIZE
r=(r-1)% QUEUE_SIZE
What is the worst case complexity of bubble sort?
O(nlogn)
O(logn)
O(n)
O(n2)
The measure of the longest amount of time possibly taken to complete an algorithm is expressed as __.
Little-O
Little-Omega
Big-Omega
Big-O
___ of an algorithm is the amount of time required for it to execute.
Time complexity
Space complexity
Compiling time
Best case
___ is the maximum amount of time an algorithm takes to execute a specific set of inputs.
Running time
Average case time complexity
Worst case time complexity
Best case time complexity
Which one of the following helps in calculating the longest amount of time taken for the completion of the algorithm?
Theta notation
Big-Oh notation
Omega notation
Time complexity
Which method is practical to perform a single search in an unsorted list of elements?
Sequential search
Bubble sort
Horspool’s method of string matching
Brute force method of string matching
Which of the following best describes the useful criterion for comparing the efficiency of algorithms?
Time
Memory
Both of the above
None of the above
What does it mean when we say that an algorithm X is asymptotically more efficient than Y?
X will always be a better choice for small inputs
X will always be a better choice for large inputs
Y will always be a better choice for small inputs
X will always be a better choice for all inputs
If for an algorithm time complexity is given by O(1) then complexityof it is:
constant
polynomial
exponential
none of the mentioned
If for an algorithm time complexity is given by O(n) then complexityof it is:
constant
linear
exponential
none of the mentioned
What is the time complexity of following code:
int a = 0, i = N;
while (i > 0)
{
a += i;
i /= 2;
}
O(N)
O(Sqrt(N))
O(N / 2)
O(log N)
The asymptotic upper-bound of f(n)=20n2+100n+2 is O(n2)
True
False
The asymptotic upper-bound of f(n)=2n+2n is O(n2)
True
False
If for an algorithm time complexity is given by O(1) then complexity of it is
constant
polynomial
exponential
none of the mentioned
If for an algorithm time complexity is given by O(n) then complexity of it is
constant
linear
exponential
none of the mentioned
What is the time complexity of following code
int a = 0, i = N;
while (i > 0) {
a + = i;
i / = 2;
}
O(N)
O(Sqrt(N))
O(N / 2)
O(log N)
The linear/sequential search method to search an element in an array has the complexity of BigO(?)
n
n-1
n^2
n logn
Indicate exponential time complexity in terms of big-O notation
O (n)
O (n^2)
O (2^n)
O (log n)
Find the slowest time complexity
O (n)
O (n^2)
O (n!)
O (2^n)
Which notation is consistent for every execution?
O (n)
O (n^2)
O (1)
O (2^n)
Which notation grows in proportion to the size of the input
O (n)
O (n^2)
O (1)
O (2^n)
Which notation would you usually use for a nested loop?
O (n)
O (n^2)
O (1)
O (2^n)
The number of executions grows extremely quickly as the size of the input increases
Exponential Time
Linear Time
Polynomial Time
Constant Time
The number of executions remains the same regardless of the input size
Exponential Time
Linear Time
Polynomial Time
Constant Time
The number of executions grows quickly by the input being multiplied by the input
Exponential Time
Linear Time
Polynomial Time
Constant Time
For every element, you are doing a constant number of operations, such as comparing each element to a known value.
Quadratic
Linear
Logarithmic
Constant
Exponential
What is the correct Big O notation for an algorithm where the number of operations (steps) can be expressed as:
4n3 +3n log2n + 273 n is the size of the input.
O(n2)
O(3n)
O(log2n)
O(273)
O(n3)
What is the big-Oh runtime of A()?
O(nlogn)
O(n2)
O(n)
O(10⋅n)
What is true for f(n)=logn and g(n)=n ?
f(n)=O(g(n))
f(n)=θ(g(n))
f(n)=Ω(g(n))
What is the maximum number of comparisons that a binary search will apply for an array of length 30.
30
15
5
3
2
What is the big-Oh runtime of B()?
O(n2)
O(n3)
O(30⋅n)
O(n)
Which of these is true for f(n)=5n3+7n+13 and g(n) = n5 ?
f(n)=θ(g(n))
f(n)=Ω(g(n))
f(n)=O(g(n))
What is the big-Oh runtime of C(n)?
O(10)
O(n)
O(2n)
O(logn)
Which of the following is the time complexity of insertion sort?
O(n2)
O(logn)
O(n)
O(nlogn)
Which is true for f(n)=2n and g(n)=n! ?
f(n)=O(g(n))
f(n)=θ(g(n))
f(n)=Ω(g(n))
What is the big-Oh runtime of D(n)?
O(n⋅logn)
O(n2)
O(logn)
O(2n)
