Data Structures Stacks and Queues using Lists Important questions with answers - Solution
A data-structure is a logical way for organizing data in memory that considers not only the items stored but also the relationship among the items so as to give efficient and optimal performance. In other words, it is a way of organizing data such that it can be used efficiently.
2.Compare a data type with a Data structure.
Solution A Data type defines a set of values along with well-defined operations stating its input-output behavior e.g., you cannot put decimal point in an integer or two strings cannot not be multiplied etc.
3.What are linear and nonlinear data Structures?
Linear Data structure. A data structure is said to or a linear list. e.g., Arrays or linear lists, Stacks and Queues etc.
Non-Linear Data structure. A data structure is said to be non-linear if traversal of nodes is nonlinear in nature, e.g., Graphs, Trees etc..
4.What purpose Linear lists data structures are mostly used for?
Linear lists data structures are used to store and process elements that are similar in type and are to be processed in the same way. For example, to maintain a shopping list, a linear list may be used where items to be shopped are inserted to it one by one and as soon as an item is shopped, it is removed from the list.
5.What is a stack? What basic operations can be performed on them?
Stack is a basic data-structure where insertion and deletion of data takes place at one end called the top of the stack i.e., it follows the Last In-First Out(LIFO) principle.
In Python, a stack is generally implemented with lists. Following basic operations can be performed on stacks :
(a) Push i.e., Insertion of element in the stack
(b) Pop i.e., Deletion of an element from the stack
(c) Peek i.c., viewing topmost element without removing it
(d) Display or view all the elements in the stack.
6.Enlist some applications of stacks.
Because of LIFO property of stacks, these are used in various applications like:
a. reversal of a sequence,
b. Postfix and prefix expression evaluation,
c. Infix to Postfix conversion,