14-BST - Binary Search Tree (BST) Properties: - Each node...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Properties: - Each node has a value - The left subtree contains only values less than the parent node’s value - The right subtree contains only values greater than or equal to the parent node’s value Binary Search Tree (BST) Binary Search Tree (BST)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
BST Example BST Example
Background image of page 2
if the root is NULL then the item is not found else if the root->Data == searchData then return the root else if the root->Data > searchData then recursively search left subtree else recursively search right subtree end if end if BST Search Algorithm BST Search Algorithm
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
If the tree is full BST search requires O(logN) operations, which is the same as O(h) where h is the height of the tree. BST Search Performance BST Search Performance Height (h) 1 2 3 4
Background image of page 4
if the root is NULL then replace the empty tree with the new node else if the root->Data == insertData then do nothing, the item is already in the tree else if the root->Data > insertData then recursively insert into the left subtree else recursively insert into the right subtree end if end if Insertion into BST Insertion into BST
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 13

14-BST - Binary Search Tree (BST) Properties: - Each node...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online