Skip to main content Accessibility help
×
Hostname: page-component-76fb5796d-wq484 Total loading time: 0 Render date: 2024-04-27T18:53:28.106Z Has data issue: false hasContentIssue false

Part five - Exercise Solutions

Published online by Cambridge University Press:  05 June 2012

Jeff Edmonds
Affiliation:
York University, Toronto
Get access

Summary

Iterative Algorithms: Measures of Progress and Loop Invariants

Selection Sort: If the input for selection sort is presented as an array of values, then sorting can happen in place. The first k entries of the array store the sorted sublist, while the remaining entries store the set of values that are on the side. Finding the smallest value from A[k + 1] … A[n] simply involves scanning the list for it. Once it is found, moving it to the end of the sorted list involves only swapping it with the value at A[k + 1]. The fact that the value A[k + 1] is moved to an arbitrary place in the right-hand side of the array is not a problem, because these values are considered to be an unsorted set anyway. The running time is computed as follows. We must select n times. Selecting from a sublist of size i takes Θ(i) time. Hence, the total time isΘ(n + (n–1) + … + 2 + 1) = Θ(n2) (see Chapter 26).

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2008

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • Exercise Solutions
  • Jeff Edmonds, York University, Toronto
  • Book: How to Think About Algorithms
  • Online publication: 05 June 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9780511808241.031
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • Exercise Solutions
  • Jeff Edmonds, York University, Toronto
  • Book: How to Think About Algorithms
  • Online publication: 05 June 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9780511808241.031
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • Exercise Solutions
  • Jeff Edmonds, York University, Toronto
  • Book: How to Think About Algorithms
  • Online publication: 05 June 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9780511808241.031
Available formats
×