Table of Contents

Toggle# Which of the following data structure is non-linear

- Array
- Linked List
- Stack
- Queue
- Tree
- Graph

**Correct answer is E – Tree and F – Graph**

Before Explaining why option E and F is correct let’s first understand what is linear and Non-linear data structure. A linear data structure is like a straight line because its elements follow a sequence, one after the other. Non-linear means something that is not growing in just one direction.

**Let’s Understand Which of the following data structure is non-linear & why option E & F is the correct answer.**

Let’s first understand Difference between Linear and Non-linear.

**Enroll now and take the first step towards a successful career. ****Click here**** to join our courses today!**

## Difference between Linear and Non-Linear

Linear | Non-Linear |

Follows a sequence | Does not follow a sequence |

Elements are arranged in a single line or sequence | Elements are not arranged in a single line or sequence |

Examples: arrays, linked lists | Examples: trees, graphs |

**Also Read :** Application Of Graph In Data Structure

## What is Array?

An Array is a collection of elements and each element in an array is identified by its index which is also called the position in the array. In data structure, Arrays are used because they allow efficient access to elements based on their index.

In Simple terms we can say An array is like a row of boxes where each box holds a value. Each element in the array has a unique position called an index. Keep one thing in mind: In Array indexing starts from 0.

**For Example – **

In this example:

- We have an array defined as “Scores” that contains five elements.
- Each element is represented by a box.
- The numbers inside the boxes are the values stored in the array.
- The numbers below the boxes represent the indices (indexing) of the elements.
- In arrays, the first item is at position 0, and each next item goes up by one.

So basically from this example it’s clear that an array follows a linear sequence, where the first element comes before the second, the second before the third, and so on.

**That’s why Array is a Linear Data Structure. **

**Also Read :** Garbage collection in Data Structure

## Linked List

**A linked list is a linear data structure **where elements are stored in memory as individual nodes and each node points to the next node in the sequence.

In a linked list, Each node contains two parts. The first node is called the head, and the last node typically points to null, indicating the end of the list.

Also, there are two types of Linked List –

- Single Linked List
- Double Linked List

Example Of Linked List –

- In a linked list, each element is stored in a node.
- Each node contains two parts
- The first node is called the head, and the last node typically points to null, indicating the end of the list.

**Also Read : **Leap Year Program In Python | Is 2024 a Leap Year?

## Stack –

A stack is a linear data structure that follows the Last In, First Out (LIFO) principle, Which means the last element you insert to the stack is the first element you can remove.

Additionally, Stack Follows two operations –

- POP Operation (Removing the top element)
- Push Operation (Adding an element to the top)

Example –

Let’s take an example of books – Initially, the stack is empty.

- We add books to the stack one by one:
- We add “Book 1” to the stack.
- Then, we add “Book 2”.
- Next, we add “Book 3”.

Now, if we want to remove a book, we can only remove the top one. If we remove a book, it will be “Book 3” because it was the last one added.

That’s why a **stack is known as a linear linked list** because it follows a linear arrangement where elements are added and removed from top only.

**Also Read : **How to check for Armstrong Number in Python?

## Queue –

A Queue is a linear data structure that follows the FIFO (First In First Out) principle, Which means that the first element added to the queue will be the first one to be removed.

**For Example – **

Imagine a queue of people waiting for a bus:

Initially, the queue is empty.

People join the queue one by one:

- First Vishal joins
- Then, Kumar joins
- Next, Aliza joins

When the bus comes, the people get on in the same order they lined up.

- Vishal boards the bus first (front of the queue)
- Kumar follows
- Finally, Aliza boards last

In this example:

- “Vishal” is at the front of the queue, so she is served first.
- “Aliza” is at the Rear (back), indicating she joined the queue last.
- The queue operates on the principle of First In, First Out (FIFO)

That’s why** Queue is a linear data structure** as it arranges elements in a straight line, where new elements are added at one end and removed from the other (FIFO Principle).

## Tree –

Just like a real tree, the tree data structure in programming has roots, branches, and leaves. But here, the roots are at the top, branches spread downward, and leaves are at the bottom. So basically It’s a hierarchical data structure to show connections between different nodes.

Example –

Let’s take an simple example of Family Tree –

- At the top is the root node, representing the oldest generation
- Each next level represents a new generation
- Nodes branching out from a parent node represent children of that parent
- Each child node can have its own children, representing grandchildren and more family members

In this example:

- “Grandparents” are the root nodes.
- “Parents” and “Aunt” are children of “Grandparents”.
- “Child1” and “Child2” are children of “Parents”.

That’s why **Tree is a Non-LInear Data Structure **because it doesn’t follow a sequential arrangement like arrays, linked lists, stack and Queue, it branches out hierarchically.

## Graph –

A graph is a non-linear data structure consisting of nodes (vertices) connected by edges (Lines), where edges represent relationships between nodes.

**Example – **

Let’s take an example of Social Network Graph –

- Each person is represented by a node (vertex)
- Friendships between people are represented by edges connecting the corresponding nodes
- The nodes are connected by edges to show who is friends with whom

In this Example –

- “Vishal”, “Kumar”, “Aliza”, and “Dave” are nodes (vertices) representing individuals.
- Edges between nodes represent friendships.
- For Example, “Vishal” is friends with “Kumar”, and “Aliza” is friends with both “Vishal” and “Dave”.

That’s why a** Graph is a non-linear data structure** as it’s like a web, with connections going in different directions, rather than following a sequence.

## Conclusion –

I hope you get a better understanding Of Which of the following data structure is non-linear and why option C & F is correct.

- So basically In this blog we conclude that, Tree and Graph is a non-linear data structure and Array, Linked List, Stack and Queue is linear data structure.
- If you want to start a career in programming and want to become a successful Programmer, understanding these data structures is very important for problem-solving.
- Searching for best programming classes in Pune, look no further than Technogeeks. Technogeeks is the best place to learn, and the course curriculum is designed for both freshers and working professionals.

**Contact Us For Free Career Counselling – +91 8600998107 / +91 7028710777**