Introduction to Linear Data structures - Arrays, Linked Lists, Stacks and Queues

Опубликовано: 16 Февраль 2023
на канале: Shahid Nihal
170
5

Before digging deeper into designing and analyzing algorithms, we need to brush up on the important and most commonly used data structures. In this video, we check out on the important linear data structures like arrays, linked lists, stacks and queues.

Arrays are data structures allocated in a contiguous memory region. If enough contiguous memory is not available, then we cannot create the array. Elements in the array are accessed via their indices. Accessing an element at any index takes the same constant time. But inserting/deleting any element into/from an array takes a lot of time and space.

Linked lists on the other hand dont need contiguous memory region. They have nodes with pointers to other nodes. These can be allocated from any memory address. Inserting/Deleting any node is simply playing with pointers. But accessing any element needs traversal till that index as the memory address is not known.

Stacks are special linear data structures which follow LIFO principle (Last In First Out). Insertion of elements is done via push() operation and deletion via pop() operation.

Queues are similar to stacks except the fact that they follow FIFO principle (First In First Out). Insertion of elements is done via enqueue() operation and deletion via dequeue()