Skip to content

Instantly share code, notes, and snippets.

@abnayak
abnayak / graph.md
Created December 10, 2020 04:19
GraphConcepts

Graph Concepts

Representing a graph

A graph can be represented as adjacency matrix or adjacency list.

Building Adjacency matrix from edge list

For a undirected graph {a,b} implies path from a to b and b to a. For directed graph {a,b} implies only path from a to b.

public Map> buildGraph(int[][] edges) {
@abnayak
abnayak / brewInstall.sh
Created July 4, 2019 08:19
Brew Installer
#!/bin/bash
CASKS=(
adoptopenjdk
alfred
brave-browser
calibre
evernote
firefox
geekbench
@abnayak
abnayak / gist:00ba771ebcb1221ec845f7e86b03690c
Last active February 22, 2019 21:52
iTerm3 + tmux + eternal-terminal = happiness
# Setup on Mac
// Place your settings in this file to overwrite the default settings
{
"editor.fontSize": 16,
"window.zoomLevel": 0,
"workbench.colorTheme": "Visual Studio Dark",
"editor.renderWhitespace": "all",
"java.errors.incompleteClasspath.severity": "ignore",
"prettier.printWidth": 120,
"prettier.tabWidth": 4,
"telemetry.enableTelemetry": false,
@abnayak
abnayak / index.html
Created February 27, 2017 08:11
Center align a button in bootstrap navbar
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<style>
@abnayak
abnayak / Sublime C++11 build file
Created October 11, 2015 03:46
Sublime C++11 build file
{
"shell_cmd": "g++ -std=c++11 \"${file}\" -o \"${file_path}/${file_base_name}\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"variants":
[
{
"name": "Run",
@abnayak
abnayak / tsws
Last active September 6, 2015 18:11 — forked from dfletcher/tsws
Totally simple web server using Bash and netcat (nc)
#!/bin/bash
# --------------------------------
# Totally Simple Web Server (TSWS)
# --------------------------------
#
# (c) 2015 Dave Fletcher
# All Rights Reserved
#
# This is free and unencumbered software released into the public domain.
@abnayak
abnayak / reverseWords.cpp
Created January 24, 2014 02:23
CPP: Reverse the works of a given string.
#include <iostream>
#include <algorithm>
/*
Input: "Hello how are you"
Output: "olleH woh era uoy"
*/
using namespace std;
void printReverse(string str){
@abnayak
abnayak / MaxRootToLeafSum.cpp
Created January 20, 2014 06:43
CPP: Find the maximum sum of nodes values from root to leaf in a BST
void MaxRootToLeafSum(node *root, int & maxSum, int currentSum){
if ( !root )
return;
if ( root->data + currentSum > maxSum )
maxSum = root->data + currentSum ;
currentSum += root->data;
@abnayak
abnayak / BST.cpp
Created January 20, 2014 06:29
CPP: BST creation, In-order Traversal, Level-Order Traversal.
#include <iostream>
#include <malloc.h>
#include <stack>
#include <queue>
using namespace std;
typedef struct node {
int data;
struct node* left;