Homechevron_rightEngineeringchevron_rightComputer Sciencechevron_rightData Structurechevron_rightQueue structure is used in _______.

Queue structure is used in _______.

  • Q. Queue structure is used in _______.
  • filter_dramaExplanation
    Answer is : A
    • Breadth-first search (BFS) and Depth First Search (DFS) is an algorithm for traversing or searching tree or graph data structures.
    • Breadth First Search (BFS) algorithm traverses a graph in a breadthwise manner and uses a queue to remember to get the next vertex to start a search, when a dead end occurs in any iteration.
    • Depth First Search (DFS) uses Stack data structure. DFS uses backtracking technique. Remember backtracking can proceed by Stack.

Discussion

    No one started the discussion yet. Break the ice and start the conversation.
    Please Login to be part of the discussion.

Similar Questions

  • 1.

    Consider the following recursive function.

    Int function (int x, int y) {

                    If (y <= 0) return x;

                    return function (y, x%y);

                    }

    The above recursive function computes ______.

  • filter_dramaExplanation
    Answer is : B

    Consider x = 10 and y = 25

    CASE1:

    If (y <= 0) return x;                           // 25<=0 (false)

                    return function (y, x%y);            return function(25, 10)

    CASE 2:

    x = 25, y= 10

    If (y <= 0) return x;                          // 10<=0 (False)

                    return function (y, x%y);        // return function (10, 5)

    CASE 3:

    x =10, y =5

    If (y <= 0) return x;                         // 5<=0 (false)

                    return function (y, x%y);             //return function(5, 0)

    CASE 4:

    x = 5, y =0

    If (y <= 0) return x;                         // condition true, return 5

                    return function (y, x%y);

    Output = 5

    Which is greatest common divisor of 10 and 25.

    So, given program computes GCD of x and y

  • 2. A stack can be implemented using queue, but then we need to use atleast:
  • filter_dramaExplanation
    Answer is : B

    A stack can be implemented using two queues. Let stack to be implemented be ‘x’ and queues used to implement be ‘a’ and ‘b’.

    Method 1 (By push operation)
    This method makes sure that the newly entered element is always at the front of ‘a’, so that pop operation just dequeues from ‘a’. ‘b’ is used to put every new element at front of ‘b’.

    Method 2 (By making pop operation costly)
    In a push operation, the new element is always enqueued to a. In pop() operation, if b is empty then all the elements except the last, are moved to b. Finally, the last element is dequeued from a and returned.

    Therefore Option 2 is correct

  • 3. Which stack operation insert an element into the stack?
  • filter_dramaExplanation
    Answer is : A
    A stack is a linear data structure. The elements in a stack are added and removed only from one end, which is called the TOP. Hence, a stack is called a LIFO (Last-In-First-Out) data structure, as the element that was inserted last is the first one to be taken out. The push operation is used to insert an element into the stack. The pop operation is used to delete the topmost element from a stack.
  • 4. A recursive problem like tower of hanoi can be rewritten without recursion using:
  • filter_dramaExplanation
    Answer is : A

    Concept:

    • A stack is an ordered list in which insertion and deletion are done at one end, called a top.
    • The last element inserted is the first one to be deleted. Hence, it is called the Last in First out (LIFO) or First in Last out (FILO) list.

    Explanation:

    A recursive problem like the Tower of Hanoi can be rewritten using system stack or user-defined stack

    Recurrence relation of tower of Hanoi:  T(n) = 2T(n - 1) + 1 

    Additional Information

    Number of moves required for n disc in a Tower of Hanoi is 2– 1 = 27 – 1 = 127. 

    Stack underflow happens when one tries to pop (remove) an item from the stack when nothing is actually there to remove.

  • 5. Which of the following data structures is used in implementing recursive calls ?
  • filter_dramaExplanation
    Answer is : B

    Answer: Option 2

    Explanation

    - For implementing recursive calls, Stack (LIFO) is required. Because for each call to the function, the caller function's temporary variables need to be pushed into the stack so that at the time of backtracking variables are easily accessible.

    for example: 

    Consider the following Fibonacci example Where fib5 make a call to fib4 then fib5 will be pushed into the stack and then fib4 make a call to fib3, fib4 will be pushed into the stack and so on. and when fib1 and fib0 complete then backtracks to fib3 reusing the variable of fib3 which are stored in the stack.

    Additional Information

    Hash Table

    A hash table is a data structure that is used to store keys/value pairs. It uses a hash function to compute an index into an array in which an element will be inserted or searched. By using a good hash function, hashing can work well. Under reasonable assumptions, the average time required to search for an element in a hash table is O(1).

    Queue

    The queue is FIFO (First in First out) data structure i.e. the first element that is added to the queue is the first one to be removed. Elements are always added to the back (Rear) and removed from the front.

    Binary Tree:

    A Binary tree consists of nodes which are having data part and a pointer pointing to the left subtree and a right pointer pointing to the right subtree.

    If a tree is empty, it is represented by a null pointer.

Data StructureTopics

leaderboardLeaderboard
  • Rahul Kumar

    191 Points

  • VIKRAM JEET

    54 Points

  • GEETHIKA CHOWDARY

    53 Points

  • sunita saini

    52 Points

  • Zain

    49 Points