Data Structure Quiz Questions!

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.
Learn about Our Editorial Process
| By Mahesh
M
Mahesh
Community Contributor
Quizzes Created: 1 | Total Attempts: 454
Questions: 10 | Attempts: 457

SettingsSettingsSettings
Data Structure Quiz Questions! - Quiz


Would you like a challenge? This quiz on data structure will blow your mind. With this quiz, you should know how to reverse the order of elements in and between positions, what the sequences do, what a single array is used for, and which permutations of printed values are possible. This quiz will help you understand data structure and enhance your knowledge. Give it a shot.


Questions and Answers
  • 1. 

    Let the following circular queue can accommodate maximum six elements with the             following data             front = 2 rear = 4             queue = __ , L, M, N, ___, ___ What will happen after insert O operation takes place?  

    • A.

      Front = 2 rear = 5 queue = __, L, M, N, O, ___

    • B.

      Front = 3 rear = 5 queue = __, L, M, N, O, ___

    • C.

      Front = 3 rear = 4 queue = __, L, M, N, O, ___

    • D.

      Front = 2 rear = 4         queue = L, M, N, O, ___

    Correct Answer
    A. Front = 2 rear = 5 queue = __, L, M, N, O, ___
    Explanation
    After the insert O operation takes place, the rear pointer will move to the next empty position in the circular queue, which is at index 5. The element "O" will be inserted at this position. Therefore, the front and rear pointers will be updated to front = 2 and rear = 5 respectively. The circular queue will then contain the elements L, M, N, O in that order.

    Rate this question:

  • 2. 

    Suppose you are given an array s[1...n] and a procedure reverse (s,i,j) which reverses the order of elements in a between positions i and j (both inclusive). What does the following sequence do, where 1 < k <= n: reverse (s, 1, k);reverse (s, k + 1, n);reverse (s, 1, n);

    • A.

      Rotates s left by k positions

    • B.

      Leaves s unchanged

    • C.

      Reverses all elements of s

    • D.

      None of the above

    Correct Answer
    A. Rotates s left by k positions
    Explanation
    The given sequence of operations reverses the order of elements in the array s between positions 1 and k, then reverses the order of elements between positions k+1 and n, and finally reverses the entire array s. This sequence effectively rotates the array s left by k positions.

    Rate this question:

  • 3. 

    A single array A[1..MAXSIZE] is used to implement two stacks. The two stacks grow from opposite ends of the array. Variables top1 and top2 (topl< top 2) point to the location of the topmost element in each of the stacks. If the space is to be used efficiently, the condition for “stack full” is

    • A.

      (top1 = MAXSIZE/2) and (top2 = MAXSIZE/2+1)

    • B.

      Top1 + top2 = MAXSIZE

    • C.

      (top1= MAXSIZE/2) or (top2 = MAXSIZE)

    • D.

      Top1= top2 -1

    Correct Answer
    D. Top1= top2 -1
    Explanation
    The condition for "stack full" is that the variable top1 is equal to top2 minus 1. This means that the topmost element in the first stack (top1) is one position less than the topmost element in the second stack (top2). This ensures that both stacks are utilizing the available space efficiently and there is no wasted space between them.

    Rate this question:

  • 4. 

    What is a leaf node in a tree?

    • A.

      Node with 1 child

    • B.

      Node with n children

    • C.

      Node with zero child

    • D.

      None of these

    Correct Answer
    C. Node with zero child
    Explanation
    A leaf node in a tree refers to a node that does not have any children. In other words, it is a node that is located at the end of a branch and does not have any further branches extending from it. This means that it is the last node in a particular path of the tree and does not have any descendants.

    Rate this question:

  • 5. 

    An item that is read as input can be either pushed to a stack and later popped and printed, or printed directly. Which of the following will be the output if the input is the sequence of items 1, 2, 3, 4, 5?

    • A.

      3, 4, 5, 1, 2

    • B.

      3, 4, 5, 2, 1

    • C.

      1, 5, 2, 3, 4

    • D.

      5, 4, 3, 1, 2

    Correct Answer
    B. 3, 4, 5, 2, 1
    Explanation
    The given sequence of items 1, 2, 3, 4, 5 will be pushed to the stack in the order they are read. However, when popping and printing the items, the last item pushed will be the first one to be popped and printed. Therefore, the output will be 3, 4, 5, 2, 1.

    Rate this question:

  • 6. 

    Stack A has the entries a, b, c (with a on top), Stack B is empty. An entry popped out of stack A can be printed immediately or pushed to stack B. An entry popped out of stack B can only be printed. In the arrangement, which of the following permutations of printed values (a, b, c) is not possible?

    • A.

      B a c

    • B.

      B c a

    • C.

      C a b

    • D.

      A b c

    Correct Answer
    A. B a c
    Explanation
    The given arrangement allows for printing the values in the order of a, b, c. This means that the permutation b a c is not possible because it contradicts the allowed order.

    Rate this question:

  • 7. 

    What does the following function do for a given Linked List? void fun1(struct Node* start) { if( start == NULL) return;   fun1(start->next); printf("%d ", start->data); }

    • A.

      Print the linked list from beginning

    • B.

      Print the linked list after first node

    • C.

      Print the first node only

    • D.

      None of these

    Correct Answer
    D. None of these
    Explanation
    The given function, fun1, recursively calls itself with the next node in the linked list until it reaches the end (start == NULL). Then, it prints the data of each node in reverse order. Therefore, the function does not print the linked list from the beginning, nor does it print the linked list after the first node, or print only the first node. Hence, the correct answer is "none of these".

    Rate this question:

  • 8. 

    What does the following function do for a given Linked List? void fun2(struct Node* head) { if(start== NULL) return; printf("%d ", start->data);    if(start->next != NULL ) fun2(start->next->next); printf("%d ", start->data);  }

    • A.

      Print the linked list from beginning

    • B.

      Print the alternate node of the linked list

    • C.

      Print the first node only

    • D.

      None of the these

    Correct Answer
    B. Print the alternate node of the linked list
    Explanation
    The given function, fun2, prints the alternate nodes of the linked list. It first checks if the head of the linked list is NULL, and if so, it returns. Then it prints the data of the current node (start) and checks if the next node (start->next) is not NULL. If it is not NULL, it recursively calls the function with the next next node (start->next->next). Finally, it prints the data of the current node again. This process continues until all the alternate nodes are printed.

    Rate this question:

  • 9. 

    A program P reads in 500 integers in the range [0..100] representing the scores of 500 students. It then prints the frequency of each score above 50. What would be the best way for P to store the frequencies?

    • A.

      An array of 50 numbers

    • B.

      An array of 100 numbers

    • C.

      An array of 500 numbers

    • D.

      A dynamically allocated array of 550 numbers

    Correct Answer
    A. An array of 50 numbers
    Explanation
    Since the program is only interested in the frequency of scores above 50, it would be sufficient to store the frequencies in an array of 50 numbers. This is because the range of possible scores is [0..100], and any score below or equal to 50 would not be counted. Therefore, an array of 50 numbers would be the most efficient way to store the frequencies of scores above 50.

    Rate this question:

  • 10. 

    Which one of the following is an application of Queue Data Structure?

    • A.

      When a resource is shared among multiple consumers

    • B.

      When data is transferred asynchronously (data not necessarily received at same rate as sent) between two processes

    • C.

      Load Balancing

    • D.

      All of these

    Correct Answer
    D. All of these
    Explanation
    The correct answer is "all of these". Queue data structure can be used in various scenarios. When a resource is shared among multiple consumers, a queue can be used to manage the access and ensure fairness. When data is transferred asynchronously between two processes, a queue can be used to buffer the incoming and outgoing data. Additionally, in load balancing, a queue can be used to distribute the workload among multiple servers or processes. Therefore, all of the given options are valid applications of a queue data structure.

    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 22, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Nov 02, 2017
    Quiz Created by
    Mahesh
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.