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
%% Iterative SVD | |
% Calculate the largetst singular value and it's corrsponding | |
% left-singular vector and right-singular vector | |
% Author: chouclee | |
% Date: 10/01/2014 | |
function [L,w,R] = SVD(S) | |
% S=[6,8,5,9; | |
% 8,5,4,6; | |
% 9,8,7,7; | |
% 6,7,3,8; |
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
// if current node has right subtree, return most left node of the right child. | |
// else trace back to its parent, if the parent is smaller than current node, then consider parent's parent... | |
// until parent node is bigger than current node. | |
public class findNextNode<Key extends Comparable<Key>> { | |
private Node root; | |
private class Node { | |
private Key key; | |
private Node left, right; | |
private Node parent; |
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
public class Node<Key> { | |
public Key key; | |
public Node<Key> left, right; | |
public Node(Key key) { | |
this.key = key; | |
} | |
} |
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.ArrayList; | |
import java.util.LinkedList; | |
import java.util.ListIterator; | |
public class BST<Key extends Comparable<Key>> { | |
private Node root; | |
private class Node { | |
private Key key; | |
private Node left, right; |
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; | |
public class BST<Key extends Comparable<Key>> { | |
private Node root; | |
private class Node { | |
Key key; | |
Node left, right; | |
public Node(Key key) { |
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
/* Depth First Search */ | |
import java.util.ArrayList; | |
public class DGraph { | |
private int V; | |
private ArrayList<Integer>[] adj; | |
private boolean[] marked; | |
@SuppressWarnings("unchecked") |
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
public class BST<Key extends Comparable<Key>> { | |
private Node root; | |
private boolean isBalanced; | |
private class Node { | |
private Key key; | |
private Node left, right; | |
public Node(Key key) |
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
public class BST<Key extends Comparable<Key>> { | |
private Node root; | |
private class Node { | |
private Key key; | |
private Node left, right; | |
public Node(Key key) | |
{ this.key = key; } |
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
// if stack.size() is not allowed, use insertion sort, but it's an O(n^2) (time) algorithm, space : O(n) | |
// else, we can use MergeSort. Each merge operation has to put the biggest element into bottom of new stack | |
// so an extra reverse operation is needed. Time complexity is O(nlogn), space : O(nlgn) | |
import java.util.Stack; | |
import java.util.Random; | |
public class stackSort { | |
public static<T extends Comparable<? super T>> Stack<T> insertSort(Stack<T> stack) { | |
Stack<T> sorted = new Stack<T>(); | |
T temp; |
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.Stack; | |
public class MyQueue<T> { | |
private Stack<T> pushStack; | |
private Stack<T> popStack; | |
public MyQueue() { | |
pushStack = new Stack<T>(); | |
popStack = new Stack<T>(); | |
} |
NewerOlder