Linear data structures are data structures in which data elements are organized and accessed sequentially or linearly. The elements are arranged in a linear manner, such as in a straight line or a sequence.
Examples of linear data structures include:
Array: An array is a collection of elements of the same data type that are stored in contiguous memory locations. Elements in an array are accessed using their respective indexes.
Linked List: A linked list is a data structure in which data elements called nodes are connected together via pointers. Each node contains a data element and a pointer to the next node. Linked lists can be singly linked, where nodes have a pointer to the next node only, or they can be doubly linked, where nodes have pointers to the next and previous nodes.
Queue: A queue is a linear data structure in which elements are added at the rear(end) and removed from the front(front). The first element that was added to the queue will be the first to be removed as well.
Stack: A stack is a linear data structure in which elements are added and removed from the top only. The last element that was added to the stack will be the first to be removed.
What is the time complexity for accessing an element in an array?
Answer: O(1)
What is the difference between a linked list and an array?
Answer: A linked list is a linear data structure where elements are stored in nodes that are linked to each other, while elements in an array are stored in contiguous memory locations.
What is the time complexity to delete an element in a singly linked list?
Answer: O(n)
Can a circular linked list be implemented as a doubly linked list?
Answer: Yes, a circular linked list can be implemented as a doubly linked list by adding a previous pointer to each node and connecting the last node to the first node.
What is the time complexity to search for an element in a binary search tree?
Answer: O(log n)