Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Divyanshu Shekhar
Divyanshu Shekhar

Posted on • Edited on

     

Golang Binary Search Tree

A Tree is a non-linear Data Structure unlike the arrays, slices, and linked lists. A Binary Tree is also a tree and data structure that has a maximum of two children nodes.

The Binary Search Tree allows us for a quick lookup, insertion, and deletion of nodes/elements. The time complexity of these operations in Binary Search Tree is O(log n).

Binary Search Tree was invented by P. F Windley, A.D. Booth, A. J. T. Colin, and T. N. Hibbard.

Prerequisite for the Binary Search Tree is you should know about Golang pointers and a little knowledge aboutGolang linked list.

Binary Search Tree Node Struct in Golang

The BST consists of nodes with these properties:

The Left field of type node that stores the address of the root of the left subtree.
Data field to store data.
The right field of type node to store the address of the root of the right subtree.

type Node struct {    left *Node    data int    right *Node}
Enter fullscreen modeExit fullscreen mode

Golang Binary Search Tree Struct

The Binary Search Tree Struct has a root field that stores the value of the root of the tree.

The root of the tree holds a very significant place because we need the root of the tree to traverse the tree.

type BinarySearchTree struct {    root *Node}
Enter fullscreen modeExit fullscreen mode

Read the whole post onGolang Binary Search Tree from the original Post.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Developer | Blogger
  • Joined

More fromDivyanshu Shekhar

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp