Data Structures and Algorithms in JavaScript – Full Course for Beginners




Learn common data structures and algorithms in this tutorial course. You will learn the theory behind them, as well as how to program them in JavaScript.

⭐️ Contents (link to code after title) ⭐️
⌨️ Stacks (00:21) https://codepen.io/beaucarnes/pen/yMBGbR?editors=0012
⌨️ Sets (09:03) https://codepen.io/beaucarnes/pen/dvGeeq?editors=0012
⌨️ Queues & Priority Queues (19:24) https://codepen.io/beaucarnes/pen/QpaQRG?editors=0012
⌨️ Binary Search Tree (26:03) https://codepen.io/beaucarnes/pen/ryKvEQ?editors=0011
⌨️ Binary Search Tree: Traversal & Height (39:34) https://codepen.io/beaucarnes/pen/ryKvEQ?editors=0011
⌨️ Hash Tables (53:19) https://codepen.io/beaucarnes/pen/VbYGMb?editors=0012
⌨️ Linked List (1:03:04) https://codepen.io/beaucarnes/pen/ybOvBq?editors=0011
⌨️ Trie (1:14:59) https://codepen.io/beaucarnes/pen/mmBNBd?editors=0011
⌨️ Heap (max and min) (1:27:29) https://codepen.io/beaucarnes/pen/JNvENQ?editors=0010
🔗 Heap visualization: https://www.cs.usfca.edu/~galles/visualization/Heap.html
⌨️ Graphs: adjacency list, adjacency matrix, incidence matrix (1:42:07)
⌨️ Graphs: breadth-first search (1:46:45) https://codepen.io/beaucarnes/pen/XgrXvw?editors=0012

📄Data structures article by Beau Carnes: https://medium.freecodecamp.org/10-common-data-structures-explained-with-videos-exercises-aaff6c06fb2b
🐦Follow creator Beau Carnes on Twitter: https://twitter.com/carnesbeau

🔗Beau also made this Algorithms course from Manning Publications: https://www.manning.com/livevideo/algorithms-in-motion?a_aid=algmotion&a_bid=9022d293 (Promo code: 39carnes)

Learn to code for free and get a developer job: https://www.freecodecamp.org

Read hundreds of articles on programming: https://medium.freecodecamp.org

And subscribe for new videos on technology every day: https://youtube.com/subscription_center?add_user=freecodecamp

Original source


28 responses to “Data Structures and Algorithms in JavaScript – Full Course for Beginners”

  1. Here is the full remove function:

    remove(data) {
    const removeNode = function(node, data) {
    if (node == null) {
    return null;
    }
    if (data == node.data) {
    // node has no children
    if (node.left == null && node.right == null) {
    return null;
    }
    // node has no left child
    if (node.left == null) {
    return node.right;
    }
    // node has no right child
    if (node.right == null) {
    return node.left;
    }
    // node has two children
    var tempNode = node.right;
    while (tempNode.left !== null) {
    tempNode = tempNode.left;
    }
    node.data = tempNode.data;
    node.right = removeNode(node.right, tempNode.data);
    return node;
    } else if (data < node.data) {
    node.left = removeNode(node.left, data);
    return node;
    } else {
    node.right = removeNode(node.right, data);
    return node;
    }
    }
    this.root = removeNode(this.root, data);
    }

  2. I think your difference method for Set is wrong!
    Lets say we have two sets
    setA = [1, 2, 3, 4]
    setB = [2, 3, 5, 6, 7]

    If we do
    setA.difference(setB)
    we get [1, 4] which I think is wrong.
    Should it not be [1, 4, 5, 6, 7] as we are getting the difference between two sets?

  3. Thank you for this.. I have one concern regarding sets data structure. The current difference function is returning what is in setA but not in setB. I have tried to implement the function which returns the difference between the two. Hopefully it will help.

    this.difference = function(otherSet) {

    var differenceSet = new mySet();

    var _this = this;

    var set1 = this.values();

    var set2 = otherSet.values();

    set1.forEach(function(e){

    if(!otherSet.has(e)){

    differenceSet.add(e);

    }

    });

    set2.forEach(function(e){

    if(!_this.has(e)){

    differenceSet.add(e);

    }

    });

    return differenceSet;

    };

  4. I love Beau and his videos, but I'd like to know if this course has new or better material than his previous Data Structures and Algorithms videos, because those are in digestible chunks and I'd rather watch those if it's the same material. So basically, should I watch this or the old videos?

  5. The Set implementation is not correct, you are using indexOf(), which has a time complexity of O(n). The real implementation of Set.add() uses hash tables, which takes O(1). Deletion in the queue should take O(1), but your implementation takes O(n)

Leave a Reply