Skip to content

Instantly share code, notes, and snippets.

View anupsavvy's full-sized avatar

Anup anupsavvy

  • Northwestern University
  • Chicago
View GitHub Profile
@anupsavvy
anupsavvy / 19.json
Last active August 29, 2015 13:57
Stacked bar-charts on time scale.
[
[
{
"time": "0",
"y": 0
},
{
"time": "1",
"y": 0
},
@anupsavvy
anupsavvy / Triangle.java
Created July 15, 2011 03:23
Triangle Problem - By starting at the top of the triangle and moving to adjacent numbers on the row below, find the maximum total from top to bottom.
package com.example.triangle;
import java.io.File;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class Triangle {
public static void main(String args[]){
@anupsavvy
anupsavvy / Tree.java
Created July 15, 2011 06:35
Check to see if the tree is balanced.
package com.example.tree;
import com.example.Node;
// Tree is balanced when the difference between maximum and minimum height is <= 1.
public class Tree{
public static void main(String args[]){
Node root = new Node();
if(checkTreeBalance(root))
System.out.println("Its a balanced tree");
else
@anupsavvy
anupsavvy / Stack.java
Created July 19, 2011 02:37
Creation of simple array based stack
package com.operations.stack;
public class Stack{
private static final int SIZE = 1024;
private int N;
private int t = -1;
@anupsavvy
anupsavvy / Queue.java
Created July 23, 2011 00:30
Simple Circular Queue
package com.operations.queue;
public class Queue{
private int N ;
private static final int SIZE = 1024;
private int[] arr = null;
private int t = 0;
private int f = 0;
@anupsavvy
anupsavvy / Sort.java
Created July 25, 2011 23:45
Simple Quicksort ( this is not a randomized version ).
public class Sort{
private int[] arr = null;
public Sort(int[] arr) throws SortException{
this.arr = arr;
if(this.arr == null)
throw new SortException("Null array found");
}
@anupsavvy
anupsavvy / Search.java
Created July 26, 2011 04:30
Write a program for finding the kth - smallest element in the array x[0..n-1] in O(n) expected time. Your algorithm may permute the elements of x.
package com.operations.search;
public class Search{
private int[] arr=null;
private int k=0;
public Search(int[] arr){
this.arr = arr;
if(this.arr == null)
throw new SearchException("Cannot accept null array");
@anupsavvy
anupsavvy / Puzzle.java
Created July 27, 2011 03:49
Write a method to shuffle a deck of cards. It must be a perfect shuffle – in other words, each 52! permutations of the deck has to be equally likely. Assume that you are given a random number generator which is perfect.
public class Puzzle {
public static int[] shuffleCards(int[] cards){
if(cards == null || cards.length==1 || cards.length==0){
return cards;
}
int cardNumber,hold;
for(int i =0; i < cards.length; i++){
cardNumber = (int)(Math.random()*(cards.length-i)) + 1;
hold = cards[cardNumber];
cards[cardNumber] = cards[i];
@anupsavvy
anupsavvy / Puzzle.java
Created July 27, 2011 04:55
Write a method to decide if two strings are anagrams are not.
public class Puzzle{
public static boolean findAnagrams(String s1, String s2){
if(s1 == null && s2!=null)
return false;
if(s1!=null && s2==null)
return false;
if(s1==null && s2==null)
return true;
if(s1.length()!=s2.length())
@anupsavvy
anupsavvy / sdword2vec.py
Created October 9, 2015 16:39
Load science direct articles and create doc2vec vectors for each one of them.
#coding:utf-8
# Author: Anup Sawant
# Purpose: Doc2vec vectors of Science Direct Articles
# Created: 9/21/2015
import sys
import os
import pandas as pd
from pandas import Series, DataFrame