Introduction to Data Structures

Data structures is a way of organizing and storing data in a computer so that it can be accessed and used efficiently.

Why do we need Data Structures?

  • Data structures are needed because they provide efficient ways to organize and manipulate data, which is crucial for optimizing memory usage, improving algorithm efficiency, and enhancing overall application performance.

  • Data structures are fundamental to computer science and software development, enabling the creation of scalable and efficient systems.

Advantages of using Data Structures

  • Efficient Data Storage

    • Data structures facilitate the efficient storage and access of data, reducing memory usage and maximizing available resources.

  • Improved Algorithm Efficiency

    • Well-designed data structures can significantly enhance the performance of algorithms by providing faster data access and manipulation.

  • Better Data Organization

    • Data structures provide a way of organizing data in a meaningful and efficient manner, making it easier to access and manipulate. They allow developers to organize their data and present it in a logical manner, resulting in more manageable programs.

  • Code Reusability

    • Data structures enable the creation of reusable code components that can be utilized across different projects, saving development time and effort. Reusable data structures can be used in many different applications, reducing the time and effort required to write and maintain code.

  • Problem Solving

    • Data structures enable programmers to solve complex problems efficiently by providing the right tools for organizing and manipulating data effectively. They provide a way of modeling real-world problems and solving them in a more efficient and elegant manner.

Different kinds of Data Structures

Linear data structures

  • A 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.

  • Examples: array, stack, queue, 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: static array

    • Dynamic data structure

      • In a dynamic data structure, the size is not fixed. The size can be randomly changed during runtime which may be considered efficient concerning the memory (space) complexity of the code [Only required amount of memory can be used, thereby reducing memory wastage].


      • Examples: dynamic array, linked list, stack and queue

Non-linear data structures

  • Data structures where data elements are not placed sequentially or linearly are called non-linear data structures.

  • Examples: tree, graph etc.

Different kinds of data structures

Top 8 Data Structures for coding interviews

Reference - Top 8 Data Structures - Neetcode

  1. Arrays

    • The most fundamental data structure. Arrays are stored contiguously in memory.

  2. Linked Lists

    • These also store an ordered list of elements, but the values are not contiguous in RAM. Linked list nodes have pointers connecting them.

  3. HashMaps

    • Probably the most useful data structure as well. They use a hash function to map keys to indexes within an array. This allows us to have an amortized time of O(1) for most operations.

  4. Queues

    • Typically used to process elements in the same order as they are added. These follow a FIFO (first-in first-out approach). Queues can be double-ended, which allow you to add and remove elements from both the front and the back.

  5. Trees

    • A Binary Tree is an ordered tree data structure where each node is connected to at most two more nodes (called the left and the right child). Being ordered means we can perform DFS and BFS in O(log n) time.

  6. Tries/Prefix Trees

    • Here, each node represents a character in the alphabet and can have at most 26 children. This allows us to save space when inserting words. Tries are useful for auto-complete features and allow us to search for words using their prefix.

  7. Heaps

    • Heaps are a nearly complete binary tree, with potentially the last level being not full. They are implemented with arrays under the hood. Heaps serve as priority queues, and always have the smallest (min-heap) or the largest (max-heap) item stored at the root node.

  8. Graphs

    • A graph is a bunch of nodes (vertices) connected by edges. Linked Lists and Trees are also special type of graphs, but a more general graph can have an arbitrary number of vertices connected to it. A good way to represent graphs in interviews is through an adjacency list.

Last updated