Frage

I have a question which says

Let a directed graph G model a relation R. If G is represented using adjacency lists, then,
the worst case time complexity for finding whether R is symmetric would be (as a
function of |R| ) _____?

The answer according to me is that for finding if symmetric property is satisfied or not we just need to go to both the vertices and check if they both have each other in each other's adjacency list. So, worst case would be O(degree(vertex)) but the answer given is O(|R|*|R|) or O(|E|*|E|)

How ?

War es hilfreich?

Lösung

what do you mean by O(degree(vertex))?

beside consider that EVERY pair in relation must be checked to have a reverse. so for each pair of |R| members of relation, there is going to be a search. the search itself -if not using any tricks- is about visiting |R| pairs , so it does make sense that in worst case it would be of |R|*|R|

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top