Skip to content

Instantly share code, notes, and snippets.

View bruceoutdoors's full-sized avatar
🧗

Lee Zhen Yong bruceoutdoors

🧗
View GitHub Profile
@bruceoutdoors
bruceoutdoors / TableToTree.js
Created March 8, 2015 12:50
Table To Tree Algorithm implementation in TestComplete JScript
function Leaf(name)
{
this.Name = name;
this.ParentBranch = null;
}
Branch.prototype = new Leaf();
Branch.prototype.constructor = Branch;
Branch.prototype.Super = Leaf.prototype;
@bruceoutdoors
bruceoutdoors / example-run-sjf.txt
Last active August 29, 2015 14:26
SJF example using input text file. NOTE: The algorithm itself is wrong!!
[bruceoutdoors@BruceManjaro bash]$ ./sjf.sh input.txt
Process Name: P1
Arrival Time: 2
Burst Time: 6
Priority: 7
Process Name: P2
Arrival Time: 1
Burst Time: 8
Priority: 1
@bruceoutdoors
bruceoutdoors / meaure-run-time.cpp
Last active November 5, 2015 07:04
Measure running time using chrono (C++11). Enable/disable printing the time by comment/uncomment the __EXE_CLOCK__ macro. This is also solution for Hashmat the Brave Warrior (UVa 10055), excluding the __EXE_CLOCK__ macro.
/*
sample run:
./measure-run-time < source-input.txt
output:
2
4
100
** elapsed time: 0.523ms **
@bruceoutdoors
bruceoutdoors / generic-lis.cpp
Created November 5, 2015 16:34
Generic longest increasing subsequence (LIS) dynamic programming solution (O(n^2) time)
#include <iostream>
#include <functional>
#include <deque>
#include <vector>
using namespace std;
template<typename T>
deque<T> find_lis(const vector<T> &a,
function<bool(const T &, const T &)> comp = [&](const T &a, const T &b)->bool { return a < b; })
@bruceoutdoors
bruceoutdoors / mat-chain-mult-recursive.cpp
Last active November 17, 2015 13:03
Matrix Chain Multiplication recursive solution
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
using namespace std;
vector<int> rc;
int B(int i, int j)
@bruceoutdoors
bruceoutdoors / mat-chain-mult-dp.cpp
Last active November 17, 2015 16:22
Matrix Chain Multiplication Dynamic Programming Implementation
#include <algorithm>
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
vector<int> rc;
vector< vector<int> > DP;
@bruceoutdoors
bruceoutdoors / mat-chain-mult-dp-trace.cpp
Last active November 18, 2015 09:45
Matrix Chain Multiplication Dynamic Programming Implementation with trace
#include <algorithm>
#include <iostream>
#include <vector>
#include <climits>
#include <string>
using namespace std;
vector<int> rc;
vector< vector<int> > DP, splits;
@bruceoutdoors
bruceoutdoors / csv.cpp
Last active December 7, 2015 04:24
Simple CSV file reader. Only reads comma delimited files, though it doesn't take must effort to customize that...
#include "csv.h"
#include <fstream>
#include <sstream>
#include <stdexcept>
Csv::Csv(const string &dir)
{
directory = dir;
read(dir);
}
@bruceoutdoors
bruceoutdoors / knapsack-select.cpp
Last active December 13, 2015 13:41
Select items from knapsack 1-0 problem - www.spoj.com/problems/KNAPSACK/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> v, c;
vector< vector<int> > DP;
void pick(int i, int w)
@bruceoutdoors
bruceoutdoors / knapsack-dp.cpp
Last active December 13, 2015 13:42
Dynamic programming solution to http://www.spoj.com/problems/KNAPSACK/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<int> v, c;
int S, N; cin >> S >> N;