If McDonalds were run like a software company, one out of every hundred Big Macs would give you food poisoning, and the response would be, ‘We’re sorry, here’s a coupon for two more.’ “ Mark Minasi

Binary search tree

Language Java | Level Intermediate | Category Algorithms | August 2, 2015 6:25 pm


Algorithm Problem Description

A binary search tree is a binary tree (contains only two nodes). The left subtree node data value is less than or equal to parent node data value and right subtree node data value is greater than or equal to parent node data value.

Each node has a unique key which helps to identify the node. The binary search tree supports search, insert and delete the node. It increases memory dynamically.

Traversal:

The Binary search tree supports inorder, preorder and post order traversal.

In-order traversal

Inorder traversal traverse left subtree, display the data and traverse the right subtree. It always gives a sorted sequence of the values

Pre-order traversal

Pre order displays the data, traverse left subtree and traverse the right subtree

Post-order traversal

Post order traverse left subtree, traverse the right subtree and display the data

Search:

Binary search Tree can use recursive or iterative search. Search operation takes time proportional to the tree's height.

Output

          	        
          	        
All Binary Tree Values: 1 2 3 4 5  
Value '4' found from given tree!
Value '11' not found from given tree!

          	        
          	        				    


Comments



Please login to add comments.