Skip to content

Instantly share code, notes, and snippets.

View 4db's full-sized avatar

Alex Dubinchyk 4db

View GitHub Profile
@4db
4db / test.js
Last active July 1, 2018 03:48
class Node {
/**
* @param {integer|string} id
*/
constructor(id) {
this.id = id;
this.children = [];
}
}
@4db
4db / unweighted_graph.js
Last active May 30, 2018 20:18
unweighted_graph.js
function Graph() {
var vm = this;
vm.vertices = [];
vm.edges = [];
vm.numberOfEdges = 0;
vm.addVertex = function(vertex) {
vm.vertices.push(vertex);
vm.edges[vertex] = [];
};
@4db
4db / depth_first_search.js
Created May 14, 2018 20:08
depth_first_search.js recursion for directed graph
function doDFS(root, tree) {
var parentInfo = {};
parentInfo[root] = 'None';
recursionDFSvisit = function(source, tree) {
tree[source].map(function(vertex) {
if (!parentInfo[vertex]) {
parentInfo[vertex] = source;
recursionDFSvisit(vertex, tree);
}
});
@4db
4db / bfs.js
Created May 11, 2018 20:35
breadth-first search in javascript
/*
* Performs a breadth-first search on a graph represent an object of array edges
* @param {string} source - The source vertex.
* @param {object} tree - Graph, represented as object.
* @returns {object} Object of objects describing each vertex, like
* { vertex : {distance: _, parent: _ } }
*/
function doBFS(sourse, tree) {
var pathInfo = {};
var level = 1;
@4db
4db / open_addressing.js
Created May 5, 2018 00:24
openaddressing
function HashTable() {
var vm = this;
vm._bucketSize = 10;
vm._buckets = [];
vm._buckets.length = vm._bucketSize;
vm.hashCode = function(str) {
var hash = 0, i, chr;
if (str.length === 0) return hash;
for (i = 0; i < str.length; i++) {
@4db
4db / chaining.js
Last active May 3, 2018 22:50
javscript hash
function Node(data) {
this.data = data;
this.next = null;
}
function SinglyList() {
var vm = this;
vm._length = 0;
vm.head = null;
@4db
4db / heapsort.js
Created May 2, 2018 17:58
heapsort javascript
function swap(arr, keyA, keyB) {
var temp = arr[keyA];
arr[keyA] = arr[keyB];
arr[keyB] = temp;
};
function heapSort(arr) {
var arrLen = arr.length;
var heapRoot = function (arr, i) {
var max = i;
@4db
4db / DocumentDistance.js
Created May 1, 2018 17:59
DocumentDistance
function DocumentDistance() {
var vm = this;
vm.vec1 = null;
vm.vec2 = null;
vm.text1 = null;
vm.text2 = null;
vm.setVector = function(text) {
var obj = {};
text.split(' ').map(function(w) {
=== PHASE 1 - Basics ===
* [X] Grokking Algorithms book
* [ ] Grokking Videos Algorithms in Motion Beau Carnes https://www.manning.com/dashboard
* [ ] Intro To Algorithms MIT Videos - 6.006 - https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-006-introduction-to-algorithms-fall-2011/
* [ ] Algorithm Design Manual Videos
* [ ] Read the Algorithm Design Manual
* [ ] Watch the Princeton Coursera course on algorithms (by Robert Sedgewick), mostly up until Dijkstra’s algorithm and not much more than that. Try to follow along and code as you go. You don’t need to implement things in Java unless you already know Java.(Phase 3)
* [ ] InterviewCake
=== PHASE 2 - Practice ===
@4db
4db / .vimrc
Created March 7, 2018 19:38
vim config
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
"part of ~/.vimrc