Check out a free preview of the full A Practical Guide to Algorithms with JavaScript course:
The "Bubble Sort & Merge Sort Exercise" Lesson is part of the full, A Practical Guide to Algorithms with JavaScript course featured in this preview video. Here's what you'd learn in this lesson:

## In this exercise, students implement bubble sort and merge sort.

Get Free Access Now

Transcript from the "Bubble Sort & Merge Sort Exercise" Lesson

[00:00:00]
>> Bianca Gandolfo: So our first learning exercise is implementing Bubble Sort. Remember, this is the Sort that loops through array, and it bubbles up the highest value each time. And our first task is to implement Bubble Sort. So I'm gonna let you do that. The second task that we have for sorting, is to implement MergeSort.

[00:00:25] We went through the pseudo-code quite a bit. So just a reminder that we're gonna split the array in halves, and we're gonna merge them recursively. And once we hit our base case, which is a sorted list of length one, right? So we're gonna check for that base case with length is, either less than two, or equals equals equals one.

[00:00:45] However you wanna do it is fine. And then, that's the base case, and you're gonna start returning out from your recursion. And you're going to compare the arrays item by item. And you're gonna return that result. So this is the conquer part of the divide and conquer paradigm.
{"ft_lang_label":"__label__en","ft_lang_prob":0.91107875,"math_prob":0.7646999,"size":1064,"snap":"2021-43-2021-49","text_gpt3_token_len":250,"char_repetition_ratio":0.12830189,"word_repetition_ratio":0.0,"special_character_ratio":0.2424812,"punctuation_ratio":0.13839285,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97193843,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-17T04:24:57Z\",\"WARC-Record-ID\":\"<urn:uuid:2d8d90b3-83ea-4277-abd8-ae05736f4f2b>\",\"Content-Length\":\"29838\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:3bb35eea-a334-463f-8807-a957d2f8e0eb>\",\"WARC-Concurrent-To\":\"<urn:uuid:f97999c4-6b90-4390-b456-080afc14aa88>\",\"WARC-IP-Address\":\"52.39.37.110\",\"WARC-Target-URI\":\"https://frontendmasters.com/courses/practical-algorithms/bubble-sort-merge-sort-exercise/\",\"WARC-Payload-Digest\":\"sha1:MZ75FXSYSKVQFMW5V7RIC2PCMVEY4YGS\",\"WARC-Block-Digest\":\"sha1:OBEL66XGV6XCINOF3OPP6HLTHRMPHHKF\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323585120.89_warc_CC-MAIN-20211017021554-20211017051554-00202.warc.gz\"}"}