ebook img

Guide to Data Structures: A Concise Introduction Using Java PDF

385 Pages·2017·11.36 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Guide to Data Structures: A Concise Introduction Using Java

Undergraduate Topics in Computer Science James T. Streib Takako Soma Guide to Data Structures A Concise Introduction Using Java Undergraduate Topics in Computer Science Series editor Ian Mackie Advisory Boards Samson Abramsky, University of Oxford, Oxford, UK Chris Hankin, Imperial College London, London, UK Dexter C. Kozen, Cornell University, Ithaca, USA Andrew Pitts, University of Cambridge, Cambridge, UK Hanne Riis Nielson, Technical University of Denmark, Kongens Lyngby, Denmark Steven S. Skiena, Stony Brook University, Stony Brook, USA Iain Stewart, University of Durham, Durham, UK Undergraduate Topics in Computer Science (UTiCS) delivers high-quality instructional content for undergraduates studying in all areas of computing and information science. From core foundational and theoretical material to final-year topics and applications, UTiCS books take a fresh, concise, and modern approach and are ideal for self-study or for a one- or two-semester course. The texts are all authoredbyestablishedexpertsintheirfields,reviewedbyaninternationaladvisory board, and contain numerous examples and problems. Many include fully worked solutions. More information about this series at http://www.springer.com/series/7592 James T. Streib Takako Soma (cid:129) Guide to Data Structures A Concise Introduction Using Java 123 James T. Streib Takako Soma Illinois College Illinois College Jacksonville, IL Jacksonville, IL USA USA ISSN 1863-7310 ISSN 2197-1781 (electronic) Undergraduate Topics inComputer Science ISBN978-3-319-70083-0 ISBN978-3-319-70085-4 (eBook) https://doi.org/10.1007/978-3-319-70085-4 LibraryofCongressControlNumber:2017957684 ©SpringerInternationalPublishingAG2017 Thisworkissubjecttocopyright.AllrightsarereservedbythePublisher,whetherthewholeorpart of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission orinformationstorageandretrieval,electronicadaptation,computersoftware,orbysimilarordissimilar methodologynowknownorhereafterdeveloped. The use of general descriptive names, registered names, trademarks, service marks, etc. in this publicationdoesnotimply,evenintheabsenceofaspecificstatement,thatsuchnamesareexemptfrom therelevantprotectivelawsandregulationsandthereforefreeforgeneraluse. The publisher, the authors and the editors are safe to assume that the advice and information in this book are believed to be true and accurate at the date of publication. Neither the publisher nor the authorsortheeditorsgiveawarranty,expressorimplied,withrespecttothematerialcontainedhereinor for any errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictionalclaimsinpublishedmapsandinstitutionalaffiliations. Printedonacid-freepaper ThisSpringerimprintispublishedbySpringerNature TheregisteredcompanyisSpringerInternationalPublishingAG Theregisteredcompanyaddressis:Gewerbestrasse11,6330Cham,Switzerland Preface Purpose The purpose of this text is to provide the reader a concise introduction to data structures and associated algorithms. This text is intended for a second-semester course in programming using the Java programming language prior to a course on advanced data structures and algorithms. It is a continuation of the text Guide to Java: A Concise Introduction to Programming using Java written by the authors and published by Springer Verlag London Limited [2]. Comparison and Need for This Text There are a number of introductory texts on data structures using the Java pro- gramming language. Many of these texts are very comprehensive, but unfortu- nately,theysometimesseemtocoversomanydetailsthatmightmakeitdifficultfor a beginning programmer to discern which concepts are the most relevant. The old adage that “one can’t see the forest for the trees” might apply in some instances becauseifoneistoobusywiththemanydetailswhentryingtolearndatastructures one might not have a clear grasp of the fundamental concepts necessary to com- pletely understand the material. There are also some shorter texts, but sometimes theyseemtocoverimportantconceptsveryquicklywhichcanconfusereaderstoo. Thistextattemptstofulfilltheneedforanintroductiontodatastructuresbyhelping the reader to concentrate on the fundamentals which in turn allows the text to be moreconciseandhelpthereaderremainfocusedonthekeyconcepts.Theresultis thatthereadercanlearndatastructuresquicklyandalsohaveagoodfoundationto learn more complex topics later. v vi Preface Features of This Text As mentioned above, this text is a concise introduction to data structures which is accomplishedbyconcentratingonthefundamentals.Thistextiswritteninthesame style as the previously mentioned Guide to Java text. It provides many examples and illustrations and uses visual contour diagrams to illustrate object-oriented semantics as needed. Also as before, in some paragraphs of the text, questions are asked of the reader to help them interact with the material and think about the subject matter presented. The text starts with data structures using arrays to reinforce array concepts learned previously and then introduces linked data structures to compare with array-basedstructures.Adatastructureisfirstintroducedwithasimpledatatypeto helpwithunderstandingbasicconcepts,andthen,itisreinforcedusinggenericdata types. In addition, elementary algorithm analysis is introduced and discussed as needed throughout the text. To help further reinforce concepts, each chapter has one or more complete programstoillustratemanyoftheconceptspresentedandtoalsohelpreaderslearn howtowriteprogramsontheirown.Inaddition,forreviewandpractice,thereare summaries and exercises provided at the end of each chapter. Further, in the appendices at the end of the text, there are answers to selected exercises and a glossary of important terms. A summary of all these features is listed below: (cid:129) Stresses the fundamentals. (cid:129) Provides many examples and illustrations. (cid:129) Begins with array-based data structures to reinforce array concepts learned previously. (cid:129) Follows with linked data structures for comparison and to reinforce methods. (cid:129) Uses both primitive and generic data types in each chapter. (cid:129) Uses contour diagrams to illustrate object-oriented concepts. (cid:129) Asks readers questions to help them interact with the material. (cid:129) Contains one or more complete programs in every chapter. (cid:129) Provides chapter summaries. (cid:129) Includes exercises at the end of each chapter, with selected answers in an appendix. (cid:129) Has a glossary of important terms. Overview of the Chapters After an overview of preliminary concepts, this text introduces stacks and queues using arrays along with a discussion of array-based lists. This is followed by an introduction to linked lists and the implementation of stacks and queues using references. Next, there is an introduction to binary trees, a discussion of various Preface vii sorting techniques, heaps, and hashing. The appendices include a glossary and answers to selected exercises. Lastly, there is a reference and useful Web site section and an index. The following provides a brief synopsis of the chapters and appendices: (cid:129) Chapter 1 reviews and discusses various preliminary concepts. (cid:129) Chapter 2 introduces stacks using arrays. (cid:129) Chapter 3 illustrates queues using arrays. (cid:129) Chapter 4 discusses lists using arrays. (cid:129) Chapter 5 introduces lists using references and objects. (cid:129) Chapter 6 examines linked lists. (cid:129) Chapter 7 explores stacks and queues using references. (cid:129) Chapter 8 introduces binary trees. (cid:129) Chapter 9 explores sorting algorithms. (cid:129) Chapter 10 discusses heaps. (cid:129) Chapter 11 introduces hashing. (cid:129) Appendix A contains a glossary of key terms. (cid:129) Appendix B provides answers to selected exercises. Note that the above order is the authors’ preferred sequence; however, it is understood that some instructors, professionals, and independent students might want to pursue some topics in a different order. As given, all linked list structures followthearray-basedstructures,butalternatively,onecouldhaveChaps.5and6, followingChap.1,andthen,Chaps.2–4couldbeexaminedlater.Further,partsof Chap. 9 can be introduced earlier at the instructor’s discretion. Of course, other combinations are possible given the preference of the instructor or the reader’s background. Scope As mentioned previously, this text concentrates on the fundamentals of data structures such as stacks, queues, lists, (using both arrays and links), sorting, and elementary binary trees, heaps, and hashing. Since it concentrates on the funda- mentals,it might not cover all the details that are foundinsome other texts, andif necessary,thesetopicscanbesupplementedbytheinstructororreader,orcovered in a subsequent text and/or course. Audience Thistextisintendedprimarilyforreaderswhohavehadapreviouscourseoruseda textinprogrammingusingJava.Someoftheconceptsandspecificskillsneededare discussedandreviewedinChap.1.Asmentionedpreviously,thistextsequentially viii Preface followstheauthors’previoustextGuidetoJava,butthisdoesnotprecludeareader fromhaving usedother textsaswell. Notethatalthoughonemight beabletoread thistextwithknowledgeofanotherlanguagesuchasC++,thistextdoesnotreview the Java programming language and previous knowledge of Java is highly rec- ommended. In addition to being a classroom text for a second-semester course in programming in preparation for a subsequent advanced course in data structures and algorithms, it can be used as a self-study guide in either academe or industry. Acknowledgements TheauthorswouldliketothankthereviewersMarkE.BollmanofAlbionCollege, James W. Chaffee of the University of Iowa, and Naomi E. Hahn of Illinois Col- lege. Also, the authors would like to acknowledge the students of Illinois College who have read and used various sections of the text in classroom. On a personal note, James Streib would like to thank his wife Kimberly A. Streib and son Daniel M. Streib for their patience, and Takako Soma would like to thank her family and friends, near and far. Note that Java is a registered trademark of Oracle and/or its affiliates and that Windows is a registered trademark of Microsoft Corporation in the USA and/or other countries. Feedback The possibilities of errors exist in any text, and therefore, any corrections, com- ments, or suggestions are welcome and can be sent to the authors via the e-mail addresses below. In addition to copies of the complete programs presented in the text, any significant corrections can be found at the Website below. Website: http://www.jtstreib.com/GuideDataStructures.html September 2017 James T. Streib Jacksonville, IL, USA [email protected] Takako Soma [email protected] Contents 1 Preliminary Concepts ... ..... .... .... .... .... .... ..... .... 1 1.1 Introduction to Data Structures. .... .... .... .... ..... .... 1 1.2 Prior Concepts and Skills Needed... .... .... .... ..... .... 1 1.3 Elementary Algorithm Analysis .... .... .... .... ..... .... 2 1.4 Abstraction and Interfaces. .... .... .... .... .... ..... .... 8 1.5 Java API. .... .... ..... .... .... .... .... .... ..... .... 12 1.6 Complete Program: Implementing Interface.... ..... .... 13 1.7 Summary .... .... ..... .... .... .... .... .... ..... .... 14 1.8 Exercises (Items Marked with an * Have Solutions in Appendix B).. .... ..... .... .... .... .... .... ..... .... 15 2 Stacks Using Arrays .... ..... .... .... .... .... .... ..... .... 17 2.1 Introduction .. .... ..... .... .... .... .... .... ..... .... 17 2.2 Analysis and Design..... .... .... .... .... .... ..... .... 17 2.3 Stack Class: Data Members and Methods. .... .... ..... .... 21 2.4 Reversing Integers . ..... .... .... .... .... .... ..... .... 29 2.5 Generic Types. .... ..... .... .... .... .... .... ..... .... 32 2.6 Prefix and Postfix Expressions . .... .... .... .... ..... .... 37 2.7 Complete Program: Checking for Palindromes in Strings.. .... 41 2.8 Summary .... .... ..... .... .... .... .... .... ..... .... 45 2.9 Exercises (Items Marked with an * Have Solutions in Appendix B).. .... ..... .... .... .... .... .... ..... .... 46 3 Queues Using Arrays ... ..... .... .... .... .... .... ..... .... 49 3.1 Introduction .. .... ..... .... .... .... .... .... ..... .... 49 3.2 Analysis and Design..... .... .... .... .... .... ..... .... 52 3.3 Queue Class: Data Members and Methods.... .... ..... .... 58 3.4 Program Using the QueueArray Class . .... .... ..... .... 62 3.5 Complete Program: Simulating a Scheduling Algorithm... .... 67 3.6 Summary .... .... ..... .... .... .... .... .... ..... .... 73 3.7 Exercises (Items Marked with an * Have Solutions in Appendix B).. .... ..... .... .... .... .... .... ..... .... 73 ix

Description:
This accessible and engaging textbook/guide provides a concise introduction to data structures and associated algorithms. Emphasis is placed on the fundamentals of data structures, enabling the reader to quickly learn the key concepts, and providing a strong foundation for later studies of more comp
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.