38_split_Introduction to Algorithms 2nd Edition

38_split_Introduction to Algorithms 2nd Edition - design of...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
2 Getting Started This chapter will familiarize you with the framework we shall use throughout the book to think about the design and analysis of algorithms. It is self-contained, but it does include several references to material that will be introduced in Chapters 3 and 4. (It also contains several summations, which Appendix A shows how to solve.) We begin by examining the insertion sort algorithm to solve the sorting problem introduced in Chapter 1. We define a “pseudocode” that should be familiar to read- ers who have done computer programming and use it to show how we shall specify our algorithms. Having specified the algorithm, we then argue that it correctly sorts and we analyze its running time. The analysis introduces a notation that focuses on how that time increases with the number of items to be sorted. Following our discussion of insertion sort, we introduce the divide-and-conquer approach to the
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: design of algorithms and use it to develop an algorithm called merge sort. We end with an analysis of merge sort’s running time. 2.1 Insertion sort Our first algorithm, insertion sort, solves the sorting problem introduced in Chap-ter 1: Input: A sequence of n numbers ± a 1 , a 2 ,... , a n ² . Output: A permutation (reordering) ± a ³ 1 , a ³ 2 , ... , a ³ n ² of the input sequence such that a ³ 1 ≤ a ³ 2 ≤ ··· ≤ a ³ n . The numbers that we wish to sort are also known as the keys . In this book, we shall typically describe algorithms as programs written in a pseudocode that is similar in many respects to C, Pascal, or Java. If you have been introduced to any of these languages, you should have little trouble reading our al-gorithms. What separates pseudocode from “real” code is that in pseudocode, we...
View Full Document

This document was uploaded on 11/22/2010.

Ask a homework question - tutors are online