One application of depth first search in real world applications is in site mapping.
type Node struct { Data interface{} Sleep time.Duration Left *Node Right *Node }Node Generator FunctionNewNode() returns a pointer to the a new node.
func (n *Node) ProcessNode() { var hello []int for i := 0; i < 10000; i++ { time.Sleep(n.Sleep) hello = append(hello, i) } fmt.Printf("Node %v ✅", n.Data) }Depth First Search Recursive FunctionThis is a single-threaded depth first search function implemented via recursion — it might look familiar to those who have written it before. Node 4 ✅ Node 2 ✅ Node 5 ✅ Node 1 ✅ Node 6 ✅ Node 3 ✅ Node 7 ✅ Time elapsed: 8.75086767sSupercharge Your Depth First Search with GoroutinesConverting the process and depth first search functions involves only minor changes when compared to other programming languages:Calling the recursive function with the go command. Maintaining a waitGroup which keeps track of the in process function so the program doesn't exit without all of them completing.

Comments to: How to Supercharge Your Depth First Search with Goroutines

Your email address will not be published. Required fields are marked *

Attach images - Only PNG, JPG, JPEG and GIF are supported.

Login

Welcome to Typer

Brief and amiable onboarding is the first thing a new user sees in the theme.
Join Typer
Registration is closed.