This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package POJ; | |
| import java.util.ArrayList; | |
| import java.util.Stack; | |
| public class Main{ | |
| /** | |
| * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package POJ; | |
| import java.util.Random; | |
| import java.util.Stack; | |
| public class Main{ | |
| /** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package POJ; | |
| import java.util.Arrays; | |
| import java.util.Date; | |
| import java.util.LinkedList; | |
| import java.util.List; | |
| import java.util.Queue; | |
| public class Main{ | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package POJ; | |
| public class Main{ | |
| /** | |
| * 4.1 Implement a function to check if a binary tree is balanced. For the purposes | |
| * of this question, a balanced tree is defined to be a tree such that the heights | |
| * of the two subtrees of any node never differ by more than one. | |
| * | |
| * @Runtime & spaces |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package POJ; | |
| import java.lang.reflect.Array; | |
| import java.util.ArrayList; | |
| public class DirectedGraph { | |
| private ArrayList<Integer>[] graph; | |
| public DirectedGraph(int n){ | |
| graph=(ArrayList<Integer>[])new ArrayList[n]; | |
| for(int i=0;i<n;i++){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.LinkedList; | |
| import java.util.Queue; | |
| public class Main{ | |
| /** | |
| * 4.3 Given a sorted (increasing order) array with unique integer elements, | |
| * write an algorithm to create a binary search tree with minimal height. | |
| * | |
| * @Runtime & spaces |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package POJ; | |
| import java.util.ArrayList; | |
| import java.util.LinkedList; | |
| import java.util.List; | |
| public class Main{ | |
| /** | |
| * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package POJ; | |
| import java.util.ArrayList; | |
| import java.util.LinkedList; | |
| import java.util.List; | |
| public class Main{ | |
| /** | |
| * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package POJ; | |
| import java.util.ArrayList; | |
| import java.util.LinkedList; | |
| import java.util.List; | |
| public class Main{ | |
| /** | |
| * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package POJ; | |
| public class Main{ | |
| /** | |
| * | |
| * 4.7 Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree. | |
| * Avoid storing additional nodes in a data structure. NOTE: This is not necessarily a binary search tree. | |
| * | |
| * Solution: |