/euler

euler tour trees in golang

Primary LanguageGoMIT LicenseMIT

euler

euler tour trees in golang 👍

algorithm description

usage

trees := CreateEuler()

fmt.Println(trees.IsConnected(1, 2)) // false
fmt.Println(trees.Link(1, 2)) // true
fmt.Println(trees.Link(2, 3)) // true
fmt.Println(trees.IsConnected(1, 2)) // true
fmt.Println(trees.IsConnected(1, 3)) // true

fmt.Println(trees) // 1-2-3-2-1 - euler tour

fmt.Println(trees.Link(1, 2)) // false - already connected
fmt.Println(trees.Cut(1, 2)) // true
fmt.Println(trees.IsConnected(1, 2)) // false
fmt.Println(trees.IsConnected(1, 3)) // false
fmt.Println(trees.IsConnected(2, 3)) // true
fmt.Println(trees.Cut(1, 2)) // false - no edge
fmt.Println(trees.Cut(1, 3)) // false - no edge

fmt.Println(trees)
// 1
// 2-3-2

// order of link params affect euler tour
fmt.Println(trees.Link(2, 1)) // true

fmt.Println(trees) // 2-3-2-1-2

tests

go test

benchmarks

go test -bench=.