227k views
2 votes
In the ADT graph, the method addEdge has efficiency

A. O(1)

B.O(n)

C.O(logn)

D.O(n2)

User Zloctb
by
4.7k points

2 Answers

5 votes

Answer:

Thx 4 the points bro

Step-by-step explanation:

its B

User Samthebrand
by
5.3k points
4 votes

Answer:

B.O(n).

Step-by-step explanation:

In an ADT graph the method addEdge uses an Array of list.So in the worst case and the worst will be when the list already has n elements in it.

So to add an edge we have to iterate over the list upto nth element and then add the edge after that.So it has to travel over n elements.

So we can say that the answer is O(n).

User Vilma
by
5.0k points