Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How O(V+E) is equal to O(b^d) In BFS [closed]

In my algoritham analysis course teacher taught us that the time complexity of Breath First search is O(V+E) but now in Artificial intelligence course teacher is saying that the complexity of BFS is O(bd). When i asked him question he gave me a logical reason i.e "In theoretical computer science , O(V+E ) is appropriate because the graph is an explicit data structure that is input to the search algorithm. In AI, the graph is often represented implicitly by an initial state, action and transition model and frequently infinite. For this reason the complexity is expressed in term of O(bd)". Now I have two questions

  1. How O(V+E) and O(bd) are equal the first one looks like a linear complexity and second one is exponential.
  2. When we talk about big O notation it means that upper bound whatsoever the input may be it should remains the same because its an upper bound. whether Big O only deals with some finite data input?
Wikipedia source
like image 381
james Avatar asked Oct 10 '12 13:10

james


People also ask

What is the big O runtime of BFS?

then the running time of BFS algorithm is O(n ), where n is the number of nodes. If we represent the graph G by link lists then the running time of BFS algorithm is O(m + n), where m is the number of edges and n is the number of nodes.

How does BFS calculate time and space complexity?

BFS: Time complexity is O(|V|) , where |V| is the number of nodes. You need to traverse all nodes. Space complexity is O(|V|) as well - since at worst case you need to hold all vertices in the queue.

What is the open and closed list in DFS & BFS?

To search the graph space, the BFS method uses two lists for tracking the traversal. An 'Open' list that keeps track of the current 'immediate' nodes available for traversal and a 'CLOSED' list that keeps track of the nodes already traversed.

How is BFS complexity calculated?

9. The Time complexity of BFS is O(V + E) when Adjacency List is used and O(V^2) when Adjacency Matrix is used, where V stands for vertices and E stands for edges.


1 Answers

In Artificial Intelligence - you usually handle with huge/infinite graphs, thus O(V+E) is not informative and not good enough for these graphs, so we try to get a better bound. This bound is O(B^d), where B is the branch factor and d is the depth of the solution. The rational behind this is if you "branch" to B directions at each depth, you end up exploring O(B^d) nodes.

Morever - note that the classic BFS from your algorithms course is exploration algorithm - which needs to explore the entire graph (explore all vertices), while in AI we use it as pathfinding - you explore until we find a path from the source to the target. (no need, and sometimes it is impossible to explore the entire graph)

Also note, that if you look on a tree (no node is discovered twice), with branch factor B and all leaves are of depth d - there are exactly B + B^2 + B^3 + ... + B^d < B^(d+1) nodes in the tree, so if you do need to

How O(V+E) and O(b^d) are equal the first one looks like a linear complexity and second one is exponential.

In the first, the graph is the input, so it is linear in the size of the input - the graph.
The second is also linear in the size of the graph - and exponential in the depth of the solution - a different factor, still - no need to traverse a vertex more then once, so still linear in the graph's size.
So, in here - basically O(B^d) is a subset of O(V+E), and is more informative then it, if you can 'suffer' the fact that your complexity is a function of d, which is not part of the input.

When we talk about big O notation it means that upper bound whatsoever the input may be it should remains the same because its an upper bound. whether Big O only deals with some finite data input?

If the graph is infinite, big O is not informative, for each f(n), and for each constants c,N - c*f(n) < infinity, so it is useless when talking about infinite graphs.

like image 116
amit Avatar answered Nov 15 '22 06:11

amit