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
import java.util.NoSuchElementException; | |
import java.util.Stack; | |
/** | |
* CLRS - Introduction to Algorithms Ex.10.1-6 | |
* | |
* Show how to implement a queue using two stacks. Analyze the running time of the queue operations | |
* | |
* */ | |
public class QueueWithTwoStack { |
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
import java.util.LinkedList; | |
import java.util.NoSuchElementException; | |
import java.util.Queue; | |
/** | |
* Show how to implement a stack using two queues. Analyze the running time of the queue operations. | |
* | |
*/ | |
public class StackWithTwoQueue { |
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
import java.util.ArrayList; | |
import java.util.LinkedList; | |
import java.util.Queue; | |
/** | |
* This class will compute the number of connected components of an un-directed graph. If graph is fully connected than it will return 1. | |
* | |
* @author buraktas | |
* | |
*/ |
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
package graph.search.dfs; | |
import static org.junit.Assert.assertEquals; | |
import graph.entity.Vertex; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import org.junit.Before; | |
import org.junit.Test; |
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 { | |
private Node root; | |
public BinarySearchTree() { | |
this.root = null; | |
} | |
public BinarySearchTree(Node root) { |
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
import java.util.Stack; | |
public class FindNextGreatestGivenArray { | |
// works in O(n*n) | |
public int[] findNextGreatestNumbers(int[] numbers) { | |
if (numbers == null) { | |
throw new IllegalArgumentException("Given array is 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
public class LinkedList { | |
public class Node { | |
int data; | |
Node next; | |
public Node(int item) { | |
this.data = item; |
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 LinkedList { | |
public class Node { | |
int data; | |
Node next; | |
public Node(int item) { | |
this.data = item; |
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 ReverseLinkedListKSizeSlots { | |
public Node reverseRecursion(Node root, int k) { | |
Node current = root; | |
Node prev = null; | |
Node next = null; | |
int count = 0; | |
while (current != null && count < k) { |
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
import java.util.Random; | |
public class RandomizedQuickSort { | |
public void quickSort(int[] numbers, int low, int high) { | |
if (low < high) { | |
// select pivot randomly | |
int q = randomizedPartition(numbers, low, high); |
OlderNewer