Q. If a graph has V vertices and E edges, what is the space complexity of Dijkstra's algorithm?
A.
O(V)
B.
O(E)
C.
O(V + E)
D.
O(V^2)
Show solution
Solution
The space complexity of Dijkstra's algorithm is O(V + E) due to the storage of the graph's adjacency list and the distance array.
Correct Answer:
C
— O(V + E)
Learn More →
Q. If a graph has V vertices and E edges, what is the space complexity of Dijkstra's algorithm using an adjacency list?
A.
O(V)
B.
O(E)
C.
O(V + E)
D.
O(V^2)
Show solution
Solution
The space complexity of Dijkstra's algorithm using an adjacency list is O(V + E) due to the storage of vertices and edges.
Correct Answer:
C
— O(V + E)
Learn More →
Q. If a graph has V vertices and E edges, what is the worst-case time complexity of Dijkstra's algorithm using an adjacency matrix?
A.
O(V^2)
B.
O(E log V)
C.
O(V + E)
D.
O(V^3)
Show solution
Solution
When using an adjacency matrix, the worst-case time complexity of Dijkstra's algorithm is O(V^2) because it requires checking all vertices for the minimum distance.
Correct Answer:
A
— O(V^2)
Learn More →
Q. If a graph is represented using an adjacency matrix, what is the time complexity of BFS?
A.
O(V + E)
B.
O(V^2)
C.
O(E)
D.
O(V log V)
Show solution
Solution
For an adjacency matrix representation, BFS has a time complexity of O(V^2) due to the need to check all possible edges.
Correct Answer:
B
— O(V^2)
Learn More →
Q. If a host has an IP address of 192.168.1.10 and a subnet mask of 255.255.255.0, what is its network address?
A.
192.168.1.0
B.
192.168.1.10
C.
192.168.0.0
D.
192.168.1.255
Show solution
Solution
The network address is obtained by performing a bitwise AND between the IP address and the subnet mask: 192.168.1.10 AND 255.255.255.0 = 192.168.1.0.
Correct Answer:
A
— 192.168.1.0
Learn More →
Q. If a network has a subnet mask of /22, how many subnets can be created from a /16 network?
Show solution
Solution
A /22 subnet mask allows for 4 subnets to be created from a /16 network (2^(22-16) = 2^6 = 4).
Correct Answer:
A
— 4
Learn More →
Q. If a network has a subnet mask of 255.255.255.128, how many subnets can be created?
Show solution
Solution
A subnet mask of 255.255.255.128 allows for 2 subnets, as it uses 1 bit for subnetting (2^1 = 2).
Correct Answer:
B
— 4
Learn More →
Q. If a network has the IP address 192.168.1.0/24, what is the broadcast address?
A.
192.168.1.255
B.
192.168.1.0
C.
192.168.1.1
D.
192.168.1.254
Show solution
Solution
The broadcast address for the subnet 192.168.1.0/24 is 192.168.1.255, which is the highest address in the subnet.
Correct Answer:
A
— 192.168.1.255
Learn More →
Q. If a queue is implemented using two stacks, what is the time complexity of dequeue operation in the worst case?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
In the worst case, the dequeue operation can take O(n) time because all elements may need to be transferred from one stack to another.
Correct Answer:
B
— O(n)
Learn More →
Q. If a sorted array has 16 elements, how many comparisons will binary search make in the worst case?
Show solution
Solution
In the worst case, binary search will make log2(16) = 4 comparisons.
Correct Answer:
B
— 5
Learn More →
Q. If a stack has a maximum size of 100 and you attempt to push 101 elements onto it, what will happen?
A.
The 101st element will be pushed successfully.
B.
An error will occur due to stack overflow.
C.
The stack will automatically resize.
D.
The stack will discard the oldest element.
Show solution
Solution
Attempting to push more elements than the maximum size of the stack will result in a stack overflow error.
Correct Answer:
B
— An error will occur due to stack overflow.
Learn More →
Q. If a stack has a maximum size of 5, what will happen if we try to push a 6th element?
A.
The element will be added
B.
The stack will overflow
C.
The stack will shrink
D.
The operation will be ignored
Show solution
Solution
If we try to push a 6th element onto a full stack, it will overflow.
Correct Answer:
B
— The stack will overflow
Learn More →
Q. If a stack is implemented using a linked list, what is the time complexity of the 'pop' operation?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
The 'pop' operation in a stack implemented using a linked list is done in constant time, O(1), as it involves removing the head node.
Correct Answer:
A
— O(1)
Learn More →
Q. If a stack is implemented using an array, what is the time complexity of resizing the array when it is full?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
Resizing the array involves creating a new array and copying all elements, which takes O(n) time.
Correct Answer:
B
— O(n)
Learn More →
Q. If a stack is used to evaluate an expression in postfix notation, what is the time complexity of the evaluation?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
The time complexity of evaluating an expression in postfix notation using a stack is O(n), where n is the number of tokens in the expression.
Correct Answer:
B
— O(n)
Learn More →
Q. If an array contains 32 elements, how many iterations will binary search take in the worst case?
Show solution
Solution
For an array of 32 elements, the worst-case number of iterations is log2(32) = 5.
Correct Answer:
A
— 4
Learn More →
Q. If an array has 16 elements, how many comparisons will binary search make in the worst case?
Show solution
Solution
In the worst case, binary search will make at most log2(16) = 4 comparisons.
Correct Answer:
B
— 5
Learn More →
Q. If an array is already sorted, what is the time complexity of Quick Sort?
A.
O(n)
B.
O(n log n)
C.
O(n^2)
D.
O(log n)
Show solution
Solution
In the worst case, which occurs when the array is already sorted, Quick Sort has a time complexity of O(n^2).
Correct Answer:
C
— O(n^2)
Learn More →
Q. If an array is sorted in descending order, can binary search still be used?
A.
Yes, with modifications
B.
No, it cannot be used
C.
Yes, without modifications
D.
Only for specific cases
Show solution
Solution
Binary search can be used on a descending sorted array, but the comparison logic must be adjusted.
Correct Answer:
A
— Yes, with modifications
Learn More →
Q. If the array has 16 elements, how many comparisons will binary search make in the worst case?
Show solution
Solution
In the worst case, binary search will make log2(16) = 4 comparisons.
Correct Answer:
B
— 5
Learn More →
Q. If the array is sorted in descending order, can binary search still be applied?
A.
Yes, with modifications
B.
No, it cannot be applied
C.
Yes, without any changes
D.
Only for specific cases
Show solution
Solution
Binary search can be applied to a descending sorted array with modifications to the comparison logic.
Correct Answer:
A
— Yes, with modifications
Learn More →
Q. If the array is [1, 2, 3, 4, 5] and the target is 3, what will be the mid index during the first iteration?
Show solution
Solution
The mid index is calculated as (0 + 4) // 2 = 2, which corresponds to the value 3.
Correct Answer:
C
— 2
Learn More →
Q. If the array is [1, 2, 3, 4, 5] and the target is 3, what will be the mid index during the first iteration of binary search?
Show solution
Solution
In the first iteration, mid is calculated as (0 + 4) // 2 = 2, which corresponds to the value 3.
Correct Answer:
C
— 2
Learn More →
Q. If the array is [1, 2, 3, 4, 5] and we search for 6, what will be the final result of binary search?
Show solution
Solution
Since 6 is not in the array, binary search will return -1.
Correct Answer:
B
— -1
Learn More →
Q. If the array is [2, 3, 4, 10, 40] and we are searching for 10, what is the first mid index calculated in binary search?
Show solution
Solution
The mid index is calculated as (0 + 4) / 2 = 2, which points to the value 4.
Correct Answer:
C
— 3
Learn More →
Q. If the binary search algorithm is implemented recursively, what is the space complexity due to recursion?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
Solution
The space complexity of a recursive binary search is O(log n) due to the call stack.
Correct Answer:
B
— O(log n)
Learn More →
Q. If the distance between two clusters in hierarchical clustering is defined as the maximum distance between points in the clusters, what linkage method is being used?
A.
Single linkage
B.
Complete linkage
C.
Average linkage
D.
Centroid linkage
Show solution
Solution
The method that defines the distance between two clusters as the maximum distance between points in the clusters is called complete linkage.
Correct Answer:
B
— Complete linkage
Learn More →
Q. If the size of the array is doubled, how does the time complexity of binary search change?
A.
It doubles
B.
It remains the same
C.
It becomes O(n)
D.
It becomes O(n log n)
Show solution
Solution
The time complexity of binary search is O(log n), which does not change with the size of the array.
Correct Answer:
B
— It remains the same
Learn More →
Q. If the target value is not present in a sorted array, what will binary search return?
A.
The index of the closest value
B.
The index of the first element
C.
The index of the last element
D.
-1 or a sentinel value
Show solution
Solution
If the target value is not found, binary search typically returns -1 or a sentinel value indicating absence.
Correct Answer:
D
— -1 or a sentinel value
Learn More →
Q. If the target value is not present in the array, what will binary search return?
A.
The index of the closest value
B.
The index of the first element
C.
The index of the last element
D.
-1
Show solution
Solution
If the target value is not found, binary search typically returns -1 to indicate absence.
Correct Answer:
D
— -1
Learn More →
Showing 121 to 150 of 3237 (108 Pages)