Skip to content

Instantly share code, notes, and snippets.

@viniru
viniru / ClusterS.java
Last active July 28, 2018 20:54
Clustering - Stanford
import java.io.FileNotFoundException;
import java.util.*;
import java.io.File;
public class ClusterS {
int max = 99999999;
int ne=0;
int nn ;
int clusters;
HashMap<Integer, Nodes> hm = new HashMap<>();
ArrayList<Edge> edges = new ArrayList<>();
@viniru
viniru / ClusterB.java
Created July 28, 2018 18:13
Clustering problem
import java.util.*;
import java.io.File;
public class ClusterB {
int n;
int bitsn;
int clusters ;
HashMap<String,Nodes> cl = new HashMap<>();
void getInput() {
try {
File f = new File("C:\\Users\\vinir_000\\IdeaProjects\\Learn\\src\\input.txt");
@viniru
viniru / points.txt
Created July 24, 2018 10:51
important points
1) In java : When you are using Math.ceil or Math.floor(a/b) , a/b will not be a float number if a or b are integers . so , dont forget to
type cast to floor , either of the integers a or b before dividing.
@viniru
viniru / MST.java
Last active July 26, 2018 15:51
Minimum spanning tree by using minumum heap
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Scanner;
public class MST
{
HashMap<Node,ArrayList<Pair>> al; //adjacency list to store the graph
ArrayList<Node> map; //map a vertex to its respective vertex object
Heap heap;
int nodes ;
int edges ;
@viniru
viniru / CPU_SCHEDULING.java
Created July 23, 2018 07:48
cpu scheduling alogorithm based on weight/length ratio of the jobs
import java.util.*;
public class CPU_SCHEDULING{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int temp = n;
ArrayList<Node> ar = new ArrayList<>();
while(n-->0)
{
@viniru
viniru / Sum
Created July 5, 2018 11:56
dqqw
import java.util.*;
public class Sum
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
TreeSet<Long> ts = new TreeSet<>();
ArrayList<Long> al1 = new ArrayList<>();
ArrayList<Long> al2 = new ArrayList<>();
HashSet<Long> hs = new HashSet<>();
@viniru
viniru / Dijkshtra.java
Last active July 5, 2018 07:58
Dijkshtra's algorithm using Min Heap in java. input : graph contains exactly 200 elements represented in terms of adjacency list.format : vertex space neighbour_vertex1, weight neighbour_vertex2,weight so on. every new line contains a list for one vertex
import java.util.*;
import java.lang.Math;
public class Dijkshtra{
int xx = 201;
HashMap<Integer,ArrayList<Pair>> al; //adjacency list
boolean X[] = new boolean[xx];
MinHeap heap = new MinHeap();
int[] distance = new int[xx];
Dijkshtra()
@viniru
viniru / Median.java
Last active July 5, 2018 08:01
Find the median at every step in log(n) time while inserting random integers .
import java.util.*;
import java.lang.Math;
public class Median
{
public static void main(String args[])
{
long sum = 0;
@viniru
viniru / MaxHeap.java
Created July 3, 2018 11:50
Min Heap using java with build heap , delete by passing postion of the element to be deleted and insertion of an element.
import java.util.*;
import java.lang.Math;
public class MaxHeap {
ArrayList<Integer> ar = new ArrayList<>();
int size = 0;
void delete(int pos)
{
ar.set(pos,ar.get(ar.size()-1));
@viniru
viniru / MinHeap.java
Created July 3, 2018 11:45
Min Heap using java with build heap , delete by passing postion of the element to be deleted and insertion of an element.
import java.util.*;
import java.lang.Math;
public class MinHeap {
ArrayList<Integer> ar = new ArrayList<>();
int size = 0;
void delete(int pos)
{
ar.set(pos,ar.get(ar.size()-1));