Sorting algorithm
A sorting algorithm is a procedure that rearranges elements of a collection into an order determined by an ordering criterion.
Pandas Workout: 200 exercises to make you a stronger data analyst
Sorting orders tabular records according to the values of an index or one or more columns.
- How it is used
- Orders DataFrame rows and derived results for readable displays, rankings, and highest-or-lowest value queries.
- How deep it goes
- Distinguishes index and column ordering, then practices direction, multiple keys, and sorted aggregation outputs without algorithm internals.
- Examples
- Uses January 2019 NYC taxi rides and Stack Overflow survey salary summaries to practice ranked comparisons.
- What you can do after
- Apply it via pandas sort_values and sort_index to rank records, organize reports, and inspect grouped results.
MongoDB 8.0 in Action, Third Edition
Sorting is the ordering of query results according to one or more document fields.
- How it is used
- Orders MongoDB query results for presentation and navigation alongside skip and limit.
- How deep it goes
- Demonstrates sort directions and compound-index field order, but does not develop sorting-algorithm internals.
- Examples
- Shows routes ordered by stops and movies ordered by runtime and year, including a filtered movie query.
- What you can do after
- Apply it via MongoDB find().sort() and configure a matching compound index for multi-field ordering.
Read how MongoDB 8.0 in Action, Third Edition explains sorting algorithm →
Secrets of the JavaScript Ninja, Second Edition
An Array method that sorts an array in place using a comparison function or default ordering.
- How it is used
- Uses Array.sort() to order collections without implementing the sorting algorithm manually.
- How deep it goes
- Explains comparator return values and works through object sorting, but leaves the engine’s sorting algorithm behind the scenes.
- Examples
- Shows numeric subtraction as a comparator and sorts objects alphabetically by name with assertions checking their order.
- What you can do after
- Apply it via Array.sort() by writing a comparator for the desired item order.
Read how Secrets of the JavaScript Ninja, Second Edition explains sorting algorithm →
Python How-To
Sorting is the process of arranging elements into an order determined by a comparison or key function.
- How it is used
- Uses sorting to arrange task data according to project requirements.
- How deep it goes
- Explains default ordering, key functions, and in-place versus returned results without detailing the underlying sorting algorithm.
- Examples
- Orders task dictionaries by urgency and challenges readers to rank them by description length.
- What you can do after
- Apply sorting via Python’s sort and sorted with custom keys and descending order.
Python Workout, Second Edition
Sorting is the technique of arranging elements according to an ordering determined by their values or derived comparison keys.
- How it is used
- Applies ordering to nested Python data structures, especially lists of dictionaries prepared for display.
- How deep it goes
- Explains key functions, lambda, and itemgetter through exercises without descending into sorting algorithm internals.
- Examples
- Uses country dictionaries, string lengths, absolute values, vowel counts, nested-list sums, shell popularity, and multi-field movie records.
- What you can do after
- Builds country-sorting functions with named keys, lambdas, and operator.itemgetter.
Read how Python Workout, Second Edition explains sorting algorithm →
Tiny Python Projects: Learn coding and testing with puzzles and games
Sorting is the operation of arranging collection elements according to an ordering criterion.
- How it is used
- Deploys sorting to order command-line list data and to make randomized-program tests reproducible.
- How deep it goes
- Explains in-place and returned-list operations, reverse ordering, numeric behavior, and mixed-type errors, but not sorting algorithms internally.
- Examples
- Demonstrates sorted picnic output, REPL lists, descending order, numeric values, mixed-type failure, and sorted password words.
- What you can do after
- Apply it via Python list.sort() or sorted() to order data while choosing whether to mutate or preserve the original.
Building Web APIs with ASP.NET Core
Sorting is the ordering of query results according to one or more specified fields or expressions.
- How it is used
- Improves board-game API responses by ordering records before returning configurable result pages.
- How deep it goes
- Explains database versus in-memory sorting, OrderBy limitations, dynamic strings, package installation, and endpoint integration.
- Examples
- Uses board-game JSON results, OrderBy(b => b.Name), dynamic sortColumn and sortOrder parameters, and paged controller queries.
- What you can do after
- Apply it via EF Core and System.Linq.Dynamic.Core to build database-backed, client-configurable sorting for API endpoints.
Read how Building Web APIs with ASP.NET Core explains sorting algorithm →
Python Workout: 50 ten-minute exercises
Sorting is the technique of arranging elements according to an ordering determined by their values or derived comparison keys.
- How it is used
- Uses sorting to organize Python data structures and solve exercises involving derived ordering criteria.
- How deep it goes
- Explains sorted and key-based ordering, but stops short of algorithm internals or implementation details.
- Examples
- Uses absolute values, vowel counts, nested-list sums, repeated vowels, and Unix shell popularity as sorting criteria.
- What you can do after
- Apply it via Python’s sorted function and key parameter to order data by custom properties.
Read how Python Workout: 50 ten-minute exercises explains sorting algorithm →
The Quick Python Book, Fourth Edition
- How it is used
- Orders lists for median calculation and arranges file rows to support duplicate handling or related-record processing.
- How deep it goes
- Explains in-place and copied sorts, comparability, keys, reverse order, memory trade-offs, and external sorting, but not sorting internals.
- Examples
- Demonstrates sorting numbers, strings, nested lists, text rows, and temperatures to calculate a median.
- What you can do after
- Apply Python sorting to reorder lists or file rows, preserve originals when needed, customize ordering, and weigh memory trade-offs.
Read how The Quick Python Book, Fourth Edition explains sorting algorithm →
The Design of Web APIs, Second Edition
Sorting is the technique of ordering returned items according to one or more specified fields and directions.
- How it is used
- Orders API list and search results for consumer browsing, processing, and display.
- How deep it goes
- Details multi-field sort syntax and defaults, but does not explain sorting algorithm internals.
- Examples
- Illustrates transaction ordering by amount or date and balance-array ordering described in JSON Schema.
- What you can do after
- Operate/configure it through optional sort query parameters with consistent syntax and helpful defaults.
Read how The Design of Web APIs, Second Edition explains sorting algorithm →
Clojure: The Essential Reference
The arrangement of elements into an order determined by a comparison criterion.
- How it is used
- Orders collection elements by their natural comparison or a supplied comparator.
- How deep it goes
- Defines input, comparator, output, and notable exceptions, but does not detail the sorting algorithm's internals.
- Examples
- Demonstrates sorting keywords, numbers, maps by age, and mixed values by string conversion.
- What you can do after
- Apply sort or sort-by with a comparator or key function to produce an ordered sequence.
Read how Clojure: The Essential Reference explains sorting algorithm →
JavaScript in Depth
The process of arranging items into a specified order according to a comparison rule.
- How it is used
- Uses timestamp sorting to expose how implicit coercion affects comparator correctness and performance.
- How deep it goes
- Traces per-comparison conversions and explains how NaN comparator results are treated as +0.
- Examples
- Compares numeric and numeric-string timestamps, then demonstrates an ineffective comparator for ISO date strings.
- What you can do after
- Diagnose comparator errors and avoid repeated coercion by checking types or using TypeScript.
Java Persistence with Spring Data and Hibernate epub
Sorting is the ordering of query results according to one or more attributes.
- How it is used
- Orders repository query results and supports selecting limited results or retrieving them in pages.
- How deep it goes
- Shows derived ordering, Sort and Pageable usage, and advises querying by display criteria instead of persisting order.
- Examples
- Uses username and registration-date ordering, level-based results with Sort, and paged user queries.
- What you can do after
- Apply sorting through Spring Data repository methods using derived ordering, Sort, or Pageable.
Read how Java Persistence with Spring Data and Hibernate epub explains sorting algorithm →
D3.js in Action, Third Edition
sort() is the JavaScript Array method that orders array elements according to an optional comparison function.
- How it is used
- Orders technology records by count so a bar chart presents the most-used items first.
- How deep it goes
- Demonstrates a count-based comparison function but does not discuss sorting internals or alternative algorithms.
- Examples
- Orders technology counts with Excel first at 1078, Tableau next at 852, and Angular last at 20.
- What you can do after
- Apply it via JavaScript Array.sort() to order records by a numeric field for a descending bar chart.
Read how D3.js in Action, Third Edition explains sorting algorithm →
Grokking Algorithms, Second Edition
A sorting algorithm is an algorithm that arranges elements according to an ordering criterion.
- How it is used
- Introduces selection sort as a first sorting algorithm and a stepping stone to quicksort.
- How deep it goes
- Positions selection sort as preparation for quicksort, without detailing its procedure in this coverage.
- Examples
- Uses an alphabetized phone book to illustrate how sorted data supports binary search.
- What you can do after
- Understand how sorted data enables binary search and why selection sort prepares readers for quicksort.
Read how Grokking Algorithms, Second Edition explains sorting algorithm →
Learn SQL in a Month of Lunches
Result ordering is the specification of the sequence in which rows are returned by a query.
- How it is used
- Uses explicit query ordering to make result sequences predictable, readable, and useful for selecting recent or extreme values.
- How deep it goes
- Explains why implicit order is unreliable and motivates explicit sorting, but does not show sorting syntax or execution internals.
- Examples
- Uses library authors, building floors, calendars, title listings, recent entries, and alphabetizing titles while ignoring articles.
- What you can do after
- Practice/perform it by writing queries whose results follow a required alphabetical, date-based, or value-based sequence.
Read how Learn SQL in a Month of Lunches explains sorting algorithm →
100 SQL Server Mistakes and How to Avoid Them
A sort operation arranges rows according to specified ordering keys during query execution or index maintenance.
- How it is used
- Treats sorting as a presentation choice to apply only when ordered output is genuinely required.
- How deep it goes
- Explains sort operators, estimated plan costs, timing tests, and inaccurate statistics, but does not develop sorting internals.
- Examples
- Uses CustomerContacts queries ordered by email, execution-plan figures, timing output, and a covering-index definition.
- What you can do after
- Diagnose sorting overhead by comparing T-SQL timings and inspecting plans in SQL Server Management Studio.
Read how 100 SQL Server Mistakes and How to Avoid Them explains sorting algorithm →
Learn Go with Pocket-Sized Projects
Sorting is the technique of ordering elements in a collection according to a specified comparison criterion.
- How it is used
- Stabilizes collection output so map-derived results and endpoints are predictable and easier to test.
- How deep it goes
- Defines a comparator and demonstrates sort.Slice with tie-breaking; notes in-place mutation and defers further details.
- Examples
- Sorts books by author then title, and habits by creation time.
- What you can do after
- Apply Go's sort.Slice to order books by author and title or habits by creation time.
Read how Learn Go with Pocket-Sized Projects explains sorting algorithm →
Build a Website with ChatGPT
Sorting is the operation of arranging data records or values according to an ordering criterion.
- How it is used
- Reorders displayed records according to a field selected by the user.
- How deep it goes
- Describes choosing a field, sorting records, and redisplaying them, but does not specify the sorting algorithm’s implementation.
- Examples
- Uses a course catalog sorted by Department or Title, with text arranged alphabetically and numbers numerically.
- What you can do after
- Apply it via JavaScript to sort catalog records by a selected field and redisplay them.
Read how Build a Website with ChatGPT explains sorting algorithm →
Also covered in
- Grokking GPU ProgrammingIn early access (MEAP)
- Get Programming: Learn to code with Python
- Learn Haskell by Example
- Algorithms Every Programmer Should KnowIn early access (MEAP)
- Data-Oriented Programming in JavaIn early access (MEAP)
- F# in Action: A Revised Edition of Get Programming with F#
- Architecting an Apache Iceberg Lakehouse
- Deep Learning with R, Third Edition
- Django in Action
- How Computers Make Books
- AI for Everyday IT
- Julia as a Second Language
What to know first
- performancePerformance is a measure of how effectively a person, process, model, or system achieves its objectives, including qualities such as output quality, speed, and resource efficiency.
- MapA map is an associative data structure that stores key-value associations and supports retrieving values by key.
- SQLSQL is a standardized declarative language for defining, querying, and manipulating data in relational database systems.
- paginationPagination is the technique of dividing a collection or result set into bounded portions that can be retrieved or displayed separately.
Related concepts
- quicksortincludes · Quicksort is a comparison-based sorting algorithm that partitions elements around a pivot and recursively sorts the resulting partitions.
- heapsortincludes · Heapsort is a comparison-sorting algorithm that uses a heap to repeatedly select elements and produce an ordered sequence.
- shufflecontrasts with · Shuffling is the random rearrangement of elements in a collection or sequence.
- warp divergenceaddresses · Warp divergence occurs when threads in a GPU warp follow different control-flow paths, requiring the paths to be executed sequentially.
- listuses · A list is an ordered collection of elements arranged in a sequence.
Questions about sorting algorithm
What is sorting algorithm?
A sorting algorithm is a procedure that rearranges elements of a collection into an order determined by an ordering criterion.
Which Manning books explain sorting algorithm?
Pandas Workout: 200 exercises to make you a stronger data analyst, MongoDB 8.0 in Action, Third Edition, Secrets of the JavaScript Ninja, Second Edition, Python How-To, Python Workout, Second Edition, Tiny Python Projects: Learn coding and testing with puzzles and games, Building Web APIs with ASP.NET Core, Python Workout: 50 ten-minute exercises and 11 more.
What should I know before learning sorting algorithm?
Manning books that teach sorting algorithm usually introduce performance, Map, SQL and pagination first.
What is the difference between sorting algorithm and shuffle?
A sorting algorithm is a procedure that rearranges elements of a collection into an order determined by an ordering criterion. Shuffling is the random rearrangement of elements in a collection or sequence.
What kinds of sorting algorithm are there?
Kinds of sorting algorithm include quicksort and heapsort.
What is sorting algorithm also called?
Sorting algorithm is also called sort.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


















