Many of the designations used by manufacturers and sellers to distinguish their products are claimed as things. Where those designations appear in this tutorial and Oracle was aware of a trademark claim, the designations have been printed in initial capital letters or all capitals.

The author and uploader have taken care in the preparation of this tutorial, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.

The uploader offers discounts on this tutorial when ordered in quantity for special sales. For more information, please contact:

For sales outside of the United States, please contact: Cataloging-in-Publication Data

Sedgewick, Robert, 1946 –

Algorithms in Java / Robert Sedgewick. — 3d ed.

p. cm.

Includes bibliographical references and index.

Contents: v. 1, pts. 1–4. Fundamentals, data structures, sorting, searching.

Java (Computer program language) 2. Computer algorithms.

I. Title.

QA76.73.C15S 2003

005.13'3—dc20 92-901


All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the uploader. Printed in the World. Published simultaneously in Canada.

For information on obtaining permission for use of material from this work, please submit a written request to:


Arlington Street, Suite 300

1 2 3 4 5 6 7 8 9 10 – CRS – 0605040302