CS 310 Unit 11 Binary Search Trees

CS 310 Unit 11 Binary Search Trees - CS 310 Unit 11 Binary...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: CS 310 Unit 11 Binary Search Trees Furman Haddix Ph.D. Assistant Professor Minnesota State University, Mankato Spring 2008 Binary Search Tree Objectives • Binary Search Tree Definitions • Binary Search Tree Algorithms – Insert() – Traversal() – Search() – Minimum() – Maximum() – Successor() – Predecessor() – Delete() • Text, Chapter 12 Binary Search Tree Definitions • Important Methodology for Dynamic Sets • Many Dynamic Set Operations are O(h) where h is the height of the tree • Can be constructed as a linked data structure where each node is an object • root is a pointer to the root of the tree • Each node minimally contains: – key data, key – pointer to left child, left – pointer to right child, right – pointer to parent, p • Properties – If y is in left subtree of x then key[y] ≤ key[x] – If y is in right subtree of x then key[y] ≥ key[x] Binary Search Tree F D B A K H J L C K E F • Build in order binary search tree with keys, F, D, B, A, K, H, J, L, C, K, E, F: Insert() • Insert new node as leaf in “in order position” • Example insert(G); F D B A K H J L C K E F ≥ < < ≥ G Binary Search Tree insert() void insert(Node *x) { Node *y = root, *z = null; while (y != null) z = y; if (x->key() < y->key()) y = y->left(); else y = y->right(); } x->setP(z); if(z == null) root = x; else if (x->key() < z->key()) z->setLeft(x); else z->setRight(x); return; } Node *p; Node *left; Node *right;...
View Full Document

This note was uploaded on 06/09/2008 for the course CS 310 taught by Professor Furmanhaddix during the Spring '08 term at Minnesota State University, Mankato.

Page1 / 19

CS 310 Unit 11 Binary Search Trees - CS 310 Unit 11 Binary...

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

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