Skip to content

Instantly share code, notes, and snippets.

View ziyoshams's full-sized avatar

Ziyo Shamisiddini ziyoshams

View GitHub Profile

ANSWERS

Pascals Triangle

Click here to run the code.

const pascalsTriangle = (level) => {
  if(level > 25 || level < 2) throw new Error('Chose a number between 2 and 25');
  
  let initialArray = [1];
class Node {
constructor(value) {
this.value = value;
this.left = null;
this.right = null;
}
}
class BST {
constructor(value) {
doesPathExist(firstNode, secondNode){
// we will approach this BFS way
let path = [];
let visited = this.createVisitedObject();
let q = [];
visited[firstNode] = true;
q.push(firstNode);
while(q.length){
let node = q.pop();
path.push(node);
dfs(startingNode){
let visited = this.createVisitedObject();
this.dfsHelper(startingNode, visited);
}
dfsHelper(startingNode, visited){
visited[startingNode] = true;
console.log(startingNode);
let arr = this.AdjList.get(startingNode);
// HELPER FUNCTION
createVisitedObject(){
let arr = {};
for(let key of this.AdjList.keys()){
arr[key] = false;
}
return arr;
}
// Breadth First Search
class Graph {
constructor() {
this.AdjList = new Map();
}
addVertex(vertex) {
if (!this.AdjList.has(vertex)) {
this.AdjList.set(vertex, []);
} else {
throw 'Already Exist!!!';
@ziyoshams
ziyoshams / Graph.js
Created July 24, 2018 23:51
Graph consructor
class Graph {
constructor() {
this.AdjList = new Map();
}
// BASIC METHODS
// addVertex(vertex) {}
// addEdge(vertex, node) {}
// print() {}
}