Skip to Content
Thinking Recursively with Java
book

Thinking Recursively with Java

by Eric Roberts
November 2005
Intermediate to advanced
187 pages
4h 31m
English
Wiley
Content preview from Thinking Recursively with Java

10.2. Binary Search Trees

The enormous difference in the performance of the sorting algorithms from Chapter 7 offers a vivid illustration of the importance of algorithmic efficiency. Even with the best algorithms, however, sorting is time-consuming, especially when large amounts of data are involved. In many practical applications, it makes sense to avoid the cost of sorting a large list of items by making sure to insert each item into the correct position at the time you add it to the list. The cost of inserting an item in its proper sequence is larger than, for example, simply adding it to the end, but eliminating the need to sort the list at a later point offers a significant advantage. If nothing else, the cost of keeping the list sorted can be distributed over time, so that the program pays a little of that cost at each insertion rather than paying all at once the cost of sorting the entire list. Algorithms that distribute time-consuming activities over a series of individual operations are said to amortize the cost of those operations.

The task of keeping a list in sorted order as you add new items can be broken down into two distinct operations. The first step is to find the correct position for the new item. This step constitutes the search phase of the algorithm. Once you have found the correct position, the next step consists of inserting the new item in that position. This step constitutes the insert phase. The efficiency of these two phases turns out to depend dramatically ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Java By Comparison

Java By Comparison

Simon Harrer, Linus Dietz, Jörg Lenhard
Java 8 in Action

Java 8 in Action

Alan Mycroft, Mario Fusco, Raoul-Gabriel Urma

Publisher Resources

ISBN: 9780471701460Purchase book