Skip to main content Accessibility help
×
Hostname: page-component-84b7d79bbc-g7rbq Total loading time: 0 Render date: 2024-07-29T18:36:45.228Z Has data issue: false hasContentIssue false

12 - Ranking suffixes

Published online by Cambridge University Press:  05 March 2013

Richard Bird
Affiliation:
University of Oxford
Get access

Summary

Introduction

The idea of ranking the elements of a list crops up frequently. An element x is assigned rank r if there are exactly r elements of the list less than x. For example, rank [51, 38, 29, 51, 63, 38] = [3, 1, 0, 3, 5, 1]. This scheme ranks from 0 and from lowest to highest, but one can also rank from 1 and from highest to lowest, as when ranking candidates by their marks in an examination. Rankings are distinct if and only if the list does not contain duplicates, in which case rank xs is a permutation of [0 .. length xs − 1].

In this pearl we consider the problem of ranking the suffixes of a list rather than the list itself. It takes Θ(n log n) steps to rank a list of length n, assuming a test x < y takes constant time. Since in the worst case it takes Θ(n) such tests to make one lexicographic comparison between two suffixes of a list of length n, it seems that ranking the suffixes of a list should require Θ(n2 log n) basic comparisons. The point of this pearl is to show that only Θ(n log n) steps are necessary. Asymptotically speaking, it takes no more time to rank the suffixes of a list than it does to rank the list itself. Surprising but true.

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

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.

  • Ranking suffixes
  • Richard Bird, University of Oxford
  • Book: Pearls of Functional Algorithm Design
  • Online publication: 05 March 2013
  • Chapter DOI: https://doi.org/10.1017/CBO9780511763199.013
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.

  • Ranking suffixes
  • Richard Bird, University of Oxford
  • Book: Pearls of Functional Algorithm Design
  • Online publication: 05 March 2013
  • Chapter DOI: https://doi.org/10.1017/CBO9780511763199.013
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.

  • Ranking suffixes
  • Richard Bird, University of Oxford
  • Book: Pearls of Functional Algorithm Design
  • Online publication: 05 March 2013
  • Chapter DOI: https://doi.org/10.1017/CBO9780511763199.013
Available formats
×