# Examples in JavaScript

src - FreeCodeCamp-youtube (opens new window)

# Stack

Functions : pop, push, peek, length

In JavaScript we have Array

# Queue

Functions : print, enqueue, dequeue, front, isEmpty, length

In JavaScript we have Array

# Binary Search Tree

Functions : add, findMin, findMax, remove, isPresent

In JavaScript we have Array

Remove node - Go to node.right then find the min ie most left node is this subtree

  • The left is always lower and right is always greater.

# Binary Search Tree - Traversal

  • Height = Length from root node to leaf node
  • There is min & max height
  • Min height = From root node to first node(without 2 children ie 0 or 1 children) 9 --> 17
  • Max height = from root node to bottom most node
  • If BST is balanced then max-min <= 1
  • Traversal
    • InOrder - From leftmost to rightmost node
    • PreOrder - Root nodes before then leaf nodes
    • PostOrder - Leaf nodes before then root nodes
    • LevelOrder - Breadth first search

# Linked List

# Graphs

# Adjacency List

// undirected
let graph = {
  a: ["b"],
  b: ["a", "c"],
  c: ["b"],
};

# Adjacency Matrix

// undirected
let graph = [
  [0, 1, 0],
  [1, 0, 1],
  [0, 1, 0],
];

// directed
let graph = [
  [0, 0, 0],
  [1, 0, 0],
  [0, 1, 0],
];

# Incidence Matrix

Graph Traversal - Distance between 2 nodes in graph. (BFS & DFS)

Last Updated: 4/19/2021, 3:50:02 PM