My Report

Data Structure I Mock Test 4


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement
 10%

Question 1 of 10

1. How many swaps are required for reversing an array having n elements where n is an odd number?

Question 1 of 10

Question 2 of 10

2. Which of the following data structure is preferred to have lesser search time when the list size is small?

Question 2 of 10

Question 3 of 10

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

#include <bits/stdc++.h> 
using namespace std; 

void func(int arr[], int left, int right) 
{ 
    if (left >= right) 
    return; 
      
    int temp = arr[left];  
    arr[left] = arr[right]; 
    arr[right] = temp; 
      
    func(arr, left + 1, right - 1);  
}      

void printArray(int arr[], int size) 
{ 
    for (int i = 0; i < size; i++) 
    cout << arr[i] << " "; 
} 

int main() 
{ 
	int arr[] = {1,2,3,4}; 
	int n = sizeof(arr) / sizeof(arr[0]); 
	func(arr, 0, n-1); 
	printArray(arr, n); 
	return 0; 
} 

Question 3 of 10

Question 4 of 10

4. What will be the minimum number of jumps required to reach the end of the array arr[] ={0,1,3,6,3,6,8,5}?

Question 4 of 10

Question 5 of 10

5. A binary tree is a rooted tree but not an ordered tree.

Question 5 of 10

Question 6 of 10

6. How many children does a binary tree have?

Question 6 of 10

Question 7 of 10

7. Predefined function reverse() in C++ is available under which header file?

Question 7 of 10

Question 8 of 10

8. To which datastructure are skip lists similar to in terms of time complexities in worst and best cases?

Question 8 of 10

Question 9 of 10

9. General ordered tree can be encoded into binary trees.

Question 9 of 10

Question 10 of 10

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

#include <bits/stdc++.h> 
using namespace std; 
void func(int a[], int n, int k) 
{ 
	if (k <= n) 
	{ 
		for (int i = 0; i < k/2; i++) 
		swap(a[i], a[k-i-1]); 
	} 
	
} 
int main() 
{ 
	int a[] = {1, 2, 3, 4, 5}; 
	int n = sizeof(a) / sizeof(int), k = 3; 
	func(a, n, k); 
	for (int i = 0; i < n; ++i) 
		cout << a[i]<<" ";
	return 0; 
} 

Question 10 of 10


 

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.