This file contains 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
public class SmallestRangeInKList { | |
public int size; | |
public HeapNode[] Heap; | |
public int position; | |
static int gMax; | |
static int gMin; | |
int currMax; //tracks the max entry in the heap | |
int range = Integer.MAX_VALUE; |
This file contains 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
public class BSTtoGreaterTree { | |
public static int sum = 0; | |
public void greaterTree(Node root){ | |
if(root!=null){ | |
//visit the right node first | |
greaterTree(root.right); | |
//store the node value in temp | |
int temp = root.data; | |
//update the sum, sum till previous visited node |
This file contains 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
public class SwapEveryKthNode { | |
public static void main (String[] args) throws java.lang.Exception | |
{ | |
LinkedListT a = new LinkedListT(); | |
a.addAtBegin(10); | |
a.addAtBegin(9); | |
a.addAtBegin(8); | |
a.addAtBegin(7); | |
a.addAtBegin(6); | |
a.addAtBegin(5); |
This file contains 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
public class PairwiseSwapNodesByChangingLinks { | |
public static Node swapNodeIterative(Node head){ | |
Node ptrOne_prev = null; | |
Node baseHead = null; | |
while(head!=null && head.next!=null ){ | |
//Take 2 pointers, one on head | |
Node ptrOne = head; | |
//another on head.next | |
Node ptrTwo = head.next; | |
//store the reference of next node of pointer 2. |
This file contains 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
public class MagicIndex { | |
// perform modified binary search | |
public int search(int[] A, int start, int end) { | |
if (start <= end) { | |
int mid = (start + end) / 2; | |
if (mid == A[mid]) // check for magic index. | |
return mid; | |
if (mid > A[mid]) { // If mid>A[mid] means fixed point might be on | |
// the right half of the array | |
return search(A, mid + 1, end); |
This file contains 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
public class BinarySearchTree { | |
public static Node root; | |
public BinarySearchTree(){ | |
this.root = null; | |
} | |
public boolean find(int id){ | |
Node current = root; | |
while(current!=null){ | |
if(current.data==id){ |
This file contains 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
public class MaxPathSumBwTwoLeaves { | |
public static int maxSoFar =0; | |
public int maxPathSum(Node root){ | |
if(root!=null){ | |
int leftS = maxPathSum(root.left); | |
int rightS = maxPathSum(root.right); | |
int sumCurrent; | |
if(leftS<0 && rightS<0){ | |
sumCurrent = root.data; |
This file contains 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
public class reverseLinkedList2 { | |
public static Node head=null; | |
public Node reverseRecur2(Node current){ | |
if(current==null){ | |
return null; | |
} | |
if(current.next==null){ | |
head = current; | |
return null; | |
} |
This file contains 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
function computeSvgSizeFromData(config){ | |
var tree = d3.layout.tree(), | |
nodes = tree.nodes(config.data); | |
var maxTreeChildrenHeight = {}, | |
maxTreeHeight = 0, | |
maxTreeDepth = 0, | |
minSvgWidth, | |
minSvgHeight; |
This file contains 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
public class LinkListImplementation { | |
public static void main(String[] args) throws java.lang.Exception { | |
LinkedListT a = new LinkedListT(); | |
a.addAtBegin(5); | |
a.addAtBegin(15); | |
a.addAtEnd(20); | |
a.addAtEnd(21); | |
a.deleteAtBegin(); | |
a.deleteAtEnd(); | |
a.addAtIndex(10, 2); |