r/computerscience • u/ResponsibilityBig343 • Oct 06 '26
Discussion A linkedlist is a skewed directed graph
Can I say the above? I think of this after studying trees and graph. Singly linked list in particular.
23
Upvotes
61
u/Flashy-Guava9952 Oct 06 '26
If I recall correctly, a linked list is a special case of a tree, which is special case of a graph.
20
u/ilovemacandcheese Oct 06 '26
Yep. Every kind of data structure can be described with discrete math and, if you understand that, algorithms and data structures becomes much easier.
5
u/CrackerJackKittyCat Oct 06 '26
Yes, in some sense is a degenerate graph. But I'd consider that a curiosity insight at most. Do not then go on to discuss it in terms of graph theory or edges and vertices and graph algorithms else would be thought of as being overly clever.
They have extremely different use cases.
2
u/FastSlow7201 Oct 07 '26
To compound what you're already looking at, matrices are graphs and vice versa.
https://www.youtube.com/watch?v=PB-1_JTHyEU
3
u/DTux5249 Oct 06 '26
Yeah, lists are a subset of trees, which themselves are a subset of graphs.
3
u/[deleted] Oct 06 '26
Linked lists are unary trees. In graph theory terms, it is a directed tree (therefore it is connected and acyclic) where every vertex has in degree and out degree <= 1.
2
u/alnyland Oct 06 '26
A single point is a cycle
1
u/amarao_san Oct 07 '26
A graph can be represented not as tree, so not every linear graph is a linked list. E.g. a Vector/Array is a well-packed linear graph, but not a linked list.
1
u/Afraid-Locksmith6566 Oct 06 '26
nope it is just a special case of tree structure - a unary tree, which trees are a special case of DAG - which is a special case of Graph
1
u/not_a_bot_494 Oct 06 '26
All datastructures can be described by graphs. Ik fact all programs can be described by graphs.
6
u/[deleted] Oct 06 '26
[removed] — view removed comment