# The Mystery Vault Game Played by radio stations A listener can win up to \$25,000 if he/she guesses the correct amount in the vault One guess per hour until.

## Presentation on theme: "The Mystery Vault Game Played by radio stations A listener can win up to \$25,000 if he/she guesses the correct amount in the vault One guess per hour until."— Presentation transcript:

The Mystery Vault Game Played by radio stations A listener can win up to \$25,000 if he/she guesses the correct amount in the vault One guess per hour until somebody wins Let’s play!

Binary Trees What are they? no node has more than two child nodes –A tree such that no node has more than two child nodes Why are they useful? –Can be efficiently manipulated –A suitable data structure in many algorithms

What is a Binary Tree? A tree such that:A tree such that: –No node has more than two child nodes (called child subtrees). –A node in a binary tree can have 0,1, or 2 child subtrees –Child subtrees must be differentiated, into: Left-child subtree Left-child subtree Right-child subtree Right-child subtree

Binary Tree - Example

Binary Search Trees Commonly used data structure in searching algorithmsCommonly used data structure in searching algorithms A binary search tree is a binary tree, where elements are stored such that:A binary search tree is a binary tree, where elements are stored such that: –For any node p, the following is true: p>= i, for all nodes i in the left subtree of pp>= i, for all nodes i in the left subtree of p p<=j, for all nodes j in the right subtree of pp<=j, for all nodes j in the right subtree of p

Binary Search Tree - Example

Searching in a Binary Search Tree Why is a binary search tree good for searching?Why is a binary search tree good for searching?

Binary Search Trees (cont) In a binary search tree, searching for existence of a value can be O(log N), where N is the number of nodesIn a binary search tree, searching for existence of a value can be O(log N), where N is the number of nodes How long does it take (in the worst case) to find a value in a(n): –Array? –Linked List?

“Bad” Binary Search Trees Below is a binary search tree that is NOT “ balanced ”, its is bad and if so why?Below is a binary search tree that is NOT “ balanced ”, its is bad and if so why?

Height to Nodes Ratio For a given binary tree of height (H), and number of nodes (N), the ratioFor a given binary tree of height (H), and number of nodes (N), the ratio of height to nodes is: –H/N For many operations on binary trees, complexity is O(H)For many operations on binary trees, complexity is O(H) If H/N is small (N much bigger than H)If H/N is small (N much bigger than H) –tree levels are “well utilized” –the tree is hence “short” and “bushy” –operations on the tree are less costly

Height to Nodes Ratio (cont) For a given binary tree of height (H), and number of nodes (N), the ratioFor a given binary tree of height (H), and number of nodes (N), the ratio of height to nodes is: –H/N For many operations on binary trees, complexity is O(H)For many operations on binary trees, complexity is O(H) If H/N is large (N not much bigger than H)If H/N is large (N not much bigger than H) –tree levels are “ill utilized” –the tree is hence “long” and “thin” – operations on the tree are more costly

The Mystery Vault Game Revisited Played by radio stations A listener can win up to \$25,000 if he/she guesses the correct amount in the vault One guess per hour until somebody wins I’ll play!

Download ppt "The Mystery Vault Game Played by radio stations A listener can win up to \$25,000 if he/she guesses the correct amount in the vault One guess per hour until."

Similar presentations