interview questions regarding data structures
Q1: Describe the types of Data Structures?
Ans: There are two types in which the data structures are classified:
Linear Data Structure: If all its components are organized in the sequence, a data structure is termed linear. Except for initial and final components, the elements are kept in linear data structures in a non-hierarchical fashion.
Non-Linear Data Structure: The non-linear structure of the data does not constitute a sequence, that is to say, that each element is linked in a non-linear arrangement with two or more other items. In the sequential structure, the data components are not organized.
Q2: What is a Linked List and What are its types?
Ans:A linked list is a linear (similar to arrays) data structure with each member being an object. There are two elements in each item (which is a node) in the list - the dates and the reference for the next node. Linked List Types are:
- Singly Linked List: Each node contains an address or reference for the next node in the list in that kind of linked list, and the final node has the next address or reference as NULL. For example 1->2->3->4->NULL
- Doubly Linked List: Here are two node references, one reference to the next node and one reference to the prior node. Eg. NULL<-1<->2<->3->NULL
- Circular Linked List: The linked circular list is a connected list with all nodes in a circle. In the end, there's no NULL. A circular linked list may be a single circular linked or twice circular connected list. Eg. 1->2->3->1 [The next pointer of the last node is pointing to the first]
Q3: Can you explain the difference between file structure and storage structure?
- File Structure: Data in secondary or subsidiary memory are represented as a file representing any device, such as hard disc or pen drives, that saves data that remains untouched until removed explicitly.
- Storage Structure: Data are saved in the main memory, i.e. RAM, in this way and are removed once the function used by this data is run.
- The distinction is that in the computer system memory the storage structure has saved the data, while in the auxiliary memory the structure has stored the data.
Q4: What is a postfix expression? Write the postfix form of the expression: (A + B) * (C - D)
Ans:The term "postfix" is an expression in which operators are following the operands. The major advantage is that no grouping or precedence of the operator is necessary for parentheses.
The expression "a + b" will be represented as "ab+" in postfix notation.
Q5: Explain the scenarios where you can use linked lists and arrays.
- The below are the circumstances in which the linked array list is used:
- If the precise number of elements is not known in advance.
- If we knew that a significant number of addition or deletion operations would take place.
- Less random accommodation transactions.
- If we would want to insert items in a list, for example when a priority queue is being implemented, a list linked is more suited.
- Following are the instances in which the linked list uses arrays:
- When items need to be indexed or accessed randomly more often.
- If we know a preliminary number of items in the array to assign the proper memory quantity.
- When iterating speed over the sequence elements.
- When memory is a concern:
- It's reasonable to claim that full arrays require less memory than linked lists by the nature of arrays and associated lists.
- Each element in the array indicates data only, whereas the data and one or two points or the references to each of the other items in the linked list are represented by each linked list node.
- To conclude, while selecting which data structure to employ over what, the needs of space, time, and simplicity of implementation are taken into account.