Data Structures Complete Guide 2026 โ€” Arrays, Linked Lists, Stacks, Queues & Trees Explained
๐Ÿ“ฆ Complete DSA Masterclass

Data Structures Explained:
Arrays to Trees โ€” Full Guide 2026

Everything you need to master Data Structures โ€” with code examples, Big-O complexity, real-world use cases, GATE PYQs, and interview tips. Zero fluff.

๐Ÿ“… Updated June 2026 โฑ ~15 min read ๐ŸŽฏ GATE + Placements ๐Ÿ’ป Code in C & Python ๐Ÿซ For CSE Students

Data Structures are the building blocks of every software system you have ever used โ€” from Google Search to WhatsApp, from your ATM machine to Swiggy’s delivery algorithm. If you are a Computer Science student, understanding data structures is not optional โ€” it is the single most tested skill in GATE CSE, TCS, Infosys, Wipro, and FAANG interviews.

This guide takes you from the very beginning โ€” what a data structure is โ€” all the way through Arrays, Linked Lists, Stacks, Queues, and Trees. Each section includes clean code examples, time complexity tables, real-world applications, and actual GATE-style questions. Bookmark this page and come back to it often.

๐Ÿ“
Array
Fixed-size, index-based, O(1) access
๐Ÿ”—
Linked List
Dynamic size, O(1) insert/delete at head
๐Ÿ“š
Stack
LIFO โ€” Last In, First Out
๐ŸŽซ
Queue
FIFO โ€” First In, First Out
๐ŸŒณ
Tree
Hierarchical, O(log n) search in BST

1. What Are Data Structures?

A Data Structure is a way of organizing and storing data in a computer so that it can be accessed and modified efficiently. Think of it like this โ€” data is the raw material (bricks), and a data structure is the architectural blueprint that decides how those bricks are arranged to build something useful.

Every program you write uses at least one data structure. When you store a list of contacts on your phone, that’s an array. When your browser lets you press Back to go to the previous page, that’s a stack. When you stand in a ticket queue at a railway station, that’s a queue in real life โ€” and it works exactly the same way in software.

Linear vs Non-Linear Data Structures

๐Ÿ“ Linear

DefinitionElements in a sequence
TraversalSingle pass possible
ExamplesArray, Stack, Queue, LL
MemoryUsually contiguous

๐ŸŒฟ Non-Linear

DefinitionHierarchical/networked
TraversalMultiple paths exist
ExamplesTrees, Graphs
MemoryNon-contiguous nodes
๐Ÿ’ก Why Does This Matter for GATE & Placements? Programming and Data Structures carries approximately 10โ€“13 marks in GATE CSE โ€” one of the highest weightage subjects. In placement interviews at TCS, Infosys, Wipro, Amazon, and Google, DSA is the primary test of your coding ability. Nail this, and you are halfway there.

2. Arrays โ€” The Foundation of Data Structures

An array is a collection of elements of the same data type stored in contiguous memory locations. Each element is identified by an index (position), starting from 0. If the base address is 1000 and each integer takes 4 bytes, then arr[3] is at address 1000 + (3 ร— 4) = 1012.

Arrays are the simplest and most widely used data structure. Almost every other data structure is either built on top of arrays or compared against them.

  Index:  [  0  ] [  1  ] [  2  ] [  3  ] [  4  ]
  Value:  [ 10  ] [ 25  ] [ 37  ] [ 48  ] [ 56  ]
          โ†‘
      Base Address (e.g. 1000)

  arr[2] โ†’ Address = 1000 + (2 ร— 4) = 1008  โ†’  value = 37
        
// One-dimensional array in memory

Array Operations with Code (C)

C array_basics.c
// Declare and initialize an array
int arr[5] = {10, 25, 37, 48, 56};

// Access โ€” O(1): direct index calculation
printf("%d\n", arr[2]);   // Output: 37

// Linear Search โ€” O(n)
for (int i = 0; i < 5; i++) {
    if (arr[i] == 48) {
        printf("Found at index %d\n", i);
        break;
    }
}

// Insertion at end โ€” O(1) if space available
// Insertion in middle โ€” O(n) due to shifting
for (int i = 4; i >= 2; i--) {
    arr[i + 1] = arr[i];   // shift right
}
arr[2] = 99;              // insert 99 at index 2

Time Complexity: Arrays

OperationAverage CaseWorst CaseExplanation
Access by indexO(1)O(1)Direct formula: base + index ร— size
Search (unsorted)O(n)O(n)Must check every element
Search (sorted, Binary)O(log n)O(log n)Divide and conquer
Insert at endO(1)O(1)No shifting needed
Insert in middleO(n)O(n)Elements must shift right
Delete from middleO(n)O(n)Elements must shift left
SpaceO(n)n contiguous blocks required

Real-World Applications of Arrays

Image pixels storage Spreadsheet rows & columns Sorting algorithms (QuickSort, MergeSort) Matrix multiplication Implementing other DS (Stack, Queue) DNA sequence analysis
โš ๏ธ Array Limitation โ€” Fixed Size In C, arrays have a fixed size declared at compile time. If you don’t know the data size in advance, use dynamic arrays (like vector in C++ or list in Python) or switch to a Linked List for truly flexible sizing.

๐ŸŽฏ GATE Exam Tip โ€” Arrays

Arrays are tested heavily in GATE โ€” expect 2โ€“3 questions per year. Focus on: address calculation formulas for 1D and 2D arrays, time complexity of search operations, and questions on row-major vs column-major order.

GATE CSE 2019 โ€” Typical Pattern An array A[1..10] is stored in row-major order with base address 100 and each element size 4 bytes. What is the address of A[4][6] in a 2D array A[10][10]?
Formula: Base + [(iโ€“1)ร—Cols + (jโ€“1)] ร— Size

3. Linked Lists โ€” Dynamic Memory Allocation

A Linked List is a linear data structure where elements (called nodes) are stored at non-contiguous memory locations. Each node contains two parts: the data and a pointer (link) to the next node. Unlike arrays, linked lists do not require a predefined size โ€” memory is allocated dynamically as new nodes are added.

  Singly Linked List:

  [HEAD]
    |
  [ 10 | โ†’] โ”€โ”€โ†’ [ 25 | โ†’] โ”€โ”€โ†’ [ 37 | โ†’] โ”€โ”€โ†’ [ 48 | NULL]
   Node 1          Node 2        Node 3        Node 4 (Tail)

  Doubly Linked List:

  NULL โ†โ”€ [โ† | 10 | โ†’] โ†โ”€โ”€โ†’ [โ† | 25 | โ†’] โ†โ”€โ”€โ†’ [โ† | 37 | โ†’ ] โ”€โ”€โ†’ NULL
        
// Each node: data + next pointer (singly) or prev + data + next (doubly)

Node Structure & Basic Operations (C)

C linked_list.c
// Define a Node
struct Node {
    int data;
    struct Node* next;
};

// Insert at beginning โ€” O(1)
struct Node* insertAtHead(struct Node* head, int val) {
    struct Node* newNode = malloc(sizeof(struct Node));
    newNode->data = val;
    newNode->next = head;   // new node points to old head
    return newNode;           // new node becomes new head
}

// Search โ€” O(n) โ€” must traverse from head
int search(struct Node* head, int val) {
    int pos = 0;
    while (head != NULL) {
        if (head->data == val) return pos;
        head = head->next;
        pos++;
    }
    return -1;  // not found
}

Types of Linked Lists

๐Ÿ”— Singly

DirectionForward only
Memory1 pointer/node
UseStacks, basic lists

๐Ÿ”„ Doubly

DirectionForward + Backward
Memory2 pointers/node
UseBrowser history, Deque

๐Ÿ” Circular

DirectionLast โ†’ First (loop)
Memory1โ€“2 pointers/node
UseRound-robin CPU scheduling

Array vs Linked List โ€” Quick Comparison

FeatureArrayLinked List
Memory layoutContiguousNon-contiguous (scattered)
SizeFixed at declarationDynamic (grows/shrinks)
Access by indexO(1) โ€” DirectO(n) โ€” Traverse
Insert at beginningO(n) โ€” Shift neededO(1) โ€” Update pointer
Insert at endO(1) โ€” If space existsO(n) โ€” Reach tail first
SearchO(n) โ€” LinearO(n) โ€” Linear
Cache efficiencyHigh (locality)Low (scattered)
Memory overheadLowExtra pointer per node

๐ŸŽฏ GATE Exam Tip โ€” Linked Lists

GATE frequently asks questions on: finding the middle node, detecting cycles (Floyd’s algorithm), reversing a linked list, and merging two sorted linked lists. Practice these operations until you can write them from memory.

Classic GATE Pattern “In a singly linked list, the time to delete a node given only a pointer to that node (not its predecessor) is ___.”
Answer: O(1) โ€” Copy next node’s data into current, then delete next node.

4. Stacks โ€” Last In, First Out (LIFO)

A Stack is a linear data structure that follows the LIFO principle โ€” the last element inserted is the first one to be removed. Imagine a stack of plates: you always place a new plate on top, and you always remove the top plate first. You cannot access any plate below without removing the ones above it.

Stacks are the backbone of how computers execute function calls, evaluate expressions, and manage undo operations.

  PUSH 10, PUSH 20, PUSH 30:        POP:

  |    |         |    |             |    |
  | 30 | โ† TOP   | 30 | removed     | 20 | โ† new TOP
  | 20 |         | 20 |             | 10 |
  | 10 |         | 10 |             |    |
  |____|         |____|             |____|

  push(x) โ†’ add to TOP             pop() โ†’ remove from TOP
  peek()  โ†’ see TOP without removing
        
// All operations happen at the TOP โ€” O(1)

Stack Implementation (Array-based, C)

C stack.c
int stack[100];
int top = -1;  // -1 means empty stack

// Push โ€” O(1)
void push(int x) {
    if (top == 99) { printf("Stack Overflow!\n"); return; }
    stack[++top] = x;
}

// Pop โ€” O(1)
int pop() {
    if (top == -1) { printf("Stack Underflow!\n"); return -1; }
    return stack[top--];
}

// Peek โ€” O(1)
int peek() {
    return (top == -1) ? -1 : stack[top];
}

Real-World Applications of Stacks

Function call stack (recursion) Browser Back button Undo/Redo in text editors Infix โ†’ Postfix expression conversion Balanced parentheses checking DFS graph traversal
โœ… Classic Stack Problem โ€” Balanced Parentheses Given a string like “{[()]}”, use a stack to check if brackets are balanced: push every opening bracket. For every closing bracket, check if the top of the stack is the matching opener. If yes, pop it. At the end, if the stack is empty โ†’ balanced. This is one of the most frequently asked coding questions in placement drives.

๐ŸŽฏ GATE Exam Tip โ€” Stacks

GATE loves postfix/prefix expression evaluation, stack simulation questions, and recursion-based stack frame analysis. The key insight: every recursive function call pushes a frame onto the call stack โ€” so recursion depth = stack size.

GATE CSE Pattern “Evaluate the postfix expression: 5 3 2 * + 4 -“
Process: push 5 โ†’ push 3 โ†’ push 2 โ†’ pop 2,3, push 3ร—2=6 โ†’ pop 6,5, push 5+6=11 โ†’ push 4 โ†’ pop 4,11, push 11โ€“4=7

5. Queues โ€” First In, First Out (FIFO)

A Queue is a linear data structure that follows the FIFO principle โ€” the first element inserted is the first one to be removed. Think of a line at a movie theatre: the person who arrives first gets served first. New people join at the rear (back), and people leave from the front.

  Enqueue (add to REAR):          Dequeue (remove from FRONT):

  FRONT                   REAR    FRONT                   REAR
    โ†“                       โ†“       โ†“                       โ†“
  [ 10 ][ 20 ][ 30 ][ 40 ][ 50 ]  [ 20 ][ 30 ][ 40 ][ 50 ]
  โ† removes here      adds here โ†’      10 is removed โ†’
        
// Enqueue at REAR = O(1) | Dequeue from FRONT = O(1)

Types of Queues

๐Ÿ“‹ Simple Queue

RuleFIFO strictly
ProblemWasted space after dequeue

๐Ÿ” Circular Queue

RuleFIFO + rear wraps around
BenefitReuses freed space

โšก Priority Queue

RuleHighest priority exits first
Used inDijkstra’s, CPU scheduling

โ†”๏ธ Deque

RuleInsert/delete at BOTH ends
Used inSliding window problems
Python queue_example.py
from collections import deque

# Python's deque is the optimal Queue implementation
q = deque()

# Enqueue โ€” O(1)
q.append(10)
q.append(20)
q.append(30)

# Dequeue โ€” O(1)
removed = q.popleft()   # removes 10
print(removed)            # Output: 10

# Peek โ€” O(1)
print(q[0])               # Output: 20 (front element)

Real-World Applications of Queues

CPU process scheduling (FCFS) BFS graph/tree traversal Printer job spooling WhatsApp message queue Network packet handling Ticket booking systems

6. Trees โ€” Hierarchical Data Structures

A Tree is a non-linear hierarchical data structure consisting of nodes connected by edges. Unlike linear data structures (arrays, linked lists), trees represent relationships with a parent-child hierarchy. A tree with n nodes has exactly nโ€“1 edges.

The root is the topmost node. Nodes with no children are called leaf nodes. The height of a tree is the length of the longest path from root to a leaf.

        Tree Terminology:

              [A]          โ† Root (Level 0)
             /   \
           [B]   [C]       โ† Level 1 (children of A)
          / \      \
        [D] [E]    [F]     โ† Level 2 (D,E children of B; F child of C)
                   / \
                 [G] [H]   โ† Leaf nodes (no children)

  โ€ข A is parent of B, C       โ€ข D, E, G, H are leaf nodes
  โ€ข Height of tree = 3        โ€ข Depth of F = 2
  โ€ข B is an internal node     โ€ข Degree of B = 2 (has 2 children)
        
// Tree: n nodes โ†’ nโ€“1 edges always

Binary Tree โ€” The Most Important Type

A Binary Tree is a tree where every node has at most 2 children โ€” commonly called the left child and right child. Binary trees are foundational because most tree-based data structures (BST, Heap, AVL) are binary trees with additional constraints.

Tree Traversals โ€” The Big Three

Traversal means visiting every node exactly once. The three main traversal methods differ in when you visit the root relative to the left and right subtrees:

TraversalOrderPatternUse Case
InorderLeft โ†’ Root โ†’ RightLโ€“Nโ€“RBST sorted output
PreorderRoot โ†’ Left โ†’ RightNโ€“Lโ€“RCopy a tree, prefix expressions
PostorderLeft โ†’ Right โ†’ RootLโ€“Rโ€“NDelete a tree, postfix expressions
Level OrderLevel by Level (BFS)Use QueueFinding shortest path
C tree_traversal.c
struct Node {
    int data;
    struct Node *left, *right;
};

// Inorder: Left โ†’ Root โ†’ Right โ†’ gives sorted order in BST
void inorder(struct Node* root) {
    if (root == NULL) return;
    inorder(root->left);
    printf("%d ", root->data);
    inorder(root->right);
}

// Preorder: Root โ†’ Left โ†’ Right
void preorder(struct Node* root) {
    if (root == NULL) return;
    printf("%d ", root->data);
    preorder(root->left);
    preorder(root->right);
}

๐ŸŽฏ GATE Exam Tip โ€” Trees

Trees are extremely high-yield for GATE. Practice: given a traversal sequence, reconstruct the tree. Know the properties of complete binary trees, full binary trees, and perfect binary trees. Height of a complete binary tree with n nodes = โŒŠlogโ‚‚nโŒ‹.

GATE CSE Pattern โ€” Traversal Reconstruction “If Inorder = [D, B, E, A, F, C] and Preorder = [A, B, D, E, C, F], find the tree structure.”
Key: First element of Preorder is always the root. Split Inorder around it to find left/right subtrees.

7. Binary Search Trees (BST)

A Binary Search Tree is a binary tree with one crucial additional property: for every node, all values in its left subtree are smaller, and all values in its right subtree are greater. This property enables incredibly efficient search, insert, and delete operations โ€” all in O(log n) on average.

  BST Property: Left < Root < Right

              [50]
             /    \
          [30]    [70]
          /  \    /  \
        [20][40][60] [80]

  Search 40:  50 โ†’ (40<50, go left) โ†’ 30 โ†’ (40>30, go right) โ†’ 40 โœ“
  Path length = 3 steps = O(log n) for balanced BST

  โš  Worst Case: Inserting sorted data [10,20,30,40] โ†’ becomes a linked list
              [10]
               \
              [20]
                \
               [30]   โ† Skewed BST โ€” search degrades to O(n)
                 \
                [40]
        
// BST: O(log n) avg | O(n) worst if skewed โ†’ use AVL or Red-Black Tree to fix

BST Operations โ€” Time Complexity

OperationAverage Case (Balanced)Worst Case (Skewed)
SearchO(log n)O(n)
InsertO(log n)O(n)
DeleteO(log n)O(n)
Inorder traversalO(n)O(n)
Find Min / MaxO(log n)O(n)
SpaceO(n)
๐Ÿ”ฎ Beyond BST โ€” Self-Balancing Trees To guarantee O(log n) in all cases, use self-balancing BSTs: AVL Tree (strict balance factor โ‰ค 1) or Red-Black Tree (used in Java’s TreeMap and C++’s std::map). These automatically restructure after insertions and deletions using rotations.

8. Big-O Complexity Cheatsheet โ€” All Data Structures

This is the table you need to memorize before any placement interview or GATE exam. Know the average and worst-case complexities for every major operation on each data structure.

๐Ÿ“Š Master Complexity Table โ€” Data Structures 2026
Data Structure Access (Avg) Search (Avg) Insert (Avg) Delete (Avg) Space
ArrayO(1)O(n)O(n)O(n)O(n)
Singly Linked ListO(n)O(n)O(1)O(1)O(n)
Doubly Linked ListO(n)O(n)O(1)O(1)O(n)
StackO(n)O(n)O(1)O(1)O(n)
QueueO(n)O(n)O(1)O(1)O(n)
Hash TableN/AO(1)O(1)O(1)O(n)
Binary Search TreeO(log n)O(log n)O(log n)O(log n)O(n)
AVL TreeO(log n)O(log n)O(log n)O(log n)O(n)
Min/Max HeapN/AO(n)O(log n)O(log n)O(n)
๐Ÿšจ Common Mistake in Interviews Hash Table has O(n) worst-case for all operations (when all keys hash to the same bucket โ€” collision). Always mention both average O(1) and worst-case O(n) when discussing Hash Tables. Interviewers specifically check if you know this.

9. Interview & GATE Tips โ€” What Toppers Know

For Placement Interviews (TCS, Infosys, Amazon, Google)

1. Always discuss approach before coding Interviewers evaluate your thought process. Say “I’ll use a stack because this problem needs LIFO order” before writing a single line of code. This shows structured thinking.
2. State Time and Space Complexity after every solution After coding, always say “This runs in O(n log n) time and O(n) space.” If you do not volunteer this, interviewers will ask โ€” and you should always know.
3. Test with edge cases out loud Say: “Let me test this with an empty array, a single element, and a duplicate-heavy input.” This shows maturity and is exactly what senior engineers do in production.

For GATE CSE โ€” Data Structures Strategy

Master these 5 problem types for maximum marks: (1) Address calculation in 1D and 2D arrays โ€” know both row-major and column-major formulas. (2) Linked list pointer manipulation โ€” reversing, finding cycles, merging sorted lists. (3) Stack-based expression problems โ€” infix/postfix conversion and evaluation. (4) Tree reconstruction from traversals โ€” given any two traversals, build the tree. (5) BST insertion/deletion/search tracing โ€” draw each step clearly.

๐ŸŽฏ Recommended Practice Resources

GATE Overflow (gateoverflow.in) โ€” solve every DS question from the past 15 years.
GeeksforGeeks DSA โ€” topic-wise practice with detailed explanations.
LeetCode Easy/Medium โ€” for placement coding rounds at TCS, Wipro, Infosys.
EnggPrep.in โ€” use our free tools like the CGPA calculator and grade tracker to stay on top of your academic standing alongside your DSA prep.

Data Structures 2026 Arrays Linked List Stack and Queue Binary Tree BST Time Complexity Big-O Notation GATE CSE DSA Interview C Programming Python DSA

10. Frequently Asked Questions (FAQ)

Arrays store elements in contiguous memory with O(1) random access but O(n) insertion/deletion. Linked Lists store nodes scattered in memory with O(1) insertion at the head but O(n) access by index. Use arrays when you need fast lookups by index; use linked lists when you need frequent insertions or deletions, especially at the beginning.
In a balanced BST, search takes O(log n) on average โ€” you eliminate half the remaining nodes at each step. However, in the worst case (a completely skewed tree, caused by inserting already-sorted data), search degrades to O(n). Self-balancing trees like AVL or Red-Black Trees guarantee O(log n) in all cases.
Start with Arrays โ€” they are the foundation. Once comfortable, move to Linked Lists, then Stacks and Queues (which can be built from arrays or linked lists), and finally Trees. This order matches both the difficulty curve and the typical exam/interview progression for GATE, TCS NQT, Infosys, and campus placements.
A Stack follows LIFO (Last In, First Out) โ€” like a pile of books. The most recently added item is removed first. A Queue follows FIFO (First In, First Out) โ€” like a queue at a counter. The earliest added item leaves first. Stacks are used in function calls and undo features; Queues are used in CPU scheduling and BFS graph traversal.
Programming and Data Structures is one of the highest-weightage subjects in GATE CSE, carrying approximately 10โ€“13 marks out of 100. Questions cover arrays (address calculation), linked lists (pointer operations), stacks (expression evaluation), queues (scheduling), and trees (traversals, BST operations). Mastering this single subject can dramatically improve your GATE rank.
For 2026 placements at TCS, Infosys, Wipro, and product-based companies like Amazon and Flipkart, focus on: Arrays (sorting, searching, sliding window), Linked Lists (reversal, cycle detection), Stacks (bracket matching, expression conversion), Queues (BFS, scheduling), Trees (traversals, height, LCA), and Hash Tables (frequency counting, anagram detection).
EP
EnggPrep.in Team

EnggPrep.in is built for Indian engineering students โ€” free tools, exam guides, and concept articles designed specifically for GATE, placements, and academics. All our content is written and reviewed by engineers who have been through the same journey.

๐ŸŽ“ Stay Ahead with EnggPrep.in

Use our free engineering tools โ€” CGPA Calculator, Attendance Tracker, Grade Calculator, and more โ€” designed specifically for CSE students like you.

Try CGPA Calculator โ†’

Leave a Comment