Unit II: Linked Lists and Queues

Table of Contents

1. Introduction to Linked Lists

A Linked List is a linear collection of data elements called nodes. Unlike arrays, elements are not stored in contiguous memory locations. Instead, each node contains two parts:

Advantages Over Arrays


2. Types: Singly, Doubly & Circular

Singly Linked List

The simplest form where each node points only to the next node. The last node's pointer is NULL.

Doubly Linked List (DLL)

Each node contains two pointers: one pointing to the next node and one to the previous node.

Circular Linked List

In this variation, the last node of the list does not point to NULL but points back to the first node (Head).


3. Stack Representation in Lists

Stacks can be implemented using linked lists to overcome the fixed size limitation of arrays.

Normal Representation

The Top of the stack is always the Head of the linked list.

Circular Representation of Stack

Using a circular linked list to represent a stack ensures that the "Top" node points to the bottom-most node, maintaining a closed loop. This is often used in buffer management.


4. Self-Organizing & Skip Lists

Self-Organizing Lists

A list that reorders its elements based on access frequency to improve search time.

Skip Lists

A probabilistic data structure that allows O(log n) search complexity. It consists of multiple layers of linked lists where the bottom layer is a standard list and upper layers act as "express lanes" to skip nodes.


5. Queues: Array & Linked Representation

A Queue is a linear structure following the FIFO (First-In, First-Out) principle.

Array Representation

Uses two pointers: Front (for deletion) and Rear (for insertion).

Warning: In a simple array queue, even if space is available at the front after deletions, you cannot insert more elements if Rear reaches the end. This is solved by Circular Queues.

Linked Representation

Maintains 'Front' and 'Rear' pointers to a linked list.


6. De-queue & Priority Queues

De-queue (Double-Ended Queue)

A generalized queue where elements can be added or removed from either the front or the rear.

Priority Queues

Each element is assigned a priority. Elements with higher priority are dequeued before elements with lower priority, regardless of their arrival order.

Application: CPU Scheduling and Dijkstra's Shortest Path Algorithm.

7. Exam Focus & FAQs

Exam Tips

Frequently Asked Questions

Q: Why is a DLL preferred over a SLL?
DLL allows moving in both directions, making deletions of a given node easier as you have immediate access to the predecessor.

Q: What is a Skip List?
It is a sorted linked list with multiple levels of pointers that allow "skipping" over many elements, providing search speeds comparable to binary search trees.

Mnemonic: Q-FIFO

Remember Q-FIFO: Queues are First-In, First-Out.