MCPcopy
hub / github.com/geekcomputers/Python / search

Function search

binary_search_trees/search_in_bst.py:5–19  ·  view source on GitHub ↗

This function searches for a node with value val in the BST and returns True if found, False otherwise

(root: Optional[Node], val: int)

Source from the content-addressed store, hash-verified

3
4
5def search(root: Optional[Node], val: int) -> bool:
6 """This function searches for a node with value val in the BST and returns True if found, False otherwise"""
7
8 # If the tree is empty, return False
9 if root is None:
10 return False
11
12 # If the root value is equal to the value to be searched, return True
13 if root.data == val:
14 return True
15
16 # If the value to be searched is less than the root value, search in the left subtree
17 if root.data > val:
18 return search(root.left, val)
19 return search(root.right, val)

Callers 1

mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected