0% found this document useful (0 votes)
21 views7 pages

Linked List and Stack Data Structures Quiz

The document contains 50 multiple choice questions about data structures like linked lists, stacks, queues, trees and heaps. The questions cover topics like linear and non-linear data structures, searching linked lists, adding and removing nodes from queues, stack and queue operations, recursion, infix, postfix and prefix expressions, dynamic memory allocation and linked lists.

Uploaded by

Nitish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views7 pages

Linked List and Stack Data Structures Quiz

The document contains 50 multiple choice questions about data structures like linked lists, stacks, queues, trees and heaps. The questions cover topics like linear and non-linear data structures, searching linked lists, adding and removing nodes from queues, stack and queue operations, recursion, infix, postfix and prefix expressions, dynamic memory allocation and linked lists.

Uploaded by

Nitish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNIT-7

Q.1 Is a linked list a linear or non-linear data structure?


(a) Linear (b) Non-linear
(c) Can’t say (d) None
Q.2 How can I search for data in a linked list?
(a) Non-linear search (b) Linear search
(c) Can’t say (d) None
Q.3 What is each entry in a linked list called?
(a) Element (b) Node
(c) Value (d) None
Q.4 The value of the first linked-list index is ____________
(a) –1 (b) 0
(c) 1 (d) none
Q.5 ____________ form of access is used to add and remove nodes from a queue.
(a) FIFO (b) LIFO
(c) FILO (d) None
Q.6 New nodes are added to the ____________ of the queue.
(a) front (b) back
(c) middle (d) none
Q.7 A dequeue (or double-ended queue) is a sequence of elements with the property that
elements can be added, inspected, and removed at ____________
(a) either end (b) one end
(c) both ends (d) none
Q.8 What is the benefit of using a queue linked list?
(a) Queue for scheduling (b) Queue is faster than stack
(c) Both (d) None
Q.9 The StackLinkedList class inherits the LinkedList class
(a) True (b) False
(c) Can’t say (d) None
Q.10 The stack top is initialized to____________ value.
(a) 0 (b) 1
(c) –1 (d) none
Q.11 Convert the infix expression (A – B) * C + D to postfix.
(a) A B – C * D + (b) AB-CD+*
(c) AB–CD*+ (d) none
Q.12 Entries in a stack are ‘ordered’. What is the meaning of this statement?
(a) A collection of stacks can be sorted.
(b) Stack entries may be compared with the ‘<’ operation.
(c) The entries must be stored in a linked list.
(d) There is a first entry, a second entry, and so on.
Q.13 The operation for adding an entry to a stack is traditionally called
(a) add (b) append
(c) insert (d) push
Q.14 The operation for removing an entry from a stack is traditionally called
(a) delete (b) peek
(c) pop (d) remove
Q.15 Which of the following stack operations could result in stack underflow?
(a) is_empty (b) pop
(c) push (d) Two or more of the above answers
Q.16 Which of the following applications may use a stack?
(a) A parentheses balancing program
(b) Keeping track of local variables at run time
(c) Syntax analyzer for a compiler
(d) All of the above
Q.17 In the linked-list implementation of the stack class, where does the push method
place the new entry on the linked list?
(a) At the head
(b) At the tail
(c) After all other entries that are greater than the new entry
(d) After all other entries that are smaller than the new entry
Q.18 Convert (6 + 2) * 5 – 8 / 4 into postfix.
(a) 62+584/–* (b) 62+5*84–/
(c) 6 2 + 5 * 8 4 / – (d) None
Q.19 Convert the expression ((A + B) * C – (D – E) ^ (F + G)) to equivalent polish
notation.
(a) –^*+ABC–DE+FG (b) ^ – * +ABC – DE + FG
(c) ^*–+ABC–DE+FG (d) None
Q.20 Convert the expression ((A + B) * C – (D – E) ^ (F + G)) to equivalent reverse
polish notation.
(a) AB+C*DE-FG+^– (b) AB+CDE*--FG+^
(c) AB + C * DE - - FG + ^ (d) None
Q.21 The minimum number of queues needed to implement the priority queue are
(a) one (b) two
(c) can’t say (d) none
Q.22 In tree construction which is the suitable efficient data structure?
(a) Array (b) Linked list
(c) Stack (d) Queue

106
Q.23 The first operation performed on a stack is____________
(a) deletion (b) insertion
(c) both (d) none
Q.24 Stack is said to be overflow when____________
(a) top=max–1 (b) top=max
(c) top=–1 (d) none
Q.25 The process of allocating memory at run time is called____________
(a) run time allocation (b) compile time allocation
(c) dynamic memory allocation (d) both a and c
Q.26 Local variables are stored in____________
(a) stack (b) heap
(c) memory (d) none
Q.27 Operations performed on a linked list is/are____________
(a) traversing the list (b) inserting an item
(c) creating a list (d) All the above
Q.28 The free memory region is called____________
(a) heap (b) stack
(c) both (d) none
Q.29 A block of memory can be requested at run time using____________
(a) malloc (b) calloc
(c) both (d) none
Q.30 Multiple blocks of memory can be allocated using____________
(a) malloc (b) calloc
(c) can’t say (d) both
Q.31 Memory space must be explicitly released in dynamic run-time allocation.
(a) True (b) False
(c) Can’t say (d) None
Q.32 Realloc is used for____________
(a) Reallocation of memory (b) free memory space
(c) none (d) can’t say
Q.33 A double-linked list is said to be empty when____________
(a) rear=front–1 (b) rear =front=0
(c) rear=front (d) none
Q.34 A double-linked list is said to be overflow when____________
(a) rear=front (b) rear>=max–1
(c) none
Q.35 Evaluate the postfix expression 22*1+
(a) 6 (b) 4

107
(c) 5 (d) 7
Q.36 Convert a$b*c-d+e/f/(g+h) into a postfix expression.
(a) ab$cd-* ef/gh+/+ (b) ab$c*d-ef/gh/++
(c) ab$c*d-ef/gh+/+ (d) None
Q.37 A circular queue is said to be underflow when____________
(a) (rear+1)%max=front (b) (front+1)%max=rear
(c) rear=front (d) none
Q.38 A ___________ is a way of organizing data that considers not only the items stored,
but also their relationship to each other.
(a) linked list (b) data structure
(c) both (d) none
Q.39 The areas in which data structures are applied extensively are
(a) Numerical Analysis, (b) Graphics,
(c) Artificial Intelligence (d) All
Q.40 A circular queue is said to be overflow when____________
(a) (rear+1)%max=front (b) (front+1)%max=rear
(c) rear=front (d) none
Q.41 The highest precedence operator is____________
(a) $ (b) ^
(c) * (d) ()
Q.42 Among the following which is fastest to implement?
(a) Array (b) Linked list
(c) Depends on application (d) Both a and b
Q.43 To place the elements in a particular place ____________ is used.
(a) array (b) linked list
(c) both (d) can’t say
Q.44 In an input restricted deque elements are insert from____________
(a) left (b) right
(c) either side (d) none
Q.45 Convert abc$+ into infix.
(a) a$b+c (b) a+b$c
(c) a$bc+ (d) None
Q.46 The data structures used to perform recursion are
(a) queue (b) stacks
(c) both (d) none
Q.47 Evaluate the postfix expression 23+5*.
(a) 11 (b) 25
(c) 13 (d) None
Q.48 Stacks are used in____________
(a) calculators (b) computers
108
(c) both (d) none
Q.49 Convert ab$c*d-ef/gh+/+ into infix.
(a) a*b$c-d+e/f/(g+h) (b) a$b*c+d-e/f/(g+h)
(c) a$b*c-d+e/f/(g+h) (d) none
Q.50 Structures which contain a member field that points to the same structure type are
called-____________
(a) self-referential structure (b) recursive structure
(c) both (d) none
Answers
1. (a) 2. (b) 3. (b) 4. (d)
5. (a) 6. (b) 7. (c) 8. (c)
9. (a) 10. (c) 11. (a) 12. (d)
13. (d) 14. (c) 15. (a) 16. (d)
17. (a) 18. (c) 19. (b) 20. (c)
21. (b) 22. (b) 23. (b) 24. (a)
25. (d) 26. (a) 27. (d) 28. (a)
29. (c) 30. (b) 31. (a) 32. (a)
33. (a) 34. (b) 35. (c) 36. (c)
37. (a) 38. (b) 39. (d) 40. (a)
41. (d) 42. (c) 43. (b) 44. (b)
45. (b) 46. (b) 47. (b) 48. (c)
49. (c) 50. (a)
Q.51 Which of the following is the feature of stack? All operations are at one end and it
cannot reuse its memory
Ans: Any element can be accessed from it directly.
Q.52 When stacks created, they are…
Ans: initially empty
Q.53 What is time required to insert an element in a stack with linked implementation?
Ans: (log 2n)
Q.54 The time taken for addition of an element in a queue is
Ans: (log n)
Q.55 When is a linear queue said to be empty? Front==rear
Ans: Front=rear
Q.56 When queues are created, they are
Ans: initially empty
Q.57 What is the type of algorithm used in solving the 8 Queens problem?
(a) Queues (b) Semaphores
(c) Backtracking (d) Dijkstra
Q.58 In which data structure, elements can be added or removed at either end, but not in
109
the middle?
(a) Linked List (b) Double ended Queue
(c) stack (d) none
Q.59 Which sort shows the best average behavior?
(a) Quick sort (b) Bubble sort
(c) Insertion sort (d) Heap sort
Q.60 Which data structure is needed to convert infix notations to post fix notations?
(a) stack (b) queue
(c) linked list (d) d-queue
Q.61 What data structure would you mostly likely see in a non recursive implementation
of a recursive algorithm?
(a) queue (b) linked list
(c) stack (d) double linked list
Miscellaneous Questions
Q.1 What is a data structure?
Ans: A data structure is a way of organizing data that considers not only the items stored,
but also their relationship to each other. Advance knowledge about the relationship
between data items allows designing of efficient algorithms for the manipulation of
data.
Q.2 List the areas in which data structures are applied extensively?
Ans: Compiler Design, Operating System, Database Management System, Statistical
analysis package, Numerical Analysis, Graphics, Artificial Intelligence, Simulation
Q.3 What are the major data structures used in the following areas: RDBMS, Network
data model and Hierarchical data model?
Ans: RDBMS-Array (i.e., Array of structures)
Network data model-Graph
Hierarchical data model-Trees
Q.4 If you are using C language to implement the heterogeneous linked list, what pointer
type will you use?
Ans: The heterogeneous linked list contains different data types in its nodes and we need
a link and pointer to connect them. It is not possible to use ordinary pointers for this.
So we go for void pointer. A void pointer is capable of storing a pointer to any type
as it is a generic pointer type.
Q.5 What is the minimum number of queues needed to implement the priority queue?
Ans: Two. One queue is used for actual storing of data and another for storing priorities.
Q.6 What is the data structures used to perform recursion?
Ans: Stack. Because of its LIFO (Last In First Out) property, it remembers its 'caller' so
knows whom to return when the function has to return. Recursion makes use of
system stack for storing the return addresses of the function calls. Every recursive
110
function has its equivalent iterative (non-recursive) function. Even when such
equivalent iterative procedures are written, an explicit stack is to be used.
Answers
57. (c) 58. (b) 59. answer missing 60. (a)
61. (c)

111

Common questions

Powered by AI

A priority queue differs from a standard queue in that each element is associated with a priority, and elements are dequeued in order of their priority rather than their arrival order. Implementing a priority queue requires at least two queues: one for the data and another for storing the associated priorities . This structure allows for elements with higher priority to be served before those with lower priority, unlike standard queues which follow a FIFO (First In First Out) order .

A stack-based linked list benefits from dynamic sizing, meaning it does not require pre-allocated memory, thus perfectly matches the ideal of dynamic growth. This avoids potential stack overflow issues faced by array-based implementations. Conversely, an array-based stack allows faster access times due to contiguous memory allocation, benefiting operations with regards to memory caching efficiency. However, managing edge cases such as overflow requires additional checks, unlike the linked list approach where overflow is only limited by system memory .

A stack overflow occurs when trying to add an element to a stack that is already at its maximum capacity (top = max - 1). On the other hand, stack underflow happens when attempting to remove an element from an empty stack . Both conditions indicate improper use or a lack of space management in stack operations.

Dynamic memory allocation enhances data structures by allowing the program to acquire memory at runtime, offering flexibility in managing memory efficiently. This process reduces waste by allocating only the required memory size, allowing structures like linked lists or variable-sized stacks to grow and shrink as needed without preallocation limits. Moreover, dynamic allocation is performed using functions like malloc and calloc in languages like C, which help optimize resource usage by only consuming memory that is demanded during execution .

A double-ended queue (deque) allows insertion and deletion at both ends, unlike a standard queue which only allows these operations at one end (rear for insertion, front for deletion). This flexibility allows a deque to serve as both a queue and a stack and supports more complex data processing scenarios such as palindrome checking, where elements might need to be accessed symmetrically from both ends .

Stacks are advantageous for implementing recursion due to their LIFO (Last In First Out) nature, which perfectly aligns with the recursive call and return sequence. Each recursive call pushes an entry onto the stack, storing the return address and local variables, and upon reaching the base case, entries are popped off the stack as calls return. This mirrors the natural flow of recursive function execution, making stacks the preferred structure for recursion over others like queues or arrays, which do not naturally support this order .

Using a linked list to implement a queue offers several advantages: dynamic memory allocation (no predefined size), efficient O(1) enqueue and dequeue operations as nodes can be added at one end and removed from the other. However, the drawbacks include higher complexity in accessing elements (only sequential access is possible) leading to O(n) search times and increased memory usage due to storage of pointers .

A circular queue is preferable over a regular queue in scenarios where maximizing the utilization of available memory is crucial, such as embedded systems with fixed memory sizes. Unlike a regular linear queue which can lead to wastage of available space when elements are dequeued, a circular queue efficiently reuses space by connecting the end of the queue back to the front, effectively managing the queue size within the given limits .

Data structures are critical in compiler design as they manage and optimize the process of translating high-level code into efficient machine code. For instance, abstract syntax trees (ASTs) are used to represent the hierarchical structure of the source code, enabling efficient syntax checking and transformation. Graph structures are employed for optimizing flow control and dependency analysis. Efficient use of stacks enables recursion handling and tracking of scope, crucial for compiling complex language constructs. Thus, data structures directly influence the speed and resource efficiency of the compiled programs .

A linked list is a linear data structure where elements are linked using pointers. Each element is called a node, which contains data and a reference to the next node. This characteristic allows for efficient insertion and deletion of nodes, as these operations do not require reallocation of other elements like in arrays. However, searching through a linked list is less efficient since it requires a linear search, making the time complexity O(n).

You might also like