# Review on concurrent BFS approach

**URL:** <https://forum.golangbridge.org/t/review-on-concurrent-bfs-approach/37308>\
**Category:** Code Review\
**Created:** [December 25, 2024, 5:33pm UTC](https://forum.golangbridge.org/t/review-on-concurrent-bfs-approach/37308 "2024-12-25T17:33:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![geekNero](https://forum.golangbridge.org/letter_avatar_proxy/v4/letter/g/45deac/32.png) [@geekNero](https://forum.golangbridge.org/u/geekNero)\
**Post date:** [December 25, 2024, 5:33pm UTC](https://forum.golangbridge.org/t/review-on-concurrent-bfs-approach/37308/1 "2024-12-25T17:33:31Z")

</div>

Hi everyone, I took a stab at writing parallel BFS code using goroutines and the result isn’t great. I managed to write my approach but the time is inconsistent ( which kind of makes sense for cases where code doesn’t have to traverse the entire tree). So I passed a value that wouldn’t exist in the tree, so the control moves through the entire tree and the time came out worse than linear BFS.

Note: The problem statement is to check if a value exists in a tree or not using BFS.

I am looking for a **review of the approach** as well as **any possible optimizations**.  
I don’t have any leads, except maybe my code spends a lot of time in the critical section.

link to the repo: [GitHub - geekNero/Parallel-BFS](https://github.com/geekNero/Parallel-BFS)

PS: I am new to golang

---

<div class="post-metadata">

**Author:** ![geekNero](https://forum.golangbridge.org/letter_avatar_proxy/v4/letter/g/45deac/32.png) [@geekNero](https://forum.golangbridge.org/u/geekNero)\
**Post date:** [January 19, 2025, 11:23am UTC](https://forum.golangbridge.org/t/review-on-concurrent-bfs-approach/37308/2 "2025-01-19T11:23:19Z")

</div>

If anyone is watching this later on, I figured out the issues, I have posted the updated code on that repo itself.

The earlier code worked fine if each node had significant work to do, but I also improved the time in cases where it didn’t ( using master-slave threads ). In the earlier approach the threads were equal entities. ( Except the manager thread )
