tree

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MaxCombine

func MaxCombine(a, b int) int

func MinCombine

func MinCombine(a, b int) int

func SumCombine

func SumCombine(a, b int) int

Common combine functions

Types

type AVLNode

type AVLNode struct {
	Key    int
	Height int
	Left   *AVLNode
	Right  *AVLNode
}

AVLNode represents a node in AVL tree

type AVLTree

type AVLTree struct {
	Root *AVLNode
	// contains filtered or unexported fields
}

AVLTree represents an AVL tree

func NewAVLTree

func NewAVLTree() *AVLTree

NewAVLTree creates a new AVL tree

func (*AVLTree) InOrderTraversal

func (t *AVLTree) InOrderTraversal(result *[]int)

InOrderTraversal performs inorder traversal of the tree

func (*AVLTree) Insert

func (t *AVLTree) Insert(key int)

Insert adds a new node to the tree

func (*AVLTree) Search

func (t *AVLTree) Search(key int) bool

Search looks for a value in the tree

type BTree

type BTree struct {
	// contains filtered or unexported fields
}

BTree represents a B-tree

func NewBTree

func NewBTree(t int) *BTree

NewBTree creates a new B-tree with minimum degree t

func (*BTree) Delete

func (tree *BTree) Delete(k int)

Delete removes a key from the B-tree

func (*BTree) GetInOrder

func (tree *BTree) GetInOrder() []int

GetInOrder returns all keys in the B-tree in sorted order

func (*BTree) Insert

func (tree *BTree) Insert(k int)

Insert inserts a key into the B-tree

func (*BTree) Search

func (tree *BTree) Search(k int) bool

Search searches for a key in the B-tree

type BTreeNode

type BTreeNode struct {
	// contains filtered or unexported fields
}

BTreeNode represents a node in B-tree

type Color

type Color bool

Color represents the color of a node in Red-Black tree

const (
	RED   Color = true
	BLACK Color = false
)

type IBinaryTree

type IBinaryTree interface {
	Insert(data int)
	Search(data int)
	Exists(data int) bool
	Delete(data int)
	Max() int
	Min() int
	Print(pType string)
	List(pType string) []int
}

func BinaryTree

func BinaryTree(data int) IBinaryTree

type RBNode

type RBNode struct {
	Key                 int
	Color               Color
	Left, Right, Parent *RBNode
}

RBNode represents a node in Red-Black tree

type RedBlackTree

type RedBlackTree struct {
	Root *RBNode
	NIL  *RBNode // Sentinel node
	// contains filtered or unexported fields
}

RedBlackTree represents a Red-Black tree

func NewRedBlackTree

func NewRedBlackTree() *RedBlackTree

NewRedBlackTree creates a new Red-Black tree

func (*RedBlackTree) InOrderTraversal

func (t *RedBlackTree) InOrderTraversal(result *[]int)

InOrderTraversal performs an inorder traversal of the tree

func (*RedBlackTree) Insert

func (t *RedBlackTree) Insert(key int)

Insert adds a new key to the tree

func (*RedBlackTree) Search

func (t *RedBlackTree) Search(key int) bool

Search looks for a key in the tree

type SegmentTree

type SegmentTree struct {
	// contains filtered or unexported fields
}

SegmentTree represents a segment tree data structure

func NewSegmentTree

func NewSegmentTree(arr []int, combine func(int, int) int) *SegmentTree

NewSegmentTree creates a new segment tree from an array

func (*SegmentTree) GetArray

func (st *SegmentTree) GetArray() []int

GetArray returns the current array

func (*SegmentTree) Query

func (st *SegmentTree) Query(left int, right int) int

Query returns the result of the combine function over the range [left, right]

func (*SegmentTree) Update

func (st *SegmentTree) Update(i int, val int)

Update updates the value at index i to val

type Trie

type Trie struct {
	// contains filtered or unexported fields
}

Trie represents a Trie (prefix tree)

func NewTrie

func NewTrie() *Trie

NewTrie creates a new Trie

func (*Trie) Delete

func (t *Trie) Delete(word string) bool

Delete removes a word from the trie

func (*Trie) GetAllWords

func (t *Trie) GetAllWords() []string

GetAllWords returns all words stored in the trie

func (*Trie) GetWordsWithPrefix

func (t *Trie) GetWordsWithPrefix(prefix string) []string

GetWordsWithPrefix returns all words that start with the given prefix

func (*Trie) Insert

func (t *Trie) Insert(word string)

Insert adds a word to the trie

func (*Trie) Search

func (t *Trie) Search(word string) bool

Search returns true if the word is in the trie

func (*Trie) StartsWith

func (t *Trie) StartsWith(prefix string) bool

StartsWith returns true if there is any word in the trie that starts with the given prefix

type TrieNode

type TrieNode struct {
	// contains filtered or unexported fields
}

TrieNode represents a node in Trie

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL