Skip to main content

Posts

Showing posts with the label Binary tree BST

Is Binary Tree?

Given a binary tree,write an algorithm to find if the tree is a binary search tree or not. Simple Recursive call is good.. int check_tree(bst *node) { if(!node) return TRUE; if(node->left!=NULL && node->info left)) return(false); if(node->right!=NULL && node->info right)) return(false); if(!check_tree(node->left) || !check_tree(node->right)) return(false); return(true); } I have already posted better algorithm in my tree sections earlier. Set Min and Max to INT_MIN and INT_MAX bool IsBst( node *root, int min, int max) { if (!root) return true; if ( !isBst( root->left,min,root->info) return false; if ( !isBst(root->right,root->info,max) return false; return true; }

Binary Tree

26. Find height of a tree with or without recursion. 27. Find the levels in tree and no of node at every level. 28. No of leaves on tree. 29. Find the diameter of tree. Longest distance between two same level nodes. 30. Write pre/in/post order traversal with and without recursion. 31. Serialization of binary tree. Storing data/object in a file and then retrieving it back. 32. Find the least common ancestor for any two given nodes from tree. 33. Threaded binary tree and link inversion tree. 34. Find whether a given tree is BST or not. 35. Write code for inorder successor. 36. Find the kth smallest element of BST. 37. Convert BST to doubly link list. 38. Is the given BST is AVL or not?

Binary Tree

26. Find height of a tree with or without recursion. 27. Find the levels in tree and no of node at every level. 28. No of leaves on tree. 29. Find the diameter of tree. Longest distance between two same level nodes. 30. Write pre/in/post order traversal with and without recursion. 31. Serialization of binary tree. Storing data/object in a file and then retrieving it back. 32. Find the least common ancestor for any two given nodes from tree. 33. Threaded binary tree and link inversion tree. 34. Find whether a given tree is BST or not. 35. Write code for inorder successor. 36. Find the kth smallest element of BST. 37. Convert BST to doubly link list. 38. Is the given BST is AVL or not?