Skip to content

Latest commit

 

History

History
76 lines (59 loc) · 1.56 KB

File metadata and controls

76 lines (59 loc) · 1.56 KB

Chapter 4

Non-Linear Data Structures

  • Trees
  • Tables
  • Containers
  • Hash functions

Tree

space usage for a binary search tree is of the order O(n), whereas the insert, search,
and delete operations are of the order O(log n). A binary search tree consists of nodes with
properties or attributes:
  • A key integer
  • A value integer
  • The leftNode and rightNode instances of TreeNode
// TreeNode class
type TreeNode struct {
 key int
 value int
 leftNode *TreeNode
 rightNode *TreeNode
}
// BinarySearchTree class
type BinarySearchTree struct {
 rootNode *TreeNode
 lock sync.RWMutex
}

what is sync.RWMutex Source Code Binary tree

AVL Tree

Tables

// Table Class
type Table struct {
 Rows []Row
 Name string
 ColumnNames []string
}

// Row Class
type Row struct {
 Columns []Column
 Id int
}
// Column Class
type Column struct {
 Id int
 Value string
 }

Golang container/ring data type source code

Hash Functions

  • The Common two ways to implement a hash function in Go: with crc32 or sha256.