Skip to content

Commit 4fa4988

Browse files
sagarpandyansitabranhe
authored andcommitted
remove recursion and implement iteratively
1 parent 6d8fa87 commit 4fa4988

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

algorithms/dsu/naive_dsu.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ void make_set(int val)
3333

3434
int find_parent(int val)
3535
{
36-
if(val == parent[val])
37-
{
38-
return val;
36+
while (parent[val] != val) {
37+
parent[val] = parent[parent[val]];
38+
val = parent[val];
3939
}
40-
return find_parent(parent[val]);
40+
return val;
4141
}
4242

4343
void union_set(int x, int y)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy