Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) on “Co-ordinate Compression”.
1. What is co-ordinate compression? Answer: a 2. What is the need for co-ordinate compression? Answer: c 3. What is the output for the following code? a) 4 3 0 1 2 Answer: a 4. What will be the time complexity of given code? a) O(n) Answer: b 5. What is the auxiliary space complexity of the given code? a) O(1) 6. What will be the output of the following code? a) 0 2 3 4 Answer: b 7. What is the time complexity of the following code? a) O(n) 8. What will be the auxiliary space complexity of the following code? a) O(n) Answer: a 9. Co-ordinate compression reduces the number of squares in a graph. Answer: a 10. Co-ordinate compression can only be applied in a co-ordinate system problem. Answer: b
a) process of reassigning co-ordinates to remove gaps
b) inserting gaps in a co-ordinate system
c) removing redundant co-ordinates
d) adding extra gaps
Clarification: Co-ordinate compression is the process of reassigning co-ordinates in order to remove gaps. This helps in improving efficiency of a solution.
a) for improving time complexity
b) for improving space complexity
c) for improving both time and space complexity
d) for making code simpler
Clarification:Co-ordinate compression is the process of reassigning co-ordinates in order to remove gaps. This helps in improving both time and space complexity of a solution.#include
b) 1 2 3 4 5
c) 5 4 1 2 3
d) 0 1 2 3 4
Clarification: The given code converts the elements of the input array. They are replaced with their respective position number in the sorted array.#include
b) O(n log n)
c) O(n2)
d) O(log n)
Clarification: The time complexity of the given code will be governed by the time complexity of the sorting algorithm used. As this code uses in built sorting of C++ so it will take O(n log n) time.#include
b) O(n)
c) O(log n)
d) O(n log n)
Answer: b
Clarification: The given code uses an auxiliary space of O(n). It is used by a vector which pairs each element of the array with their respective index number of the original array.#include
b) 1 3 0 2
c) 2 4 1 3
d) 1 2 3 4
Clarification: The given code converts the elements of input array. They are replaced with their respective position number in the sorted array.#include
b) O(1)
c) O(n log n)
d) O(n2)
Answer: c
Clarification: The time complexity of the given code will be governed by the time complexity of the sorting algorithm used. As this code uses inbuilt sorting of C++ so it will take O(n log n) time.#include
b) O(1)
c) O(log n)
d) O(n log n)
Clarification: The given code uses an auxiliary space of O(n). It is used by a vector which pairs each element of the array with their respective index number of the original array.
a) true
b) false
View Answer
Clarification: The idea behind co-ordinate compression is to reduce the number of squares in a graph by converting them into rectangles of viable size. This reduces the time complexity of traversal.
a) true
b) false
View Answer
Clarification: Co-ordinate compression technique can be applied where such optimization is suitable. It does not require to co-ordinate system problem only.