Skip to content

Instantly share code, notes, and snippets.

View shahril96's full-sized avatar
🐢

Mohd Shahril shahril96

🐢
View GitHub Profile
@shahril96
shahril96 / 8queensolver.c
Created April 9, 2016 15:28
Solve 8 Queens Problem using backtracking algorithm
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 8
int base[SIZE][SIZE];
void shuffle(int arrayNum[]) {
@shahril96
shahril96 / ratmazeprob.c
Created April 10, 2016 16:00
Using backtracking algorithm in order to solve "Rat in a Maze" problem
#include <stdio.h>
#include <stdbool.h>
#define N 6
// 0 = valid box to step
// x = invalid box to step (halangan)
char board[N][N] = {
{ 0 ,'x','x','x','x','x'},
{ 0 , 0 , 0 ,'x', 0 ,'x'},
@shahril96
shahril96 / kruskal_algo.cpp
Last active June 30, 2016 15:15
Find minimum spanning tree using Kruskal's algorithm
/*
* references
* 1) http://www.geeksforgeeks.org/greedy-algorithms-set-2-kruskals-minimum-spanning-tree-mst/
* 2) https://en.wikipedia.org/wiki/Kruskal%27s_algorithm
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
@shahril96
shahril96 / prim_algo.cpp
Last active July 1, 2016 18:15
Find MST in weighted graph using Prim's algorithm
/*
* references
*
* 1) http://www.geeksforgeeks.org/greedy-algorithms-set-5-prims-minimum-spanning-tree-mst-2/
* 2) https://www.cse.ust.hk/~dekai/271/notes/L07/L07.pdf
*
*/
#include <iostream>
#include <set>
@shahril96
shahril96 / dijkstras_algo.cpp
Created July 3, 2016 14:49
Using Dijkstra's algorithm to find the shortest path between 2 vertices inside a graph
/*
* references
*
* 1) http://www.geeksforgeeks.org/greedy-algorithms-set-6-dijkstras-shortest-path-algorithm/
* 2) http://home.cse.ust.hk/faculty/golin/COMP271Sp03/Notes/MyL09.pdf
*
*/
#include <iostream>
#include <set>
@shahril96
shahril96 / matrixChainMultiplication.cpp
Created July 4, 2016 15:33
Solve matrix chain multiplication using top-bottom dynamic programming technique
/**
*
* references :
*
* 1) http://www.geeksforgeeks.org/dynamic-programming-set-8-matrix-chain-multiplication/
* 2) https://home.cse.ust.hk/~dekai/271/notes/L12/L12.pdf
* 3) http://www.bowdoin.edu/~ltoma/teaching/cs231/spring14/Lectures/12-dynamicAndGreedy/matrixchain.pdf
*
**/
@shahril96
shahril96 / lis-nlogn.py
Created July 18, 2016 17:22
Longest increasing sub-sequence solver with complexity of O(n * logn)
def bin_search(lis, x):
lo, hi = 0, len(lis)-1
while lo < hi:
mid = int((hi+lo)/2)
if lis[mid] >= x:
hi = mid
else:
@shahril96
shahril96 / segmentTree.cpp
Created August 20, 2016 17:23
Segment Tree data structure (min property) (CP3 book's guide)
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class segmentTree {
private:
@shahril96
shahril96 / bit.cpp
Created August 28, 2016 01:40
Simple Binary Indexed Tree implementation (also called as Fenwick Tree)
#include <bits/stdc++.h>
using namespace std;
class BIT {
private:
vector<int> bit;
int n;
@shahril96
shahril96 / zbigz_snippet.js
Created September 11, 2016 17:45
Javascript snippet - List all files in ZbigZ without needing to click Next/Previous
javascript: [].forEach.call(document.querySelectorAll('.torrent'), function (el) { el.style.display = 'block'; });