Data Structure Introduction and Basic Terminologies
A Data Structure is a particular way of organizing, storing, and managing data in a computer so that it can be accessed, modified, processed, and retrieved efficiently.
Browse unit-wise Data Structures notes, explanations, dry runs, diagrams, and implementations. Every published tutorial added from the admin panel automatically appears here with a direct link.
A Data Structure is a particular way of organizing, storing, and managing data in a computer so that it can be accessed, modified, processed, and retrieved efficiently.
Elementary data organization arranges raw facts into a hierarchy from fields to records and files, while C built-in data types define memory size, range, and format.
Algorithm efficiency measures how well an algorithm uses time and space as input size (n) grows, helping compare scalability across different solutions.
Asymptotic notations describe how an algorithm's time or space grows as input size (n) increases. Big O gives an upper bound, Big Omega a lower bound, and Big Theta a tigh
An Abstract Data Type (ADT) defines what operations a data structure supports and their expected behaviour without specifying how they are implemented internally in memory or code.
Arrays store collections of same-type data in contiguous memory, allowing instant, indexed access. While providing fast lookup, they typically have a fixed size determined at creation, making resizing difficult.
A linked list is a linear data structure of nodes linked via pointers or references, allowing dynamic size and easy insertion or deletion without shifting elements.
A Stack is a LIFO Abstract Data Type where elements are added and removed only from the top. Push inserts an item on top (checking overflow), while Pop removes and returns the top item (checking underflow), both running in O(1) time.
In C, an array stack uses a fixed array and top index (fixed size, no pointer overhead). A linked stack uses dynamic nodes and a top pointer (grows dynamically, extra pointer space). Both push and pop run in O(1) time.
Stacks efficiently handle Prefix and Postfix notations, eliminating parentheses and precedence rules. To evaluate a postfix expression, scan left to right: push operands, pop top two for operators, apply the operator, and push the result back.
Recursion uses the call stack (base nd recursive cases); tail recursion does work before the final call. Classic examples: Fibonacci and Towers of Hanoi. Iteration uses loops with lower stack space, while recursion can be clearer but risks stack overflow.
A Queue is a linear FIFO (First-In, First-Out) data structure where elements are added at the rear (enqueue) and removed from the front (dequeue). Common variants include circular, double-ended (deque), and priority queues, typically running in O(1) time.
Searching finds a target key in data. Sequential (linear) search checks items one by one in O(n) time on any list. Indexed sequential search uses an index table to jump blocks faster. Binary search halves a sorted list repeatedly in O(log n) time.
Hashing maps keys via a hash function to array indices for ~O(1) search. Collisions (same index for different keys) are handled by chaining (linked lists/buckets) or open addressing (linear/quadratic probing, double hashing) to probe another slot.
Sorting arranges data elements in a specific order, such as ascending or descending, based on a key. Common algorithms include bubble, selection, insertion, merge, and quick sort, differing in time and space complexity, stability, and suitability for data
Bubble sort is a simple comparison sorting algorithm that repeatedly steps through a list, compares adjacent elements, and swaps them if out of order. After each pass, the largest unsorted element settles at the end. It takes O(n²) average/worst time and
Selection sort divides a list into sorted and unsorted parts, repeatedly finding the minimum (or maximum) element from the unsorted portion and swapping it into place. It runs in O(n²) time across best, average, and worst cases with O(1) space.
Insertion sort builds a sorted list one element at a time by taking each item from the unsorted part and shifting larger sorted elements right to insert it in place. It runs in O(n) best time, O(n²) average/worst time, and O(1) space.
Merge sort is a divide-and-conquer sorting algorithm that splits a list into halves, recursively sorts each half, and merges the sorted halves back together. It guarantees O(n log n) time across best, average, and worst cases with O(n) extra space and is
Quick sort is a divide-and-conquer sorting algorithm that picks a pivot element, partitions the array so smaller items go left and larger items go right, and recursively sorts both sides. It averages O(n log n) time and O(log n) stack space, with O(n²) wo
Bucket sort distributes elements into several ordered buckets based on value ranges, sorts each bucket individually (using insertion sort or another algorithm), and concatenates the buckets. It runs in O(n + k) average time for uniformly distributed data
Heap sort builds a binary heap (max-heap for ascending sort) from the array, repeatedly swaps the root with the last unsorted element, reduces heap size by one, and heapifies the root. It runs in O(n log n) time across all cases with O(1) extra space.
Radix sort is a non-comparison sorting algorithm that sorts integers or fixed-length strings digit by digit or character by character, from least significant to most significant (LSD) or vice versa, using a stable subroutine like counting sort.
A tree is a non-linear hierarchical data structure of nodes connected by edges with a single root node and no cycles. Each node holds data and links to child nodes, supporting efficient searching, sorting, and hierarchical modeling like file systems.
A binary tree is a hierarchical data structure of nodes where each node has at most two children, called the left child and the right child. It supports tree traversals, search trees, and heaps, and can be represented using linked nodes or arrays.
Tree traversal is the process of visiting exactly once every node in a tree data structure. It defines the specific order in which nodes are accessed, typically to update, delete, or display the data they contain.
A binary tree is a hierarchical data structure where each node has at most two children, referred to as the left child and the right child. It is commonly used for efficient searching and sorting, such as in Binary Search Trees and Heaps.