• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Pro Programming

Professional way of Programming: Learn C, C++, Java, Python, Dot Net, Android the professional way

  • Home
  • C MCQs
  • C/C++ Programs
  • Java Programs
  • C#
  • Python
  • MySQL
  • Topics
    • Arrays
    • Strings
    • Link Lists
    • Trees
    • Shapes
  • Projects
  • Articles
  • Games
You are here: Home / c programming / Co-ordinate Compression Multiple Choice Questions and Answers (MCQs)

Co-ordinate Compression Multiple Choice Questions and Answers (MCQs)

Leave a Comment


This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on “Co-ordinate Compression”.

1. What is co-ordinate compression?
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
View Answer

Answer: a
Explanation: Co-ordinate compression is the process of reassigning co-ordinates in order to remove gaps. This helps in improving efficiency of a solution.

2. What is the need for co-ordinate compression?
a) for improving time complexity
b) for improving space complexity
c) for improving both time and space complexity
d) for making code simpler
View Answer

Answer: c
Explanation: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.

3. What is the output for the following code?

#include <bits/stdc++.h> 
using namespace std;  
void convert(int a[], int n) 
{ 	
	vector <pair<int, int> > vec;	
	for (int i = 0; i < n; i++) 
		vec.push_back(make_pair(a[i], i)); 
	sort(vec.begin(), vec.end()); 	
	for (int i=0; i<n; i++) 
		a[vec[i].second] = i; 
} 
void printArr(int a[], int n) 
{ 
	for (int i=0; i<n; i++) 
		cout << a[i] << " "; 
} 
int main() 
{ 
	int arr[] = {10,8,2,5,7}; 
	int n = sizeof(arr)/sizeof(arr[0]);  
	convert(arr , n); 
   	printArr(arr, n); 
	return 0; 
}

a) 4 3 0 1 2
b) 1 2 3 4 5
c) 5 4 1 2 3
d) 0 1 2 3 4
View Answer

Answer: a
Explanation: The given code converts the elements of the input array. They are replaced with their respective position number in the sorted array.

4. What will be the time complexity of given code?

#include <bits/stdc++.h> 
using namespace std;  
void convert(int a[], int n) 
{ 	
	vector <pair<int, int> > vec; 	
	for (int i = 0; i < n; i++) 
		vec.push_back(make_pair(a[i], i)); 	
	sort(vec.begin(), vec.end()); 	
	for (int i=0; i<n; i++) 
		a[vec[i].second] = i; 
} 
void printArr(int a[], int n) 
{ 
	for (int i=0; i<n; i++) 
		cout << a[i] << " "; 
} 
int main() 
{ 
	int arr[] = {10,8,2,5,7}; 
	int n = sizeof(arr)/sizeof(arr[0]); 	
	convert(arr , n); 
   	printArr(arr, n); 
	return 0; 
}

a) O(n)
b) O(n log n)
c) O(n2)
d) O(log n)
View Answer

Answer: b
Explanation: 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.

5. What is the auxiliary space complexity of the given code?

#include <bits/stdc++.h> 
using namespace std;  
void convert(int a[], int n) 
{ 	
	vector <pair<int, int> > vec; 	
	for (int i = 0; i < n; i++) 
		vec.push_back(make_pair(a[i], i)); 	
	sort(vec.begin(), vec.end()); 
	for (int i=0; i<n; i++) 
		a[vec[i].second] = i; 
} 
void printArr(int a[], int n) 
{ 
	for (int i=0; i<n; i++) 
		cout << a[i] << " "; 
} 
int main() 
{ 
	int arr[] = {10,8,2,5,7}; 
	int n = sizeof(arr)/sizeof(arr[0]);  
	convert(arr , n); 
   	printArr(arr, n); 
	return 0; 
}

a) O(1)
b) O(n)
c) O(log n)
d) O(n log n)
View Answer

Answer: b
Explanation: 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.

6. What will be the output of the following code?

#include <bits/stdc++.h> 
using namespace std; 
void convert(int arr[], int n) 
{ 
	int temp[n]; 
	memcpy(temp, arr, n*sizeof(int)); 
	sort(temp, temp + n); 	
        unordered_map<int, int> map; 	
	int sort_index = 0; 
	for (int i = 0; i < n; i++) 
		map[temp[i]] = sort_index++; 	
	for (int i = 0; i < n; i++) 
		arr[i] = map[arr[i]]; 
} 
void printArr(int arr[], int n) 
{ 
	for (int i=0; i<n; i++) 
		cout << arr[i] << " "; 
} 
int main() 
{ 
	int arr[] = {3,5,2,4}; 
	int n = sizeof(arr)/sizeof(arr[0]); 
	convert(arr , n); 	
	printArr(arr, n); 
	return 0; 
}

a) 0 2 3 4
b) 1 3 0 2
c) 2 4 1 3
d) 1 2 3 4
View Answer

Answer: b
Explanation: The given code converts the elements of input array. They are replaced with their respective position number in the sorted array.

7. What is the time complexity of the following code?

#include <bits/stdc++.h> 
using namespace std; 
void convert(int arr[], int n) 
{ 	
	int temp[n]; 
	memcpy(temp, arr, n*sizeof(int)); 
	sort(temp, temp + n); 	
        unordered_map<int, int> map; 	
	int sort_index = 0; 
	for (int i = 0; i < n; i++) 
		map[temp[i]] = sort_index++; 	
	for (int i = 0; i < n; i++) 
		arr[i] = map[arr[i]]; 
} 
void printArr(int arr[], int n) 
{ 
	for (int i=0; i<n; i++) 
		cout << arr[i] << " "; 
} 
int main() 
{ 
	int arr[] = {10, 20, 15, 12, 11, 50}; 
	int n = sizeof(arr)/sizeof(arr[0]); 
	convert(arr , n); 	
	printArr(arr, n); 
	return 0; 
}

a) O(n)
b) O(1)
c) O(n log n)
d) O(n2)
View Answer

Answer: c
Explanation: 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.

8. What will be the auxiliary space complexity of the following code?
a) O(n)
b) O(1)
c) O(log n)
d) O(n log n)
View Answer

Answer: a
Explanation: 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.

9. Co-ordinate compression reduces the number of squares in a graph.
a) true
b) false
View Answer

Answer: a
Explanation: 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.

10. Co-ordinate compression can only be applied in a co-ordinate system problem
a) true
b) false
View Answer

Answer: b
Explanation: Co-ordinate compression technique can be applied where such optimization is suitable. It does not require to co-ordinate system problem only.

Sanfoundry Global Education & Learning Series – Data Structures & Algorithms.

To practice all areas of Data Structures & Algorithms, here is complete set of 1000+ Multiple Choice Questions and Answers.



Source link

Filed Under: c programming Tagged With: •   Array-Recursion-Min-Max, •   Array-Recursion-Search - 1, •   Array-Recursion-Search - 2, •   Assembly Line Scheduling, •   Balanced Partition, •   Best First Search, •   Binary Search Iterative, •   Binary Tree Sort, •   Bipartite Graph, •   Bipartite Graphs Properties, •   Bogosort, •   Boolean Parenthesizations, •   Bottom Up Mergesort, •   Breadth First Search, •   Catalan Number, •   Chan's Algorithm, •   Closest Pair Problem, •   Co-ordinate Compression, •   Coin Change Problem, •   Comb Sort, •   Complete Bipartite Graph, •   Continuous Subarray - 1, •   Continuous Subarray - 2, •   Counting Sort, •   Decimal-Binary Conversion, •   Depth First Search, •   Dice Throw Problem, •   Digits Sum - Recursion, •   Dijkstra's Algorithm, •   Dynamic Programming, •   Edit Distance Problem, •   Eight Queens Problem, •   Euclid's Algorithm, •   Factorial using Recursion, •   Fibonacci Term, •   Fibonacci using Recursion, •   First-in First-out Algorithm, •   Fraction Knapsack Problem, •   GCD & LCM Recursion - 1, •   GCD & LCM Recursion - 2, •   Generating Combinations, •   Generating Partitions, •   Generating Permutations, •   Generating Subsets, •   Gnome Sort, •   Hamiltonian Path Problem, •   Hamming Code, •   Heapsort - 1, •   Heapsort - 2, •   Huffman Code, •   In-place Merge Sort, •   Inclusion Principle, •   Insertion Sort - 1, •   Insertion Sort - 2, •   Introsort, •   Jump Search, •   Kruskal's Algorithm, •   Linear Search Iterative, •   Linear Search Recursive, •   Linkedlist-Length-Recursion, •   Linkedlist-Recursion-Search, •   Lists-Recursion-Min-Max, •   Longest Subsequence, •   LSD Radix Sort, •   Matrix Multiplication, •   Max Bipartite Matching, •   Maximum Flow Problem, •   Minimum Cut, •   Minimum Number of Jumps, •   Minimum Spanning Tree, •   Monoalphabetic Cipher, •   Morse Code - 1, •   Morse Code - 2, •   N Queens Problem, •   Natural No's - Recursion, •   Non-recursive DFS, •   NP Complexity Classes, •   Number Power - Recursion, •   Odd-Even Sort, •   Optimal Page Replacement, •   Palindrome Min Insertions, •   Palindromic Subsequence, •   Pancake Sort, •   Permutation Sort, •   Polyalphabetic Cipher, •   Prim's Algorithm, •   Quick Search Algorithm, •   Quickhull, •   Quickselect, •   Quicksort - 1, •   Quicksort - 2, •   Quicksort - 3, •   Quicksort using Sampling, •   Rabin-Karp Algorithm, •   Rectangle Sum in 2D Matrix, •   Recursive Selection Sort, •   Rod Cutting, •   Selection Sort, •   Shell Sort - 1, •   Shell Sort - 2, •   Sleep Sort, •   Square Root Decomposition, •   Stable Marriage Problem, •   Stack Reversal - Recursion, •   Strassen's Algorithm, •   String Length - Recursion, •   String Reversal - Recursion, •   Timsort, •   Topological Sorting, •   Towers of Hanoi - Recursion, •   Uniform Binary Search, •   Vigenere Cipher, •   Wagner-Fischer Algorithm, 0 - 1 Knapsack Problem, 1000 C Questions & Answers, 1000 Hadoop Questions, 1000 Java Questions & Answers, 1000 Linux Questions & Answers, 1000 PHP Questions & Answers, 1000 Python Questions, About, About Us, Advanced C Training, Aeronautical, Aerospace, Agriculture, Algorithm & Programming Books, All Stream Best Books, All Stream Internships, All Stream Questions & Answers, Backtracking, Bangalore Training, BCA, Bellman–Ford Algorithm, Biotechnology, Bogosort Multiple Choice Questions and Answers (MCQs), Bottom-Up Mergesort Multiple Choice Questions and Answers (MCQs), Bubble Sort, Chemical, Chemical Engineering Books, Chemical Internships, Civil, Civil Engineering Books, Civil Internships, Cloud Computing Questions, Comb Sort Multiple Choice Questions and Answers (MCQs), Computer Science Books, Computer Science Internships, Computer Science Questions, Contact, Contact Us, Copyright, CS, Data Structures & Algorithms II - Questions and Answers, Data Structures & Algorithms Books, Developer Tracks, Developers Track, ECE, EE, EEE, Electrical Engineering Books, Electrical Internships, Electronics Engineering Books, Electronics Internships, Facebook, Fibonacci Search, Floyd Warshall Algorithm, GDB Assignment, here is complete set of 1000+ Multiple Choice Questions and Answers, Home, In-place Merge Sort Multiple Choice Questions and Answers (MCQs), Industrial Engineering Books, Industrial Internships, Instrumentation, Instrumentation Engg Books, Instrumentation Internships, Internship, Introsort Multiple Choice Questions and Answers (MCQs), IS, IT, IT Internships, Jobs, Kadane's Algorithm, Kernel Debugging, Kernel Programming, LinkedIn, Linux Device Drivers, Linux Driver Developer, Linux Fundamentals, Linux Kernel Developer, Linux Network Developer, Linux Threads, Linux-C Debugging, Live Training Photos, Manish, Manish Bhojasia, Marine, Matrix Chain Multiplication, MCA, Mechanical, Mechanical Engineering Books, Mechanical Internships, Mentoring, Mentoring Sessions, Metallurgical Engineering Books, Metallurgy, Mining, Network Programming, Next Page, Next Page - Square Root Decomposition Multiple Choice Questions and Answers (MCQs), Online Training, Operating System Questions and Answers, Permutation Sort Multiple Choice Questions and Answers (MCQs), Prev Page, Prev Page - Quickselect Multiple Choice Questions and Answers (MCQs), Privacy Policy, Programming, Quickhull Multiple Choice Questions and Answers (MCQs), Quickselect Multiple Choice Questions and Answers (MCQs), Quicksort using Random Sampling Multiple Choice Questions and Answers (MCQs), Recursion, SAN Developer, SAN I - Technology, SAN II - Admin, Sitemap, Software Productivity, Square Root Decomposition Multiple Choice Questions and Answers (MCQs), System Programming, Systems Internships, Terms, Test & Rank, Training, Twitter

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • Geek Week – Celebrate The Biggest Programming Festival With GeeksforGeeks
  • Is Bitcoin a digital currency?
  • Internships in Automobile Engineering
  • Count pairs of non-overlapping palindromic sub-strings of the given string
  • Co-ordinate Compression Multiple Choice Questions and Answers (MCQs)
  • Privacy Policy
  • About
  • Contact US

© 2019 ProProgramming
 Privacy Policy About Contact Us