Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest algorithm for a 'circular linked list builder'

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)

like image 633
frankhommers Avatar asked Feb 11 '17 15:02

frankhommers


People also ask

Is it faster to traverse in circular linked list?

b) It is faster to traverse the circular linked list.

Which scheduling algorithm uses circular Linkedlist?

Circular Linked Lists is the basic idea for the round robin scheduling algorithm.

What is the time complexity of circular linked list?

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) .


1 Answers

I believe that you're looking for Eulerian path

like image 129
algojava Avatar answered Oct 06 '22 00:10

algojava