Help with asymptotics...

Правка en3, от eddy, 2016-01-15 08:16:50

I need some help to find out which are the asymptotics (big-O) of the following codes:

void EulerTour(List<Pair>[] graph, int u, Stack<int> tour)
{
    for (int i = 0; i < graph[u].Count; i++)
    {
        var v = graph[u][i];
        if (v.Second != 0) //edge hasn't been deleted
        {
            v.Second = 0; //deactivate edge
            for (int j = 0; j < graph[v.First].Count; j++)
            {
            	//remove edge from v's list
                var uu = graph[v.First][j]; 
                if (uu.First == u && uu.Second != 0)
                {
                    uu.Second = 0; //deactivate edge
                    break;
                }
            }
            EulerTour(graph, v.First, tour);
        }
    }
    tour.Push(u);
}

It looks for an Euler tour in a graph G = (V, E). I have read that this algorithm (cycle finding) is O(|V| + |E|), but I don't know if this specific implementation is that too.

I have this other, using Linked Lists:

void EulerTour(LinkedList<int>[] graph, int u, Stack<int> tour)
{
    while (graph[u].Count > 0)
    {
        var v = graph[u].First.Value;

        graph[u].RemoveFirst();
        graph[v].Remove(u);

        EulerTour(graph, v, tour);
    }
    tour.Push(u);
}

And I don't know if this one have the same asymptotics that the previous, because it actually removes the edge.

I have one more code:

void EulerTour(LinkedList<int>[] graph, int u, Stack<int> tour)
{
    while (graph[u].Count > 0)
    {
        var v = graph[u].First.Value;
        graph[u].RemoveFirst();

        EulerTour(graph, v, tour);
    }
    tour.Push(u);
}

It's idem to the second, but in this case the graph is directed, so here we don't perform the second removal. I think this one should be O(|E|) since it is executed once for each edge, but I'm not sure :(

Please, can someone explain me this asymptotics?

Теги asymptotics, euler tour, graph theory

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en4 Английский eddy 2016-01-15 22:19:38 3 Tiny change: 'lain me this asymptoti' -> 'lain me these asymptoti'
en3 Английский eddy 2016-01-15 08:16:50 120
en2 Английский eddy 2016-01-15 07:53:59 124
en1 Английский eddy 2016-01-15 07:36:45 1968 (published)