Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@calmhandtitan
calmhandtitan / Articulation_points.cpp
Created December 25, 2013 00:23
C++ program to find the articulation/cut vertices in a graph..
#include "stdio.h"
#include "stdlib.h"
#include "limits.h"
#include "math.h"
#include "string.h"
#include "stdint.h"
#include "stack"
#include "queue"
#include "vector"
#include "set"
@calmhandtitan
calmhandtitan / Kruskal_MST.cpp
Created December 25, 2013 00:20
C++ implementation of Kruskal's Algorithm for finding the MST using Union-Find Data Structure
//Kruskal using Union_Find
#include "stdio.h"
#include "string.h"
#include "vector"
#include "algorithm"
using namespace std;
#define pii pair<int, int>
#define pip pair<int, pii>
#define F first
@calmhandtitan
calmhandtitan / SARRAY_nlogn.cpp
Created December 25, 2013 00:13
Suffix Array Construction in O(nlogn) using Manber and Myers algo and linear time LCP array construction
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "algorithm"
using namespace std;
// Begins Suffix Arrays implementation
// O(n log n) - Manber and Myers algorithm
// Refer to "Suffix arrays: A new method for on-line txting searches",
// by Udi Manber and Gene Myers
@calmhandtitan
calmhandtitan / BIT2.c
Created December 9, 2013 20:30
Point sum query, Range update Binary Indexed tree
//Point sum query, Range update Binary Indexed tree
//Author: Chandan Mittal
#include<stdio.h>
int BIT[10010], a[10010], n;
int query(int k)
{
int s =0;
while(k > 0)
@calmhandtitan
calmhandtitan / BIT1.c
Created December 9, 2013 20:29
Point Update, Range Sum Query Binary Indexed Tree
//Point Update, Range Sum Query Binary Indexed Tree
//Author: Chandan Mittal
#include<stdio.h>
int BIT[100010], n, a[100010];
void update(int x, int v)
{
while(x <= n)
{
@calmhandtitan
calmhandtitan / trie.cpp
Created December 9, 2013 13:42
C++ implementation of Trie
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <algorithm>
using namespace std;
struct node
{
int prefix_count;
bool isEnd;
@calmhandtitan
calmhandtitan / kmp.C
Created December 9, 2013 13:40
C implementation of Knuth Morris Pratt Algorithm for pattern searching in linear time
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void computeLPSarray(char *pat, int M, int *lps)
{
int len = 0; //lenght of previous longest prefix suffix
int i ;
lps[0] = 0 ; //lps[0] is always 0
@calmhandtitan
calmhandtitan / pollard_rho.cpp
Created November 20, 2013 21:05
Prime factorization of an Integer using Pollard Rho Algorithm
/*
Algo: Pollar Rho
Task: Prime Factorization of an Integer
Author: Chandan Mittal
*/
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "time.h"
@calmhandtitan
calmhandtitan / Seg_tree.cpp
Last active February 16, 2018 14:36
Segment Tree implementation for Range Maximum Query with Build, Query and Update Operations
/*
Segment Tree implementation for Range Maximum Query
Author: Chandan Mittal
*/
#include "stdio.h"
#include "stdlib.h"
#include "limits.h"
#include "math.h"
#include "string.h"
#define min(a,b) (a)<(b)?(a):(b)
@calmhandtitan
calmhandtitan / Graph.cpp
Created September 13, 2013 20:16
class graph with built-in dfs function using Stack(as a class)
#include "stdio.h"
#include "string.h"
#define MAX 1000
class stack
{
int arr[MAX];
int idx;
public:
stack()