Skip to content

Instantly share code, notes, and snippets.

View osjayaprakash's full-sized avatar
💭
I may be slow to respond.

Jayaprakash Sundararaj osjayaprakash

💭
I may be slow to respond.
View GitHub Profile
@osjayaprakash
osjayaprakash / SelectionAlgorithm.cpp
Last active October 6, 2015 21:07
Selection Algorithm - Kth Largest / Smallest from unsorted list in O(n)
int A[MAX], N;
int partitions(int low, int high) {
int p=low, r=high, x=A[r], i=p-1;
for (int j=p; j<=r-1; j++) {
if (A[j]<=x){
i=i+1;
swap(A[i],A[j]);
}
}
@osjayaprakash
osjayaprakash / StableMarriageProblem.cpp
Last active October 6, 2015 23:37
Stable Marriage Problem
while (unenm != 0) {
while (men[j] != -1)
j++; //man no. j is unengaged. he proposes to men2[j].
int wc = m[j][men2[j]];
if (women[wc] == -1){ //wc and j get engaged
women[wc] = j;
men[j] = wc;
unenm --;
j = 0;
} else if (w[wc][women[wc]] > w[wc][j]) {
@osjayaprakash
osjayaprakash / PQueue.cpp
Last active October 7, 2015 03:37
Kthe Largest Element
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
using namespace std;
struct compare {
@osjayaprakash
osjayaprakash / MLE_LAPLACE.java
Created August 25, 2012 07:39
Maximum Liklihood Estimator for Laplace Density Function
/*
* Author : JAYAPRAKASH S
* Maximum liklihood estimator for Laplace density function
* Mail : first_name [at] cse [dot] iitb [dot] ac [dot] com
* Please mail me, if any error is found.
*/
import java.util.ArrayList;
import java.util.Collections;
@osjayaprakash
osjayaprakash / SPOJ-RENT.cpp
Last active December 10, 2015 00:49
Scheduling, Dynamic Programming, SPOJ, Rent, Binary Search
#include <iostream>
#include <algorithm>
using namespace std;
class _x{
public: int s, e, p,m;
}VAL[10005];
int N;
@osjayaprakash
osjayaprakash / SPOJ-BUZZOFF.cpp
Created December 21, 2012 19:18
Matrix Exponentiation, Recurrence Eqn, Fibonacci
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const long long int mod = 1000000007;
class _matrix{
public:
long long int x[2][2];
int n,m;
#include <iostream>
#include <cstring>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
char str[]="ALLIZZWELL";
int v[105][105];
@osjayaprakash
osjayaprakash / SPOJ-WORKB.cpp
Created December 22, 2012 18:34
Greedy , SPOJ
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX=100025;
int N,A,B;
int v[MAX];
int min2(int a, int b) {
@osjayaprakash
osjayaprakash / SPOJ-QUEST5.cpp
Created December 22, 2012 18:37
SPOJ, Greedy
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX=100025;
class _x{
public:
int s,e;
}v[MAX];
#include <iostream>
#include <cstring>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
char str[]="ALLIZZWELL";
int v[105][105];