Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uses of self referencing lists

I know it is possible to create a self referencing list in languages like Python:

>>> my_list = [1,2]
>>> my_list.append(my_list)
>>> print my_list
[1,2,[...]]
>>> print my_list[0]
1
>>> print my_list[2]
[1,2,[...]]

What algorithms benefit from self referencing lists? I cannot think of one.

Thanks.

like image 996
Escualo Avatar asked Sep 16 '10 16:09

Escualo


1 Answers

Self-referencing lists, and, generally speaking, circular data structures, can be caused when representing a graph using data structures.

For example, consider this naive representation of a graph: Each node is either an atomic value, or a list of nodes that it is linked to. A circle may cause a list to contain another list that contains the list. A self-circle, i.e., an edge from a node to itself, will cause a self-referencing list.

like image 92
Little Bobby Tables Avatar answered Oct 20 '22 12:10

Little Bobby Tables