DEV Community

Discussion on: Introduction to Data Structures and Algorithms With Python

Collapse
 
smartjeff profile image
Jeff Odhiambo • Edited

linked list is linear and I listed it as linear, and explained that in linear data structures are data structures structures where data are accessed siquentially. kindly check again.

About insertion and deletion operation, they are expensive in the sence that much time can be taken as it may involve shifting of elements where a certain order is to be maintained

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

yes but linked lists are trees though (and, by extension, graphs)

Thread Thread
 
Sloan, the sloth mascot
Comment deleted
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

That's... factually incorrect. Have you even looked up the definition of trees before writing an article on them?

Thread Thread
 
smartjeff profile image
Jeff Odhiambo • Edited

hope this will help in understanding why one is linear and why the other is non linear
dev-to-uploads.s3.amazonaws.com/up...

Thread Thread
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️ • Edited

But... linked lists are literally trees though; they can't be linear and non-linear at the same time 😂

EDIT: That image is nice, but wrong. Trees are just (connected) graphs without loops, so every linked list is also a tree.

Thread Thread
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

I'll just quote wikipedia here:

In graph theory, a tree is an undirected graph in which any two vertices are connected by exactly one path, or equivalently a connected acyclic undirected graph.

Which perfectly applies to a linked list:

  • Any two list elements are connected by exactly one path
  • There are no loops in a list

There's even a whole programming language that pretty much implements linked lists as a special case of binary trees (That's lisp I'm talking about), and you could easily do the same in any other programming language that implements trees.

Thread Thread
 
smartjeff profile image
Jeff Odhiambo

I think we are also learning new stuffs in the process, maybe the resources that I was using in my research were not clear 😅. And they have given me a new Friend called DarkWiiPlayer

Thread Thread
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

Yaaay!

By the way it may seem like a technicality but it's actually a really cool thing. So many things can be thought of as special kinds of graphs so learning a thing or two about those can be immensely helpful in so many programming problems 😁

Thread Thread
 
tylerroost profile image
tylerroost

So we agree that linked lists are both linear and non linear. And when using the definition of seuqnetiality would a tree not be linear because there is topological ordering from the root to leaves?

Thread Thread
 
smartjeff profile image
Jeff Odhiambo

that's more clear, thanks