Submitted by heartin on Mon, 11/09/2015 - 19:48
Problem Statement
Create a binary search tree with minimal height from a sorted increasing order array.
Approach
If you traverse a Binary Search Tree in inorder traversal, you will get the numbers printed in a sorted increasing order. So you can reverse process and create a binary search tree from a sorted increasing order array of integers.
Submitted by heartin on Mon, 11/09/2015 - 18:23
Problem statement
Check if a Binary Tree is Balanced in O(N) time complexity.
Assumption: Heights of two subtrees of any node should never differ by more than one, to consider a tree as balanced.
Approach
We can use a recursive function that will return the height of its subtree, or a special integer (-1) if the node is not balanced.
In every recusrive call,
if node is null, then return 0.
Submitted by heartin on Mon, 11/09/2015 - 03:36
We have already seen what SOAP faults are and how they are reprecented in the WSDL and SOAP message in the WSDL and SOAP overview notes respectively. Here we will try to consolidate the basic information related to SOAP faults.
Java application exceptions can be mapped to SOAP faults in WSDL/SOAP message.
Fault element in SOAP message
-
A SOAP message can have fault elements within it.
-
Fault elements contain errors and status information.
-
Fault is an optional element.
Submitted by heartin on Mon, 11/09/2015 - 03:32
Java application exceptions can be mapped to SOAP faults in WSDL/SOAP message.
Problem statement
We will create a simple web service class with a single method that will accept an integer and check if it is even. If even we will return “Received even N” where N is the received even number.
If received number is not even, then we will throw a custom exception NotEvenNumberException that extends Exception.
Submitted by heartin on Sun, 11/08/2015 - 18:50
Approach
-
For a BST, all left nodes should be less than or equal to current node and current node must be less than all right nodes.
-
We will have a recursive function that checks if this property is true for every node and all its sub trees:
-
If the method get null node, it may return true, and should be first checked (exit condition for the recursion).
-
Check if 'left nodes is less than or equal to current node and current node must be less than all right nodes.