Skip to content

Instantly share code, notes, and snippets.

View zapstar's full-sized avatar

Thirumal Venkat zapstar

View GitHub Profile
@zapstar
zapstar / SecondLargest.java
Created May 2, 2014 06:17
Finds the second largest element in an array within n + log(n)_base2 -2 comparisons
import java.util.LinkedList;
/**
* @author thiru
*
*/
public class SecondLargest {
private class TreeNode {
int item;
@zapstar
zapstar / fast_multiply.py
Created April 21, 2014 16:41
A method for multiplying faster than our repeated addition
# Really cool algorithm I learnt from a blog somewhere
# Also sometimes called russian's peasents algorithm
def fast_multiply(a,b):
z=0;
while a > 0:
if a % 2 == 1:
z = z + b
a = a >> 1
b = b << 1
@zapstar
zapstar / Notes on Logic: Language and Information 1.md
Last active August 29, 2015 13:57
My notes for the Coursera course on Language and Information of Logic

Logic: Language and Information 1

Propositions: Fundamental units of information. You can assert/deny, agree/disagree, believe/not believe


Connectives

  • ~A is true only when A is false
  • A & B is true, only when both A and B are true
@zapstar
zapstar / list_comprehension.py
Created March 28, 2014 04:19
List Comprehension in Python (Quick Reference)
# Syntax: All in one line or by escape characters
# [ <some expression to be evaluated and put in another list>
# for <some iterating variable in the list>
# in <some list>
# if <some condition holds true>
# ]
mylist = [10,20,30,40,50,60,70,80,90,100]
# create a new list containing variables in the list divided by 10
@zapstar
zapstar / BitBoolean.java
Created March 17, 2014 05:59
Bit boolean class in Java for implementing a more space-efficient boolean storage (1 bit instead of 1 byte). All operations are O(1).
import java.util.Map;
import java.util.HashMap;
public class BitBoolean {
//Holds boolean data as bits
//Each byte can hold 8 boolean values
//So index = booleanDataIndex + booleanMappingIndex
//booleanDataIndex = index/8
//boleanMappingIndex, see booleanMapping variable
@zapstar
zapstar / Notes on Linear Regression
Last active August 29, 2015 13:57
Notes on linear regression chapter from 15.071x = Analytics Edge (Week 02)
Dependent variable = y what we predict
Independent variable = x's. What we use to predict y.
Baseline Prediction: We take the average of all y in the training set and predict that no matter what x is input into the model.
One variable linear regression:
y_i = B_0 + B_1 * x_i + e_i
y_i = i'th independent variable
B_0 = intercept term (the value of y when x is 0)