I have two questions:
1) What is the fastest algorithm to put this list in a "connecting" order?
2) Is this an existing problem/algorithm, and what name does it have?
The nodes are always connected in a circular fashion, so my starting ID does not matter.
Given this list:
id node1 node2
A 4 9
B 6 1
C 1 3
D 3 10
E 7 2
F 4 2
G 9 8
H 10 5
I 7 5
J 6 8
node1 & node2 are not in a specific order so id A can be 4 - 9 as well as 9 - 4.
The output should be this (it doesn't matter if it starts with A, as long as the output is a chain).
node ids: 4 - 9 - 8 - 6 - 1 - 3 - 10 - 5 - 7 - 2 - 4
ids: A G J B C D H I E F
(I am writing my code in C#. But pseudo code in any language will do)
b) It is faster to traverse the circular linked list.
Circular Linked Lists is the basic idea for the round robin scheduling algorithm.
Circular Linked List Complexity. The insertion operations that do not require traversal have the time complexity of O(1) . And, an insertion that requires traversal has a time complexity of O(n) . The space complexity is O(1) .
I believe that you're looking for Eulerian path
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With