Data Structures Flashcards
A data structure used to store homogeneous elements at contiguous locations. Size must be provided before storing data.
Array
Search Time: O(n) for Sequential search, O(log n) for Binary Search (if sorted)
Array
Accessing Time: O(1), because elements are stored at contiguous locations
Array
Insertion Time: O(n), the worst case occurs when insertion happens at the beginning of the structure which then requires shifting all of the other elements
Array
Deletion Time: O(n), the worst case occurs when deletion happens at the beginning of the structure which then requires shifting all of the elements
Array
A data structure where each element is a separate object. Each element is comprised of two items – the data and a reference to the next node.
Linked list
In this type of linked list, every node stores the address / reference of next node. The last node’s reference is NULL.
For example 1->2->3->4->NULL
Singly linked list
In this type of Linked list, there are two references associated with each node. One that points to the next node and one that points to the previous node.
For example NULL23->NULL
Doubly Linked List
Advantage of this linked list data structure is that we can traverse in both directions and for deletion we don’t need to have explicit access to previous node.
Doubly Linked List
A linked list where all nodes are connected in either a singly linked list or doubly linked list.
Circular linked list
Advantage of this linked list data structure is that any node can be the starting node.
Circular linked list
Accessing time: O(n)
Search time: O(n)
Insertion of an Element : O(1), if we are at the position where we have to insert an element
Deletion of an Element : O(1), if we know the address of the node previous the node to be that is to be deleted.
Linked list
Eliminates unused memory when compared to an Array as nodes are only added when a new element is introduced.
Linked list
Insertions and deletions are easier when compared to an array because there is not need to shift elements.
Linked list
One big drawback of this data structure is that random access is not allowed. Unlike arrays, where we can access the n’th element in O(1) time. In this data structure, it would take O(n) time.
Linked list