My Report

Data Structure I Practice 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

1. 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; 
} 

2. Why is heap implemented using array representations than tree(linked list) representations though both tree representations and heaps have same complexities?

for binary heap
-insert: O(log n)
-delete min: O(log n)

for a tree
-insert: O(log n)
-delete: O(log n)

Then why go with array representation when both are having same values ?

3. Which of the following is the predefined function for array reversal in javascript?

4. What operation does the following diagram depict?
binary-tree-operations-questions-answers-q7

5. If the tree is not a complete binary tree then what changes can be made for easy access of children of a node in the array?

6. What is indexed skip list?

7. What will be the auxiliary space complexity of the following code?

#include <iostream>
using namespace std;
int main()
{   
    int arr[] = {1,2,3,4,5,6};
    int n = sizeof(arr)/sizeof(arr[0]);
    int d=4;
    int temp[10];
    
    for(int i=0;i<d;i++)
    temp[i]=arr[i];
    
    int j=0;
    for(int i=d;i<n;i++,j++)
    arr[j]=arr[i];
    
    int k=0;
    for(int i=n-d;i<n;i++,k++)
    arr[i]=temp[k];
    
    for(int i=0;i<n;i++)
    cout<<arr[i]<<" ";
    return 0;
}

8. In _____________ method, whenever a node is accessed, it might move to the head of the list if its number of accesses becomes greater than the records preceding it.

9. Which of the following is the predefined function for array reversal in C++?

10. What is the time complexity improvement of skip lists from linked lists in insertion and deletion?


 

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.