Complete the code to insert a key into a binary search tree (BST).
func insert(root *Node, key int) *Node {
if root == nil {
return &Node{key: key}
}
if key [1] root.key {
root.left = insert(root.left, key)
} else {
root.right = insert(root.right, key)
}
return root
}In a BST, keys less than the current node go to the left subtree.
Complete the code to check if a key exists in a hash map.
func containsKey(m map[int]string, key int) bool {
_, ok := m[1]key
return ok
}In Go, map keys are accessed using square brackets.
Fix the error in the BST search function to correctly find a key.
func search(root *Node, key int) bool {
if root == nil {
return false
}
if key == root.key {
return true
} else if key [1] root.key {
return search(root.left, key)
} else {
return search(root.right, key)
}
}To search in BST, go left if key is less than current node's key.
Fill both blanks to create a map from keys to their values only if the key is greater than 10.
filtered := map[int]string{}
for k, v := range data {
if k [1] 10 {
filtered[k] = [2]
}
}We check if key is greater than 10, then assign the value to filtered map.
Fill all three blanks to create a BST in-order traversal that collects keys greater than 5.
func inorder(root *Node, result *[]int) {
if root == nil {
return
}
inorder(root.left, result)
if root.key [1] 5 {
*result = append(*result, [2])
}
inorder(root.right, [3])
}Check if key is greater than 5, append key to result slice, and continue traversal.
