Data Structures and Algorithms in JavaScript Data Structures and Algorithms in JavaScript

Exercise: Bubble, Insertion, and Selection Sort

Check out a free preview of the full Data Structures and Algorithms in JavaScript course:
The "Exercise: Bubble, Insertion, and Selection Sort" Lesson is part of the full, Data Structures and Algorithms in JavaScript course featured in this preview video. Here's what you'd learn in this lesson:

In this exercise, you will implement the elementary sorting algorithms covered in this section. These algorithms include Bubble Sort, Insertion Sort, and Selection Sort.

Get Unlimited Access Now

Transcript from the "Exercise: Bubble, Insertion, and Selection Sort" Lesson

[00:00:00]
>> Bianca Gandolfo: What we're gonna be doing is we're gonna implement all of the elementary sorting algorithms, bubble, insertion, and selection. Keep in mind that when you're testing out your code, the fact that it's coming out sorted at the end isn't necessarily a sign that you're doing it right. Because for these particular sorting algorithms, what you wanna check for is that you're doing it in the order.

[00:00:21] And the logic is the same. So you might need to put a debugger in there and walk through your code. Maybe you throw in console dot logs or whatever your style is, just to make sure that it's going in the order that you expect. Because it can be easy to think you got them all right just because it comes out sorted, when actually, the logic's a little bit off.

[00:00:42] Like maybe you're doing an insertion sort for a selection sort, or vice versa, or you're accidentally doing the same thing twice. So keep that in mind.