0% found this document useful (0 votes)
8 views1 page

Cs Notes Binary Search Trees 14 0630368d

A Binary Search Tree (BST) is a data structure with nodes having at most two children, where left subtree values are smaller and right subtree values are larger. Key operations such as insertion, search, and deletion have a complexity of O(h), ideally O(log n) for balanced trees. Exercises include implementing BST insertion, finding the height of a BST, and checking if a tree is a valid BST.

Uploaded by

phamhuy061106dz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Cs Notes Binary Search Trees 14 0630368d

A Binary Search Tree (BST) is a data structure with nodes having at most two children, where left subtree values are smaller and right subtree values are larger. Key operations such as insertion, search, and deletion have a complexity of O(h), ideally O(log n) for balanced trees. Exercises include implementing BST insertion, finding the height of a BST, and checking if a tree is a valid BST.

Uploaded by

phamhuy061106dz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Computer Science: Binary Search Trees Notes 14

Introduction
A Binary Search Tree (BST) is a tree data structure where each node has at most two children, with left
subtree values smaller and right subtree values larger.

1. Node Structure
class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None

2. Diagram
[10]
/ \
[5] [15]
/ /
[3] [12]

3. Operations
Insertion and search are O(h) where h is the tree height, ideally O(log n) for balanced trees.

Summary Table
Operation Complexity

Insert O(h)

Search O(h)

Delete O(h)

Exercises
1. Implement BST insertion. 2. Find the height of a BST. 3. Check if a tree is a valid BST.

You might also like