Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linear Data Structure and Non linear Data Structure

I don't understand linear Data Structure and Non linear Data Structure difference

I want to Learn Programming. And I want to know Data. I want to understand for education.

Can someone explain with examples? I am learning programming and want to understand how data structures work, their importance, and where they are used in real applications.

like image 301
Kaung Thant Zaw Avatar asked Oct 17 '25 13:10

Kaung Thant Zaw


1 Answers

Linear Data Structure are those which are organised and can be traversed linearly. For example List (Arrays, Linked List) they are organized in a way where from one position traversal is linear (back or forward) to next/previous position. There is maximum of only 1 predecessor and maxium of only 1 successor. This creates a linear 1 to 1 relationship. This also ensures a sequential ordering (Arrays uses contiguous memory where as Linkedlist may not use contiguous memory but still conceptually arranged in linear sequence, where a node has a link to next or previous node)

Non Linear Data structures are those which has one to many or even many to many relationship. Examples are trees or graphs. Instead of simple previous or next here a position may have link to multiple positions.

Examples

Consider a social media where one person may have many friends and each friend may have multiple others and these friends may or may not be friends of each other. Here there is no one to one relationship but many to many relationship. Traversal is complex and non linear. This data can be represented by a non linear data structure.

Now consider a list of first 5 Presidents of a country. This data can be represented by an array or linked list. This is an example of linear data structure.

like image 65
nits.kk Avatar answered Oct 19 '25 08:10

nits.kk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!