Functional Problem Solving (CSC 151 2013F) : EBoards

CSC151.02 2013F, Class 48: Merge Sort


Overview

Preliminaries

Admin

More efficient sorting techniques

Thinking about insertion sort ... * For a list of length n, we call insert n times * Insert into the empty list * Insert into a list of length 1 * Insert into a list of length 2 * Insert into a list of length 3 * And so and so forth * If we're lucky, insert happens at the front, that's one step Approximately n total calls to cons (or whatever) * If we're unlucky, insert happens at the end * Inserting into a sublist of length k takes about k recursive calls * Overall running time * 0 + 1 + 2 + ... n-1 is approximately (n^2)/2 * If I double the input size and I'm unlucky ... * E.g., if it's 1 minute to sort 100 things, it will take 4 minutes to sort 200 things (2n)^2/2 = 4(n^2)/2 * When we have an inefficient algorithm ... can we do better?

Divide and conquer, revisited

Analyzing merge sort


Samuel A. Rebelsky, rebelsky@grinnell.edu

Copyright (c) 2007-2013 Janet Davis, Samuel A. Rebelsky, and Jerod Weinman. (Selected materials are copyright by John David Stone or Henry Walker and are used with permission.)

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/3.0/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.