Data structures are the fundamental building blocks of computer programming. They define how data is organized, stored, and manipulated within a program. Understanding data structures is very important for developing efficient and effective algorithms.
In this tutorial, we will explore the most commonly used data structures, including arrays, linked lists, stacks, queues, trees, and graphs.
What is Data Structure?A data structure is a storage that is used to store and organize data. It is a way of arranging data on a computer so that it can be accessed and updated efficiently.
A data structure is not only used for organizing the data. It is also used for processing, retrieving, and storing data. There are different basic and advanced types of data structures that are used in almost every program or software system that has been developed. So we must have good knowledge about data structures.
Get Hands-on With Data Structures and Algorithms
Master fundamental computer science concepts to solve real-world problems and ace coding interview questions with Educative’s interactive course Data Structures and Algorithms in Python. Sign up at Educative.io with the code GEEKS10 to save 10% on your subscription.
Classification of Data StructureClassification of Data StructureLinear Data Structure: Data structure in which data elements are arranged sequentially or linearly, where each element is attached to its previous and next adjacent elements, is called a linear data structure. Example: Array, Stack, Queue, Linked List, etc.Static Data Structure: Static data structure has a fixed memory size. It is easier to access the elements in a static data structure. Example: array.Dynamic Data Structure: In dynamic data structure, the size is not fixed. It can be randomly updated during the runtime which may be considered efficient concerning the memory (space) complexity of the code. Example: Queue, Stack, etc.Non-Linear Data Structure: Data structures where data elements are not placed sequentially or linearly are called non-linear data structures. In a non-linear data structure, we can’t traverse all the elements in a single run only. Examples: Trees and Graphs.Data Structures TutorialIntroduction to Data StructuresArray Data StructureLinked List Data Structure1. Singly Linked List:2. Circular Linked List:3. Doubly Linked List:Matrix Data StructureStack Data StructureQueue Data StructureBinary Tree Data StructureBinary Search Tree Data StructureHeap Data StructureHashing Data StructureGraph Data StructureAdvanced Data Structure1. Advanced Lists:2. Segment Tree Data Structure:3. Trie Data Structure:4. Binary Indexed Tree Data Structure:5. Suffix Array and Suffix Tree:6. AVL Tree:7. Splay Tree:8. B Tree:9. Red-Black Tree:10. K Dimensional Tree:Others Data Structures:Misc:Introduction to Data StructuresWhat is Data Structure: Types, Classifications and ApplicationsIntroduction to Data StructuresCommon operations on various Data StructuresArray Data StructureSearch, insert and delete in an unsorted arraySearch, insert and delete in a sorted arrayWrite a program to reverse an arrayLeaders in an arrayGiven an array A[] and a number x, check for pair in A[] with sum as xMajority ElementFind the Number Occurring Odd Number of TimesLargest Sum Contiguous SubarrayFind the Missing NumberSearch an element in a sorted and pivoted arrayMerge an array of size n into another array of size m+nMedian of two sorted arraysProgram for array rotationReversal algorithm for array rotationBlock swap algorithm for array rotationMaximum sum such that no two elements are adjacentSort elements by frequency | Set 1Count Inversions in an arrayAll Articles on ArrayCoding Practice on ArrayQuiz on ArrayCoding Practice on ArrayRecent Articles on ArrayLinked List Data Structure1. Singly Linked List:Introduction to Linked ListLinked List vs ArrayLinked List InsertionLinked List Deletion (Deleting a given key)Linked List Deletion (Deleting a key at given position)A Programmer’s approach of looking at Array vs. Linked ListFind Length of a Linked List (Iterative and Recursive)How to write C functions that modify head pointer of a Linked List?Swap nodes in a linked list without swapping dataReverse a linked listMerge two sorted linked listsMerge Sort for Linked ListsReverse a Linked List in groups of given sizeDetect and Remove Loop in a Linked ListAdd two numbers represented by linked lists | Set 1Rotate a Linked ListGeneric Linked List in C2. Circular Linked List:Circular Linked List Introduction and Applications,Circular Singly Linked List InsertionCircular Linked List TraversalSplit a Circular Linked List into two halvesSorted insert for circular linked list3. Doubly Linked List:Doubly Linked List Introduction and InsertionDelete a node in a Doubly Linked ListReverse a Doubly Linked ListThe Great Tree-List Recursion Problem.QuickSort on Doubly Linked ListMerge Sort for Doubly Linked ListAll Articles of Linked ListCoding Practice on Linked ListRecent Articles on Linked ListMatrix Data StructureSearch in a row wise and column wise sorted matrixPrint a given matrix in spiral formA Boolean Matrix QuestionPrint unique rows in a given boolean matrixMaximum size square sub-matrix with all 1sPrint unique rows in a given boolean matrixInplace M x N size matrix transpose | UpdatedDynamic Programming | Set 27 (Maximum sum rectangle in a 2D matrix)Strassen’s Matrix MultiplicationCreate a matrix with alternating rectangles of O and XPrint all elements in sorted order from row and column wise sorted matrixGiven an n x n square matrix, find sum of all sub-squares of size k x kCount number of islands where every island is row-wise and column-wise separatedFind a common element in all rows of a given row-wise sorted matrixAll Articles on MatrixCoding Practice on MatrixRecent Articles on Matrix.Stack Data StructureIntroduction to StackInfix to Postfix Conversion using StackEvaluation of Postfix ExpressionReverse a String using StackImplement two stacks in an arrayCheck for balanced parentheses in an expressionNext Greater ElementReverse a stack using recursionSort a stack using recursionThe Stock Span ProblemDesign and Implement Special Stack Data StructureImplement Stack using QueuesDesign a stack with operations on middle elementHow to efficiently implement k stacks in a single array?Sort a stack using recursionAll Articles on StackCoding Practice on Stack\Recent Articles on StackQueue Data StructureQueue Introduction and Array ImplementationLinked List Implementation of QueueApplications of Queue Data StructurePriority Queue IntroductionDeque (Introduction and Applications)Implementation of Deque using circular arrayImplement Queue using StacksFind the first circular tour that visits all petrol pumpsMaximum of all subarrays of size kAn Interesting Method to Generate Binary Numbers from 1 to nHow to efficiently implement k Queues in a single array?All Articles on QueueCoding Practice on QueueRecent Articles on QueueBinary Tree Data StructureBinary Tree IntroductionBinary Tree PropertiesTypes of Binary TreeHandshaking Lemma and Interesting Tree PropertiesEnumeration of Binary TreeApplications of tree data structureTree TraversalsBFS vs DFS for Binary TreeLevel Order Tree TraversalDiameter of a Binary TreeInorder Tree Traversal without RecursionInorder Tree Traversal without recursion and without stack!Threaded Binary TreeMaximum Depth or Height of a TreeIf you are given two traversal sequences, can you construct the binary tree?Clone a Binary Tree with Random PointersConstruct Tree from given Inorder and Preorder traversalsMaximum width of a binary treePrint nodes at k distance from rootPrint Ancestors of a given node in Binary TreeCheck if a binary tree is subtree of another binary treeConnect nodes at same levelAll articles on Binary TreeCoding Practice on Binary TreeRecent Articles on TreeBinary Search Tree Data StructureSearch and Insert in BSTDeletion from BSTMinimum value in a Binary Search TreeInorder predecessor and successor for a given key in BSTCheck if a binary tree is BST or notLowest Common Ancestor in a Binary Search Tree.Inorder Successor in Binary Search TreeFind k-th smallest element in BST (Order Statistics in BST)Merge two BSTs with limited extra spaceTwo nodes of a BST are swapped, correct the BSTFloor and Ceil from a BSTIn-place conversion of Sorted DLL to Balanced BSTFind a pair with given sum in a Balanced BSTTotal number of possible Binary Search Trees with n keysMerge Two Balanced Binary Search TreesBinary Tree to Binary Search Tree ConversionAll Articles on Binary Search TreeCoding Practice on Binary Search TreeRecent Articles on BSTHeap Data StructureBinary HeapWhy is Binary Heap Preferred over BST for Priority Queue?Heap SortK’th Largest Element in an arraySort an almost sorted arrayBinomial HeapFibonacci HeapTournament Tree (Winner Tree) and Binary HeapAll Articles on HeapCoding Practice on HeapRecent Articles on HeapHashing Data StructureHashing IntroductionSeparate Chaining for Collision HandlingOpen Addressing for Collision HandlingPrint a Binary Tree in Vertical OrderFind whether an array is subset of another arrayUnion and Intersection of two Linked ListsFind a pair with given sumCheck if a given array contains duplicate elements within k distance from each otherFind Itinerary from a given list of ticketsFind number of Employees Under every EmployeeAll Articles on HashingCoding Practice on HashingRecent Articles on HashingGraph Data StructureGraph and its representationsBreadth First Traversal for a GraphDepth First Traversal for a GraphApplications of Depth First SearchApplications of Breadth First TraversalDetect Cycle in a Directed GraphDetect Cycle in Graph using DSUDetect cycle in an Undirected Graph using DFSLongest Path in a Directed Acyclic GraphTopological SortingCheck whether a given graph is Bipartite or notSnake and Ladder ProblemMinimize Cash Flow among a given set of friends who have borrowed money from each otherBoggle (Find all possible words in a board of characters)Assign directions to edges so that the directed graph remains acyclicAll Articles on Graph Data StructureCoding Practice on GraphRecent Articles on GraphAdvanced Data Structure1. Advanced Lists:Memory efficient doubly linked listXOR Linked List – A Memory Efficient Doubly Linked List | Set 1XOR Linked List – A Memory Efficient Doubly Linked List | Set 2Skip List | Set 1 (Introduction)Self Organizing List | Set 1 (Introduction)Unrolled Linked List | Set 1 (Introduction)2. Segment Tree Data Structure:Segment Tree | Set 1 (Sum of given range)Segment Tree | Set 2 (Range Minimum Query)Lazy Propagation in Segment TreePersistent Segment Tree | Set 1 (Introduction)All Articles on Segment Tre
3. Trie Data Structure:Trie | (Insert and Search)Trie | (Delete)Longest prefix matching – A Trie based solution in JavaPrint unique rows in a given boolean matrixHow to Implement Reverse DNS Look Up Cache?How to Implement Forward DNS Look Up Cache?All Articles on Trie
4. Binary Indexed Tree Data Structure:Binary Indexed TreeTwo Dimensional Binary Indexed Tree or Fenwick TreeBinary Indexed Tree : Range Updates and Point QueriesBinary Indexed Tree : Range Update and Range QueriesAll Articles on Binary Indexed Tree
5. Suffix Array and Suffix Tree:Suffix Array IntroductionSuffix Array nLogn Algorithmkasai’s Algorithm for Construction of LCP array from Suffix ArraySuffix Tree IntroductionUkkonen’s Suffix Tree Construction – Part 1Ukkonen’s Suffix Tree Construction – Part 2Ukkonen’s Suffix Tree Construction – Part 3Ukkonen’s Suffix Tree Construction – Part 4,Ukkonen’s Suffix Tree Construction – Part 5Ukkonen’s Suffix Tree Construction – Part 6Generalized Suffix TreeBuild Linear Time Suffix Array using Suffix TreeSubstring CheckSearching All PatternsLongest Repeated Substring,Longest Common Substring, Longest Palindromic SubstringAll Articles on Suffix Tree
6. AVL Tree:AVL Tree | Set 1 (Insertion)AVL Tree | Set 2 (Deletion)AVL with duplicate keys7. Splay Tree:Splay Tree | Set 1 (Search)Splay Tree | Set 2 (Insert)8. B Tree:B-Tree | Set 1 (Introduction)B-Tree | Set 2 (Insert)B-Tree | Set 3 (Delete)9. Red-Black Tree:Red-Black Tree IntroductionRed Black Tree Insertion.Red-Black Tree DeletionProgram for Red Black Tree InsertionAll Articles on Self-Balancing BSTs
10. K Dimensional Tree:KD Tree (Search and Insert)K D Tree (Find Minimum)K D Tree (Delete)Others Data Structures:Treap (A Randomized Binary Search Tree)Ternary Search TreeInterval TreeImplement LRU CacheSort numbers stored on different machinesFind the k most frequent words from a fileGiven a sequence of words, print all anagrams togetherTournament Tree (Winner Tree) and Binary HeapDecision Trees – Fake (Counterfeit) Coin Puzzle (12 Coin Puzzle)Spaghetti StackData Structure for Dictionary and Spell Checker?Cartesian TreeCartesian Tree SortingSparse SetCentroid Decomposition of TreeGomory-Hu TreeRecent Articles on Advanced Data Structures.Misc:Commonly Asked Data Structure Interview Questions | Set 1A data structure for n elements and O(1) operationsExpression TreeH
harendrakumar123ImprovePrevious ArticleAdvanced Data StructuresNext ArticleSearching Algorithms