Types of Data Structures | Linear and Non-Linear Data Structures

05 min read

A data structure is a particular way of organizing data in the memory. The main aim of a data structure is to group similar/related items together and bundle them, hence making it easier and efficient to execute the program. Now let us look at the different types of data structures.

A Data Structure is classified into two categories.

  • Linear Data Structure
  • Non-Linear Data Structure

Types of data structures

 

Linear Data Structures Vs Non-Linear Data Structures

Now let us look at the difference between Linear and Non-Linear data structures.

LINEAR DATA STRUCTURE NON-LINEAR DATA STRUCTURE
Data is arranged in a linear fashion in which elements are linked one after the other. Data elements in a non-linear data structure are hierarchically related.
All the data elements can be traversed in one go, but at a time only one element is directly reachable. All the data elements cannot be traversed in one go as the nodes are not visited sequentially.
Linear data structure tends to waste the memory. Efficient utilization of memory.
Linear data structures are easy to implement. Implementation of non-linear data structures is complex.
Array, Queue, Stack, Linked List are linear data structures. Trees, graphs are non-linear data structures.

 
Now let us try to get a basic understanding of each of these linear and non-linear data structures.

  • An Array is a collection of data items having similar data types.
  • Linked list is a collection of nodes, where each node has a data element and a reference to the next node in the sequence.
  • Stack is a FILO (First In Last Out) data structure where the element that is added first will be deleted last.
  • Queue is a FIFO (First in First Out) data structure where the element that added is first will be deleted first.
  • Tree is a collection of nodes where these nodes are arranged hierarchically and form a parent-child relationship.
  • Graph is a collection of a finite number of vertices and edges. Edges connect the vertices and represent the relationship between the vertices that connect these vertices.
POST A NEW COMMENT
     
  • Input (stdin)

    Output (stdout)


    Input (stdin)

    Your Output (stdout)

    Expected Output

    Compiler Message

    Input (stdin)

    2    3

    Your Output (stdout)

    5

    Expected Output

    5

    Compiler Message

    5

    Error