What is data structures list out linear and non-linear data structures?

Difference between Linear and Non-linear Data Structures

Linear Data Structure:
Data structure where data elements are arranged sequentially or linearly where the elements are attached to its previous and next adjacent in what is called a linear data structure. In linear data structure, single level is involved. Therefore, we can traverse all the elements in single run only. Linear data structures are easy to implement because computer memory is arranged in a linear way. Its examples are array, stack, queue, linked list, etc.

1. Array

The array is a type of data structure that stores elements of the same type. These are the most basic and fundamental data structures. Data stored in each position of an array is given a positive value called the index of the element. The index helps in identifying the location of the elements in an array.

If supposedly we have to store some data i.e. the price of ten cars, then we can create a structure of an array and store all the integers together. This doesn’t need creating ten separate integer variables. Therefore, the lines in a code are reduced and memory is saved. The index value starts with 0 for the first element in the case of an array.

2. Stack



The data structure follows the rule of LIFO [Last In-First Out] where the data last added element is removed first. Push operation is used for adding an element of data on a stack and the pop operation is used for deleting the data from the stack. This can be explained by the example of books stacked together. In order to access the last book, all the books placed on top of the last book have to be safely removed.

3. Queue

This structure is almost similar to the stack as the data is stored sequentially. The difference is that the queue data structure follows FIFO which is the rule of First In-First Out where the first added element is to exit the queue first. Front and rear are the two terms to be used in a queue.

Enqueue is the insertion operation and dequeue is the deletion operation. The former is performed at the end of the queue and the latter is performed at the start end. The data structure might be explained with the example of people queuing up to ride a bus. The first person in the line will get the chance to exit the queue while the last person will be the last to exit.

4. Linked List

Linked lists are the types where the data is stored in the form of nodes which consist of an element of data and a pointer. The use of the pointer is that it points or directs to the node which is next to the element in the sequence. The data stored in a linked list might be of any form, strings, numbers, or characters. Both sorted and unsorted data can be stored in a linked list along with unique or duplicate elements.

5. Hash Tables

These types can be implemented as linear or non-linear data structures. The data structures consist of key-value pairs.

Non-linear Data Structure:
Data structures where data elements are not arranged sequentially or linearly are called non-linear data structures. In a non-linear data structure, single level is not involved. Therefore, we can’t traverse all the elements in single run only. Non-linear data structures are not easy to implement in comparison to linear data structure. It utilizes computer memory efficiently in comparison to a linear data structure. Its examples are trees and graphs.

1. Trees

A tree data structure consists of various nodes linked together. The structure of a tree is hierarchical that forms a relationship like that of the parent and a child. The structure of the tree is formed in a way that there is one connection for every parent-child node relationship. Only one path should exist between the root to a node in the tree. Various types of trees are present based on their structures like AVL tree, binary tree, binary search tree, etc.

2. Graph

Graphs are those types of non-linear data structures which consist of a definite quantity of vertices and edges. The vertices or the nodes are involved in storing data and the edges show the vertices relationship. The difference between a graph to a tree is that in a graph there are no specific rules for the connection of nodes. Real-life problems like social networks, telephone networks, etc. can be represented through the graphs.

Difference between Linear and Non-linear Data Structures:

S.NO Linear Data Structure Non-linear Data Structure
1. In a linear data structure, data elements are arranged in a linear order where each and every elements are attached to its previous and next adjacent. In a non-linear data structure, data elements are attached in hierarchically manner.
2. In linear data structure, single level is involved. Whereas in non-linear data structure, multiple levels are involved.
3. Its implementation is easy in comparison to non-linear data structure. While its implementation is complex in comparison to linear data structure.
4. In linear data structure, data elements can be traversed in a single run only. While in non-linear data structure, data elements can’t be traversed in a single run only.
5. In a linear data structure, memory is not utilized in an efficient way. While in a non-linear data structure, memory is utilized in an efficient way.
6. Its examples are: array, stack, queue, linked list, etc. While its examples are: trees and graphs.
7. Applications of linear data structures are mainly in application software development. Applications of non-linear data structures are in Artificial Intelligence and image processing.

Article Tags :
Data Structures
Difference Between
Practice Tags :
Data Structures
Read Full Article

Linear vs Non-Linear data structure

What is Data structure?

A data structure is a technique of storing and organizing the data in such a way that the data can be utilized in an efficient manner. In computer science, a data structure is designed in such a way that it can work with various algorithms. A data structure is classified into two categories:

  • Linear data structure
  • Non-linear data structure

Now let's have a brief look at both these data structures.

What is the Linear data structure?

A linear data structure is a structure in which the elements are stored sequentially, and the elements are connected to the previous and the next element. As the elements are stored sequentially, so they can be traversed or accessed in a single run. The implementation of linear data structures is easier as the elements are sequentially organized in memory. The data elements in an array are traversed one after another and can access only one element at a time.

The types of linear data structures are Array, Queue, Stack, Linked List.

Let's discuss each linear data structure in detail.

  • Array: An array consists of data elements of a same data type. For example, if we want to store the roll numbers of 10 students, so instead of creating 10 integer type variables, we will create an array having size 10. Therefore, we can say that an array saves a lot of memory and reduces the length of the code.
  • Stack: It is linear data structure that uses the LIFO [Last In-First Out] rule in which the data added last will be removed first. The addition of data element in a stack is known as a push operation, and the deletion of data element form the list is known as pop operation.
  • Queue: It is a data structure that uses the FIFO rule [First In-First Out]. In this rule, the element which is added first will be removed first. There are two terms used in the queue front end and rear The insertion operation performed at the back end is known ad enqueue, and the deletion operation performed at the front end is known as dequeue.
  • Linked list: It is a collection of nodes that are made up of two parts, i.e., data element and reference to the next node in the sequence.

What is a Non-linear data structure?

A non-linear data structure is also another type of data structure in which the data elements are not arranged in a contiguous manner. As the arrangement is nonsequential, so the data elements cannot be traversed or accessed in a single run. In the case of linear data structure, element is connected to two elements [previous and the next element], whereas, in the non-linear data structure, an element can be connected to more than two elements.

Trees and Graphs are the types of non-linear data structure.

Let's discuss both the data structures in detail.

  • Tree

It is a non-linear data structure that consists of various linked nodes. It has a hierarchical tree structure that forms a parent-child relationship. The diagrammatic representation of a tree data structure is shown below:

For example, the posts of employees are arranged in a tree data structure like managers, officers, clerk. In the above figure, A represents a manager, B and C represent the officers, and other nodes represent the clerks.

  • Graph

A graph is a non-linear data structure that has a finite number of vertices and edges, and these edges are used to connect the vertices. The vertices are used to store the data elements, while the edges represent the relationship between the vertices. A graph is used in various real-world problems like telephone networks, circuit networks, social networks like LinkedIn, Facebook. In the case of facebook, a single user can be considered as a node, and the connection of a user with others is known as edges.

Differences between the Linear data structure and non-linear data structure.

Linear Data structureNon-Linear Data structure
BasicIn this structure, the elements are arranged sequentially or linearly and attached to one another.In this structure, the elements are arranged hierarchically or non-linear manner.
TypesArrays, linked list, stack, queue are the types of a linear data structure.Trees and graphs are the types of a non-linear data structure.
implementationDue to the linear organization, they are easy to implement.Due to the non-linear organization, they are difficult to implement.
TraversalAs linear data structure is a single level, so it requires a single run to traverse each data item.The data items in a non-linear data structure cannot be accessed in a single run. It requires multiple runs to be traversed.
ArrangementEach data item is attached to the previous and next items.Each item is attached to many other items.
LevelsThis data structure does not contain any hierarchy, and all the data elements are organized in a single level.In this, the data elements are arranged in multiple levels.
Memory utilizationIn this, the memory utilization is not efficient.In this, memory is utilized in a very efficient manner.
Time complexityThe time complexity of linear data structure increases with the increase in the input size.The time complexity of non-linear data structure often remains same with the increase in the input size.
ApplicationsLinear data structures are mainly used for developing the software.Non-linear data structures are used in image processing and Artificial Intelligence.
Next TopicArray vs Linked List


← prev next →


Difference between Linear and Non-linear Data Structures

Data StructureDatabaseData Storage

Content: Linear and Non-linear Data Structure

    1. Comparison Chart
    2. Definition
    3. Key Differences
    4. Conclusion

Comparison Chart

Basis for comparisonLinear data structureNon-linear data structure
BasicThe data items are arranged in an orderly manner where the elements are attached adjacently.It arranges the data in a sorted order and there exists a relationship between the data elements.
Traversing of the dataThe data elements can be accessed in one time [single run].Traversing of data elements in one go is not possible.
Ease of implementationSimplerComplex
Levels involvedSingle levelMultiple level
ExamplesArray, queue, stack, linked list, etc.Tree and graph.
Memory utilizationIneffectiveEffective

Definition of Linear Data Structure

The data structure is considered to be linear if the data elements construct a sequence of a linear list. The elements are adjacently attached to each other and in a specified order. It consumes linear memory space, the data elements are required to store in a sequential manner in the memory. While implementing the linear data structure the necessary amount of memory is declared previously. It does not make a good utilization of memory and result in memory wastage. The data element are visited sequentially where only a single element can be directly reached.

The examples included in the linear data structure are array, stack, queue, linked list, etc. An array is a group of a definite number of homogeneous elements or data items. Stack and queue are also an ordered collection of the elements like an array but there is a special condition where stack follows LIFO [Last in first out] order and queue employ FIFO [First in first out] to insert and delete the elements. Lists can be defined as a set of variable number data items.

Definition of Non-linear Data Structure

Non-linear data structure does not arrange the data consecutively rather it is arranged in sorted order. In this, the data elements can be attached to more than one element exhibiting the hierarchical relationship which involves the relationship between the child, parent, and grandparent. In the non-linear data structure, the traversal of data elements and insertion or deletion are not done sequentially.

The non-linear data structure utilizes the memory efficiently and does not require the memory declaration in advance. There are the two common examples of the non-linear data structure – tree and graph. A tree data structure organizes and stores the data elements in a hierarchical relationship.

Difference between Linear and Non-Linear Data Structure in Tabular Form

Contents

  • 1 Difference between Linear and Non-Linear Data Structure in Tabular Form
    • 1.1 Comparison Between Linear and Non-Linear Data Structure
    • 1.2 Comparison Chart
    • 1.3 Linear data structures
    • 1.4 Nonlinear data structures
  • 2 More Difference

Comparison Between Linear and Non-Linear Data Structure

  • A data structure is simply the implementation of Abstract Data Types using suitable algorithms.
  • Mainly Data Structures are classified into two categories
    1. Linear
    2. Non-Linear
Data Structure

Comparison Chart

Linear Data StructureNon-Linear Data Structure
Every item is related to its previous and next timeEvery item is attached with many other items.
Data is arranged in a linear sequence.Data is not arranged in sequence
Data items can be traversed in a single run.Data cannot be traversed in a single run.
Examples: Linked List, Stack, Queue, etc.Examples: Trees, graphs, etc.
Implementation is easy.Implementation is difficult.
Memory utilization IneffectiveMemory utilization Effective




Linear data structures

  • A data structure is said to be linear if its elements are connected in a linear fashion by means of logical or in sequence memory locations.
  • There are two ways to represent a linear data structure in memory,
    • Static memory allocation
    • Dynamic memory allocation
  • The possible operations on the linear data structure are Traversal, Insertion, Deletion, Searching, Sorting and Merging.
  • Examples of Linear Data Structure are Stack and Queue.
  • Stack: Stack is a data structure in which insertion and deletion operations are performed at one end only.
    • The insertion operation is referred to as ‘PUSH’ and deletion operation is referred to as ‘POP’ operation.
    • A stack is also called as Last in First out [LIFO] data structure.
  • Queue: The data structure which permits the insertion at one end and Deletion at another end, known as Queue.
    • The end at which deletion occurs is known as FRONT end and another end at which insertion occurs is known as a REAR end
    • A queue is also called a First in First out [FIFO] data structure.

Nonlinear data structures

  • Nonlinear data structures are those data structures in which data items are not arranged in a sequence.
  • Examples of Non-linear Data Structure are Tree and Graph.
  • Tree: A tree can be defined as a finite set of data items [nodes] in which data items are arranged in branches and sub-branches according to requirements.
    • Trees represent the hierarchical relationship between various elements
    • Tree consists of nodes connected by an edge, the node represented by a circle and edge lives connecting to the circle.
  • Graph: Graph is a collection of nodes [Information] and connecting edges [Logical relation] between nodes.
    • A tree can be viewed as a restricted graph.
    • Graphs have many types:
      • Un-directed Graph
      • Directed Graph
      • Mixed Graph
      • Multi-Graph
      • Simple Graph
      • Null Graph
      • Weighted Graph




Data Structure and Types

In this article, you will learn about data strucrture and its types.

What is The Difference Between Linear And Non Linear Data Structure?

The data structure means relationship between the multiple data. It is a simple kind of technique to manage, organize, and efficiently sort the data. It includes suitable algorithms to implement abstract data types.

There are two categories of data structure. One is a linear data structure, and another is a non-linear data structure.

In the real-life, linear data structure is used to develop software, and non-linear data structure is used in image processing and artificial intelligence.

Every programmer should have data structure knowledge and we will get it through this article.

Linear Data Structure

It is a type of data structure where the arrangement of the data follows a linear trend. The data elements are arranged linearly such that the element is directly linked to its previous and the next elements. As the elements are stored linearly, the structure supports single-level storage of data. And hence, traversal of the data is achieved through a single run only.

Characteristics

  • It is a type of data structure where data is stored and managed in a linear sequence.
  • Data elements in the sequence are linked to one after the other.
  • Implementation of the linear structure of data in a computer’s memory is easy as the data is organized sequentially.
  • Array, queue. Stack, linked list, etc. are examples of this type of structure.
  • The data elements stored in the data structure have only one relationship.
  • Traversal of the data elements can be carried out in a single run as the data elements are stored in a single level.
  • There is poor utilization of the computer memory if a structure storing data linearly is implemented.
  • With the increase in the size of the data structure, the time complexity of the structure increases.

These structures can therefore be summarized as a type of data structure where the elements are stored sequentially and follow the order where:

  • Only one first element is present which has one next element.
  • Only one last element is present which has one previous element.
  • All the other elements in the data structure have a previous and a next element

List of data structure in a linear type of data structure

1. Array

The array is that type of structure that stores homogeneous elements at memory locations which are contiguous. The same types of objects are stored sequentially in an array. The main idea of an array is that multiple data of the same type can be stored together. Before storing the data in an array, the size of the array has to be defined. Any element in the array can be accessed or modified and the elements stored are indexed to identify their locations.

An array can be explained with the help of a simple example of storing the marks for all the students in a class. Suppose there are 20 students, then the size of the array has to be mentioned as 20. Marks of all the students can then be stored in the created array without the need for creating separate variables for marks for every student. Simple traversal of the array can lead to the access of the elements.

2. Linked list

The linked list is that type of data structure where separate objects are stored sequentially. Every object stored in the data structure will have the data and a reference to the next object. The last node of the linked list has a reference to null. The first element of the linked list is known as the head of the list. There are many differences between a linked list to the other types of data structures. These are in terms of memory allocation, the internal structure of the data structure, and the operations carried on the linked list.

Getting to an element in a linked list is a slower process compared to the arrays as the indexing in an array helps in locating the element. However, in the case of a linked list, the process has to start from the head and traverse through the whole structure until the desired element is reached. In contrast to this, the advantage of using linked lists is that the addition or deletion of elements at the beginning can be done very quickly.

There are three types of linked lists:

  • Single Linked List: This type of structure has the address or the reference of the next node stored in the current node. Therefore, a node which at the last has the address and reference as a NULL. Example: A->B->C->D->E->NULL.
  • A Double Linked List: As the name suggests, each node has two references associated with it. One reference directs to the previous node while the second reference points to the next node. Traversal is possible in both directions as reference is available for the previous nodes. Also, explicit access is not required for deletion. Example: NULLNULL.
  • Linked List which is circular: The nodes in a circular linked list are connected in a way that a circle is formed. As the linked list is circular there is no end and hence no NULL. This type of linked list can follow the structure of both singly or doubly. There is no specific starting node and any node from the data can be the starting node. The reference of the last node points towards the first node. Example: A->B->C->D->E.

Properties of a linked list are:

    • Access time: O[n]
    • Searching time: O[n]
    • Adding element: O[1]
  • Deleting an Element : O[1]

3. Stack

The stack is another type of structure where the elements stored in the data structure follow the rule of LIFO [last in, first out] or FILO [First In Last Out]. Two types of operations are associated with a stack i.e. push and pop. Push is used when an element has to be added to the collection and pop is used when the last element has to be removed from the collection. Extraction can be carried out for only the last added element.

Properties of a stack are:

  • Adding element: O[1]
  • deleting element: O[1]
  • Accessing Time: O[n] [Worst Case]
  • Only one end allows inserting and deleting an element.

Examples of the stack include the removal of recursion. In scenarios where a word has to be reversed, or while using editors when the word that was last typed will be removed first [using an undo operation], stacks are used. If you want to try interesting data structure projects, click to read this article.

4. Queue

Queue is the type of data structure where the elements to be stored follow the rule of First In First Out [FIFO]. The particular order is followed for performing the required operations over the elements. The difference of a queue from that of a stack lies in the removal of an element, where the most recently added object is removed first in a stack. Whereas, in the case of a queue, the element that was added first is removed first.

Both the end of the data structure is used for the insertion and the removal of data. The two main operations governing the structure of the queue are enqueue, and dequeue. Enqueue refers to the process where inserting an element is allowed to the collection of data and dequeue refers to the process where removal of elements is allowed, which is the first element in the queue in this case.

Properties of a queue are:

  • Inserting an element: O[1]
  • Deleting an element: O[1]
  • Accessing Time: O[n]

Example of the queue: Similar to those queues made while waiting for the bus or anywhere, the data structure too follows the same pattern. We can imagine a person waiting for the bus and standing at the first position as the person that came to the queue first. This person will be the first one who will get onto a bus, i.e. exit the queue. Queues are applied when multiple users are sharing the same resources and they have to be served on the basis of who has come first on the server.

Video liên quan

Bài Viết Liên Quan

Bài mới nhất

Chủ Đề