Perform DFS over the entire graph. The linear time taken by a size of graph as visiting each node finished is put it on the head of initially empty list is
- $O(|V|+|E|)$
- $O(|V+E|)$
- $O(|V|^k)$
- $O(\log |V|)$
My attempt: There is no doubt answer is $O(|V|+|E|)$.
But, what is difference between $O(|V|+|E|)$ and $O(|V+E|)$? Are these same?
Can you explain, please?
I want to disagree with the answer by Newb slightly, but mainly just to point out some issues with formalism. Also if you answered $O(|V+E|)$ on my test you would get zero points and I'm sure there are other teachers like that.
Since $V$ and $E$ are sets (exactly what kind depends on your particular definition of graph but the most prevalent definition in the US seems to be $E\subseteq V\times V$ and $V$ arbitrary), then under usual circumstances $V+E$ makes no sense, as you probably haven't defined addition on sets. You could define $V+E=V\cup E$ but it is decidedly non-standard.
For this reason $O(|V+E|)$ is undefined and thus nonsense. Note that the $|\;\;|$ operator here is not the absolute value, instead it is the cardinality operator.