문제

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 ?

도움이 되었습니까?

해결책

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|

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top