Types of Data Structure

    A data structure is basically used to collect and organize the data on which we are going to perform the operations. For example, we all know what an array is; it is one of the most-used data structures.

    We use arrays to collect similar data types and organize them in a linear structure. Similar to object-oriented programming, we use a class to store different kinds of data types and functions (methods). In programming, we require different types of data structures in order to make an effective program. In this post, we are going to discuss them.

    Let's begin!

    Types of Data Structures

    Data structures are broadly of two types:

    1. Primitive
    2. Non-primitive

    Primitive Data Structures

    Primitive data structures are further classified into the following types:

    1. Integer
    2. (Double) Floating-point Numbers
    3. Character
    4. Pointer

    What are Primitive Data Structures?

    These types of data structures are the basic data structures, and most of these are built-in in many high-level programming languages. Primitive data structures can be defined as data types present in the programming languages. The main property of a primitive data structure is they can not be further divided, they are elementary.

    Basic Types of Primitive Data Structures:

    • Integer: The integer holds all the integer values, basically all the positive and negative numbers without decimals. e.g. 11
    • Floating Points Numbers: Floating point numbers also cover all the real numbers, positive fractions, as well as negative with the decimal point. E.g. = 11.0
    • Character: It holds every character, may it be any number, alphabet, or any special symbol, but it would be represented inside the double or single inverted comma. eg = ’$’
    • Pointers: Pointers hold (point to) the memory address of the variables, pointers, etc.

    Non-Primitive Data Structures

    We can classify all non-primitive data structures into the following categories:

    1. Linear Data Structures
      1. Array
      2. List
      3. Stack
      4. Queue
    2. Non-Linear Data Structures
      1. Tree
      2. Graph
    3. File Data Structures

    What are Non-Primitive Data Structures?

    Non-primitive data structures are the complex data structures we use in programming. Mostly, all the non-primitive data structures are user-defined data structures, though many languages provide built-in support for these data structures, and thus, they are considered user-defined data structures.

    They are derived from primitive data structures.

    Types of Non-Primitive Data Structures:

    As mentioned above, there are 3 types of non-primitive data structures:

    1. Linear Data Structures

    In the linear data structure, elements are stored in a sequential manner.

    Myth-buster: their name doesn't say that they store elements in a linear or contiguous memory location.

    Types of Linear Data Structures

    The linear data structure is further divided into 4 categories:

    • Array: An array is a homogeneous collection of elements. In simple words, an array can store only similar data types at once. An array stores all the elements in a linear sequence and in a contiguous memory location. Due to storing elements in contiguous memory locations, the operation, such as retrieving data elements, is very easy. There are many disadvantages of an array, such as it can only store similar data types at once and is not that memory efficient when it comes to an arbitrary number of elements.
    • List: The functionality of a list is similar to an array. It also stores elements in a linear sequence. List, however, uses dynamic memory allocation to store its elements at different memory locations. Though elements are stored at different memory locations, all are arranged in a sequence and linked with one another.
    • Stack: A stack is similar to a list but follows the LIFO principle to store and retrieve elements. LIFO stands for Last In First Out, which means the element stored last in the stack would be retrieved first. To perform the LIFO principle, the stack uses two operations: push and pop. push() is used to insert an element in the stack, while pop() is used to retrieve one or many.
    • Queues: The queue data structure is just the opposite of the stack since it uses the FIFO principle. FIFO stands for First In, First Out. In a queue, the element stored first in the structure would be retrieved first.
    2. Non-Linear Data Structures

    In a non-linear data structure, the storage of elements doesn't follow a sequential order.

    Types of Non-Linear Data Structures
    • Graph: Used for network representation. A graph data structure basically uses two components: vertices and edges. In the graph, edges are used to connect vertices.
    • Tree: The tree data structure uses a hierarchical form of structure to represent its elements. One of the famous tree data structures is the binary tree. A tree uses a node-like structure to make a hierarchical form, where each node represents a value. The uppermost node of the tree is known as the root node, and the bottom node is known as the leaf node. Tree data structures are the most complex and efficient data structures we use in programming. As such, we use these to solve many real-time problems.
    3. File Data Structures

    A file is a collection of records. Using a file, we can store data in the .txt format. Many programming languages come with a built-in file-handling structure. We can perform read, write, and append operations on files so we can add and retrieve data from them.

    The file is the easiest method of creating and retrieving data, but it is not productive when it comes to handling a huge amount of data.


    Data structures are the most important part of a programming language and, during tech interviews, the favorite topic of the interviewer. That's probably because the ability to choose the right data structure is one of the vital skills a programmer should possess. In a big project or furthering development, especially dealing with huge amounts of data, developers who have complete knowledge of all basic data structures are able to make the best decisions.

    We hope that the aforementioned information helps you gain clarity of the topic.

    Good luck!

    People are also reading: