This course and others like it are available as part of our Frontend Masters video subscription.
Table of Contents
IntroductionBianca Gandolfo begins her Data Structures & Algorithms course by sharing her background and how she developed this course. She will be using a cooking metaphor throughout the course because she believes learning these concepts involves understanding the “recipes”, watching them in action, and getting time to try them out yourself.
Agenda and ScopeBianca quickly walks through the agenda and scope of this six-day course. The fundamentals introduced and practiced in the first day will be used throughout the rest of the course. This course is based on university-level computer science courses and covers the most common data structures and algorithms programmers use today.
How to SucceedUsing a “fad diet” metaphor, Bianca explains what it takes to succeed in this course. She recommends pairing up with someone or a team of people to try the exercises and discuss the solutions. Ask questions and don’t be afraid of failure.
Creating a Constructor SolutionBianca walks through the solution to the Creating a Constructor exercise.
Stacks & Queues
StacksThe first data structure Bianca introduces is a stack. With each data structure, she will be drawing it out, pseudocoding it, then putting it to work with an API and any applicable algorithms. The stacks API follows a last-in-first-out model where the last item added to the stack is the first item removed.
Implementing a StackBianca implements each method of the Stack object. The constructor initializes the storage object. In this case, she’s using a String for storing the stack data. She then implements the push() and pop() methods which add and remove items from the stack.
QueuesQueues are similar to a stack except for the order in which items are added. In the case of a queue, the first item in is the first item out. Rather than push() and pop() methods, a queue has an enqueue() method for adding items and a dequeue() method for removing items.
Exercise: Creating Stacks and QueuesIn this exercise, you will implement both the Stack and Queue data structures. Each data structure is stubbed out and commented with the instructions for what you need to complete. – https://github.com/kuychaco/algoClass/blob/master/data-structures/stack.js,
Creating Stacks and Queues SolutionBianca walks through the solution to the Creating Stacks and Queues exercise. he code for the solution is located on the “solutions” branch in the Github exercise repository. – https://github.com/kuychaco/algoClass/blob/solutions/data-structures/stack.js
Why Recursion?Recursion occurs when a function calls itself. Bianca makes a case for recursion and talks about why understanding the core concepts will make it easier to understand other use cases like recursive algorithms or recursive data structures.
Tracing Recursive ExecutionBianca explores a recursive function by tracing through each call. The callMe() function continues to call itself until the tracker variable satisfies the base case. If the function’s base case is never reached, an infinite loop may occur.
Template for a Recursive FunctionBianca summarizes her recursion introduction by sharing the recipe for a recursive function. You identify the base case, identify the recursive case, return when appropriate, and write procedures that bring you closer to the base case.
Factorial with LoopUsing factorials as an example, Bianca first looks at how the factorial algorithm would be implemented with a for() loop. The loop starts at the number 2 and continues to multiply the numbers together until the desired factorial is reached. She will use this example as a baseline for implementing the recursive example.
Factorial with RecursionBianca now looks at the implementation of the factorial algorithm with recursion. The recursive computeFactorial(num) function continues to call itself while decrementing the num parameter. Once num is equal to one, the function returns and the results of all the calls on the stack are multiplied together.
Exercise: Recursion Interview QuestionsIn this exercise, you will implement a common recursion questions that are often asked during job interviews. – https://github.com/kuychaco/algoClass/blob/master/recursion/recursionIntro.js
Recursive Reverse SolutionBianca begins walking through the solution to the Recursion Interview Questions exercise. The first question she answers is how to implement a recursiveReverse() function.
Recursive Multiplier SolutionBianca continues her demonstration of the solution to the Recursion Interview Questions exercise by implementing the recursiveMultiplier() function.
Implementing a Queue with Two Stacks SolutionBianca continues working through the exercises left over from the Stacks & Queues topic. In this video, she looks at the solution to implementing a queue by using two stacks.