Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time Complexity #7

Closed
Kostekgol opened this issue Sep 21, 2022 · 1 comment
Closed

Time Complexity #7

Kostekgol opened this issue Sep 21, 2022 · 1 comment

Comments

@Kostekgol
Copy link

for(int u = 1; u <= 2*N; u++){

image
It seems to me that these 2 loops can possibly run in O(n*m). I know that it can't be the case, bc of limit, what's the complexity of those?

@Jonathan-Uy
Copy link
Owner

The if statement on Line 76 is run as many times as there are edges in the graph. This is because u will be the start node of an edge, v will be the end node, and no edge will be counted twice (in this question, the graph is directed). So, the two for-loops have $O(\max(N, M))$ time complexity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants