> For the complete documentation index, see [llms.txt](https://cs61b-2.gitbook.io/cs61b-textbook-fall-2026/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cs61b-2.gitbook.io/cs61b-textbook-fall-2026/34.-radix-sorts/34.2-lsd-radix-sort.md).

# 34.2 LSD Radix Sort

<figure><img src="https://2512475561-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBGDh1mPw1Aw5u4IlOFCn%2Fuploads%2Fgit-blob-e5ff8c0340022d20ca0f8c6d0d1dceb8cfb9e31c%2FScreen%20Shot%202023-04-15%20at%202.44.24%20AM.png?alt=media" alt=""><figcaption><p>Least Significant Digit Radix Sort -- Using Count Sort</p></figcaption></figure>

Notice in the above picture that we had a completely random input of numbers 22, 34, 41, etc. Then in the second box, we had sorted by right most digit, so 41, 41, 31 would come first as 1 is the lowest rightmost digit. Next would come 32, 22, 12, as 2 is the second least rightmost digit. Notice that we still have to take care of sorting 32, 22, and 12 which is why we move to the second right most digit in our last box which has everything sorted.

What is the runtime of LSD sort?

* $$\Theta(WN+WR)$$
* $$N$$: Number of items, $$R$$: size of alphabet, $$W$$: Width of each item in # digits

<figure><img src="https://2512475561-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBGDh1mPw1Aw5u4IlOFCn%2Fuploads%2Fgit-blob-124404a3387c55b445404d2c865ba9d654039ed9%2FScreen%20Shot%202023-04-15%20at%202.49.06%20AM.png?alt=media" alt=""><figcaption><p>Non-equal Key Lengths</p></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cs61b-2.gitbook.io/cs61b-textbook-fall-2026/34.-radix-sorts/34.2-lsd-radix-sort.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
