-
Determine if Two Trees are Identical
```java boolean identicalTrees(Node a, Node b) { if (a == null && b == null) return true;
-
Count Full Nodes Binary Tree Iterative Recursive
```java int getfullCount(Node root) { if (root == null) return 0;
-
Calculate Size of a tree | Recursion
int size(Node node) { if (node == null) return 0; else return(size(node.left) + 1 + size(node.right)); }
-
Find a pair with maximum product in array of Integers
```java void maxProduct(int arr[], int n) { if (n < 2) { System.out.println(“No pairs exists”); return; }
-
Find the Minimum length Unsorted Subarray, sorting which makes the complete array sorted
```java void printUnsorted(int arr[], int n) { int s = 0, e = n - 1, i, max, min;
-
Merge Overlapping Intervals
```java void mergeIntervals(Interval arr[]) { if (arr.length <= 0) { return; }
-
Maximum difference between two elements such that larger element appears after the smaller number
```java int maxDiff(int arr[], int arr_size) { int max_diff = arr[1] - arr[0]; int min_element = arr[0]; for (int i = 1; i < arr_size; i++) { if (arr[i] - min_element > max_diff) { max_diff = arr[i] - min_element; } if (arr[i] < min_element) { min_element = arr[i]; } } return max_diff; }
-
K’th Smallest/Largest Element in Unsorted Array (Expected Linear Time)
```java int kthSmallest(int arr[], int l, int r, int k) { if (k > 0 && k <= r - l + 1) { int pos = randomPartition(arr, l, r);
-
Given a sorted array and a number x, find the pair in array whose sum is closest to x
```java void printClosest(int arr[], int n, int x) { int res_l = -1, res_r = -1;
-
Given an array A[] and a number x, check for pair in A[] with sum as x
```java