# Data Structure Skills Quiz! Trivia

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
| By Shrenya Mathur
S
Shrenya Mathur
Community Contributor
Quizzes Created: 2 | Total Attempts: 919
Questions: 10 | Attempts: 357

Settings

Have you ever heard of data structure? A data structure is a data organization, supervision and storage format that allows for efficient contact and modification in computer science. Data structures are often employed as objects, so understanding these items and analyzing them is an extremely important skill to possess. A data structure is a compilation of data values and the relationships they keep. This quiz will demonstrate your skills with the data structure.

• 1.

### Struct Node{    int val;    struct Node *next; }*head; int get_max() {       struct Node* temp = head->next;   int max_num = temp->val;   while(______)   {         if(temp->val > max_num)     max_num = temp->val; temp = temp->next;   }   return max_num; } Which of the following lines should be inserted to complete the above code?

• A.

Temp->next!=0

• B.

Temp->next!=0

• C.

• D.

B. Temp->next!=0
Explanation
In order to iterate through the linked list and find the maximum value, a condition needs to be added to the while loop to ensure that the loop continues until the end of the linked list is reached. The condition "temp->next!=0" checks if the next pointer of the current node is not NULL, indicating that there is still a node to iterate to. This ensures that the loop continues until the end of the linked list is reached.

Rate this question:

• 2.

### What is the time complexity of inserting a node in a doubly linked list?

• A.

O(nlogn)

• B.

O(logn)

• C.

O(n)

• D.

O(1)

C. O(n)
Explanation
The time complexity of inserting a node in a doubly linked list is O(n). This is because in order to insert a node, we need to traverse the list to find the correct position for insertion. This traversal takes a linear amount of time, proportional to the number of nodes already present in the list. Therefore, the time complexity is O(n).

Rate this question:

• 3.

### Which of the following real-world scenarios would you associate with a stack data structure?

• A.

Piling up of chairs one above the other

• B.

People standing in a line to be serviced at a counter

• C.

Offer services based on the priority of the customer

• D.

All of the above

A. Piling up of chairs one above the other
Explanation
The scenario of piling up chairs one above the other can be associated with a stack data structure because a stack follows the Last-In-First-Out (LIFO) principle. Just like when we pile up chairs, the last chair we put on top will be the first one to be removed when we want to take a chair from the pile. Similarly, in a stack data structure, the most recently added element is the first one to be removed.

Rate this question:

• 4.

### What does the following piece of code do?   public Object function() { if(isEmpty()) return -999; else { Object high; high = q[front]; return high; } }

• A.

Dequeue

• B.

Enqueue

• C.

Return the front statement

• D.

None

C. Return the front statement
Explanation
The given piece of code is a function that returns the element at the front of a queue. It first checks if the queue is empty using the isEmpty() function. If the queue is empty, it returns -999 as a placeholder value. Otherwise, it assigns the value at the front of the queue to the variable 'high' and returns it. Therefore, the correct answer is "return the front statement".

Rate this question:

• 5.

### What is the output of the following code? #include<stdio.h> int recursive_search_num(int *arr, int num, int idx, int len) {      if(idx == len)       return -1;      if(arr[idx] == num)       return idx;      return recursive_search_num(arr, num, idx+1, len); } int main() {       int arr[8] ={-11,2,-3,0,3,5,-6,7},num = -2,len = 8;       int indx = recursive_search_num(arr,num,0,len);       printf("Index of %d is %d",num,indx);       return 0; }

• A.

Index of -2 is 1

• B.

Index of -2 is 0

• C.

Index of -2 is -1

• D.

None

C. Index of -2 is -1
Explanation
The code is implementing a recursive search function called recursive_search_num. It takes an array, a number to search for, the current index, and the length of the array as parameters.

In the main function, an array arr is initialized with values {-11,2,-3,0,3,5,-6,7}, and the number to search for is -2. The length of the array is 8.

The recursive_search_num function is called with the array, the number, the initial index 0, and the length 8.

Inside the recursive_search_num function, it checks if the current index is equal to the length of the array. If it is, it means the number was not found in the array, so it returns -1.

If the current element at the index is equal to the number, it means the number was found, so it returns the current index.

If neither of the above conditions is true, it calls the recursive_search_num function again with the incremented index.

In this case, the number -2 is not present in the array arr, so the function will go through all the elements and reach the end of the array without finding the number. Therefore, the output will be "Index of -2 is -1".

Rate this question:

• 6.

### Which data structure can be used suitably to solve the Tower of Hanoi problem?

• A.

Tree

• B.

Heap

• C.

Priority Queue

• D.

Stack

D. Stack
Explanation
The Tower of Hanoi problem involves moving a stack of disks from one peg to another, following specific rules. A stack is a suitable data structure for this problem because it follows the Last-In-First-Out (LIFO) principle, which aligns with the rules of the Tower of Hanoi problem. By using a stack, we can easily keep track of the disks and their order, allowing us to move them according to the problem's constraints.

Rate this question:

• 7.

### What is the space complexity of the post-order traversal in the recursive fashion? (d is the tree depth and n is the number of nodes)

• A.

O(1)

• B.

O(nlogd)

• C.

O(logd)

• D.

O(d)

D. O(d)
Explanation
The space complexity of the post-order traversal in the recursive fashion is O(d). This is because in a post-order traversal, the recursive function calls are made for each node in the tree, and the maximum depth of the recursion is equal to the depth of the tree. Therefore, the space required for the recursive function calls is proportional to the depth of the tree, resulting in a space complexity of O(d).

Rate this question:

• 8.

### How many times is the recursive function called, when the following code is executed?   void my_recursive_function(int n) {      if(n == 0)      return;      printf("%d ",n);      my_recursive_function(n-1); } int main() {      my_recursive_function(10);      return 0; }

• A.

9

• B.

10

• C.

11

• D.

12

C. 11
Explanation
The recursive function is called 11 times because it is called recursively until the base case is reached, which is when n becomes 0. In this case, the function is initially called with n = 10, and then it is called again with n = 9, 8, 7, 6, 5, 4, 3, 2, 1, and finally 0. So, the function is called a total of 11 times.

Rate this question:

• 9.

### What is the output of the following code?   void my_recursive_function(int n) {     if(n == 0)     return;     printf("%d ",n);     my_recursive_function(n-1); } int main() {     my_recursive_function(10);     return 0; }

• A.

10

• B.

1

• C.

10 9 8 ……. 1 0

• D.

10 9 8 ……. 1

D. 10 9 8 ……. 1
Explanation
The code defines a recursive function called "my_recursive_function" that takes an integer parameter "n". If "n" is equal to 0, the function returns. Otherwise, it prints the value of "n" and then calls itself with the parameter "n-1".

In the main function, "my_recursive_function" is called with the argument 10. This means that the function will be called recursively 10 times, each time printing the value of "n" and then calling itself with "n-1".

Therefore, the output of the code will be a sequence of numbers from 10 to 1, with each number separated by a space.

Rate this question:

• 10.

### What is a dynamic array?

• A.

A variable size data structure

• B.

An array which is created at runtime

• C.

The memory to array is allocated at runtime

• D.

An array which is reallocated everytime whenever new elements have to be added

A. A variable size data structure
Explanation
A dynamic array is a variable size data structure that allows for the allocation of memory at runtime. It is different from a static array, which has a fixed size. With a dynamic array, the memory can be reallocated whenever new elements need to be added, making it flexible and efficient for managing changing amounts of data.

Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

• Current Version
• Mar 21, 2023
Quiz Edited by
ProProfs Editorial Team
• Jan 28, 2019
Quiz Created by
Shrenya Mathur

Related Topics