Data Structures and Algorithm Analysis in C, Second Edition(《数据结构与算法分析》C语言版 第二版)——Mark Allen Weiss

         Data Structures and Algorithm Analysis in C, SecondEdition

数据结构和算法分析C语言版(第二版)

by Mark Allen Weiss

作者: Mark Allen Weiss

 

PREFACE

卷首语

 

CHAPTER1:  INTRODUCTION

第一章: 简介

CHAPTER2:  ALGORITHM ANALYSIS

第二章:  算法分析

CHAPTER3:  LISTS,STACKS,AND QUEUE

第三章: 列表,栈,和队列

CHAPTER4:  TREES

第四章: 树

CHAPTER5:  HASHING

第五章: 哈希表

CHAPTER6:  PRIORITY QUEUES(HEAPS)

第六章: 优先队列(哈希表)

CHAPTER7:  SORTING

第七章: 排序

CHAPTER8:  THE DISJOINT SET ADT

第八章: 互斥集合,抽象数据类型

CHAPTER9:  GRAPH ALGORITHMS

第九章: 图算法

CHAPTER10: ALGORITHM DESIGNTECHNIQUES

第十章: 算法设计技术

CHAPTER11: AMORTIZED ANALYSIS

第十一章: 分摊分析

 

 

 

 

 

PREFACE

 

卷首语

Purpose/Goals

目的/目标

 

   This book describes data structures, methodsof organizing large amounts of data, and algorithm analysis, the estimation ofthe running time of algorithms. As computers become faster and faster, the needfor programs that can handle large amounts of input becomes more acute.Paradoxically, this requires more careful attention to efficiency, sinceinefficiencies in programs become most obvious when input sizes are large. Byanalyzing an algorithm before it is actually coded, students can decide if aparticular solution will be feasible. For example, in this text students lookat specific problems and see how careful implementations can reduce the timeconstraint for large amounts of data from 16 years to less than a second.Therefore, no algorithm or data structure is presented without an explanationof its running time. In some cases, minute details that affect the running time of the implementation are explored.

     这本书描述了数据结构(组织大量数据的方法)和算法分析(算法运行时间的估计)。随着电脑变得越来越快,就对程序可以处理大量输入有更高的需求。矛盾的是,这就要求对效率更加注意,因为当输入大量数据时,程序的低效率最为明显。在算法被实际编码前分析该算法,学生们就可以确定这个方案是否可行。例如,在本书中学生们会看到一些特殊的问题以及认真仔细的实现是如何将大量数据的时间限制从16年变成不到一秒的。因此,没有一个算法或数据结构是与运行时间的解释无关的。在一些情况中,就要探究影响实现的运行时间的微小细节。

   Once a solution methodis determined, a program must still be written. As computers have become more powerful, the problems they solve have becomelarger and more complex, thus requiring development of more intricate programsto solve the problems. The goal of this text is to teach students goodprogramming and algorithm analysis skills simultaneously so that they candevelop such programs with the maximum amount of Efficiency.

      一旦确定一个解决方案,就会写出一个程序。随着电脑的功能越来越强大,他们需要解决的问题就越来越大,越来越复杂,因此就需要更加复杂的程序去解决这些问题。本书的目的就是教学生同时掌握好的编程技能和算法分析技能,使他们可以开发出最高效的程序。

   This book is suitable for either an advanceddata structures (CS7) course or a first-year graduate course in algorithmanalysis. Students should have some knowledge of intermediate programming,including such topics as pointers and recursion, and some background indiscrete math.

    这本书适合于任一高级数据结构(CS7)课程或研究生一年级的算法分析课程。学生们应该懂一些作为中介的编程知识(包括指针,递归等)和一些离散数学的知识。

 

Approach

方法

 

   I believe it isimportant for students to learn how to program for themselves, not how to copyprograms from a book. On the other hand, it is virtually impossible to discussrealistic programming issues without including sample code. For this reason,the book usually provides about half to three-quarters of an implementation,and the student is encouraged to supply the rest.

    我认为对于学生来说重要的是怎样写出自己的程序而不是怎样从一本书里抄袭程序。另一方面,不用示例代码讨论实际编程问题几乎是不可能的。出于这个原因,本书通常会提供实现的大约八分之三的内容,剩下的部分就由学生补充。

   The algorithms in thisbook are presented in ANSI C, which, despite some flaws, is arguably the mostpopular systems programming language. The use of C instead of Pascal allows theuse of dynamically allocated arrays (see for instance rehashing in Ch. 5). Italso produces simplified code in several places, usually because the and(&&) operation is shortcircuited.

    本书是用ANSI C描述的,尽管C语言有些不足,但是它大概是最流行的系统性的编程语言。使用C语言而不是使用Pascal语言,是因为C语言允许动态分配数组(可以在第五章中的重建内部数据结构部分找示例)。它也在几个地方提供了简化了的代码,通常是因为&&操作是短路(计算逻辑表达式中的一部分便能确定结果,而不对整个表达式进行计算的现象)的。

Most criticisms of Ccenter on the fact that it is easy to write code that is barely readable. Some of the more standard tricks, such as thesimultaneous assignment and testing against 0 via  if (x=y) are generally not used in the text, since the loss of clarity iscompensated by only a few keystrokes and no increased speed. I believe that this bookdemonstrates that unreadable code can be avoided by exercising reasonable care.

大多数对C语言的批判都集中于使用C语言容易写出几乎不可读的代码。一些更好的技巧,例如同时分配和对0通过测试If(x=y)通常不会用在本书中,因为清晰度的损失只会增加键盘输入次数而不会降低速度。我觉得这本书表明了不可读的代码可以通过适当的注意来避免。

 

Overview  

综述

   Chapter 1 containsreview material on discrete math and recursion. I believe the only way to be comfortable with recursion is to see good uses overand over. Therefore, recursion is prevalent in this text, with examples inevery chapter except Chapter 5.

    第一章包含离散数学和递归的复习材料。我觉得使自己对递归感到舒服唯一的方式就是反复地去看递归好的用法。因此,递归在本书中是很普遍的,并且除了第五章,在每一章都有例子。

   Chapter 2 deals with algorithmanalysis. This chapter explains asymptotic analysis and its major weaknesses.Many examples are provided, including an in-depth explanation of logarithmicrunning time. Simple recursive programs are analyzed by intuitively convertingthem into iterative programs. More complicated divide and-conquer programs areintroduced, but some of the analysis (solving recurrence relations) isimplicitly delayed until Chapter 7, where it is performed in detail.

   第二章研究了算法分析。这一章解释了渐近分析法和它主要的缺点。本章中举了很多例子,包括对于对数的运行时间的深入的解释。通过将递归程序转化为迭代程序的方法分析简单的递归程序。介绍了更复杂的分治法的程序,但是一些解决递归关系的分析被推迟到了第七章,在第七章进行了对递归详细的分析。

   Chapter 3 covers lists,stacks, and queues. The emphasis here is on coding these data structures usingADTS, fast implementation of these data structures, and an exposition of someof their uses. There are almost no programs (just routines), but the exercisescontain plenty of ideas for programming assignments.

    第三章研究了链表,堆栈和队列。这里的重点是将这些数据结构使用抽象数据类型进行编码,以及这些数据结构的快速实现和它们的某些应用的阐述。几乎没有程序(只有惯例),但是这些练习包含了大量的编程工作的思想。

   Chapter 4 covers trees,with an emphasis on search trees, including external search trees (B-trees).The UNIX file system and expression trees are used as examples. AVL trees andsplay trees are introduced but not analyzed. Seventy-five percent of the codeis written, leaving similar cases to be completed by the student. Additional coverage of trees, such as file compression andgame trees, is deferred until Chapter 10. Data structures for an externalmedium are considered as the final topic in several chapters.

    第四章研究了树,重点是搜索树,包括外部搜索树(B-trees)。UNIX文件系统和表达树被用作例子。本章介绍了平衡二叉树和伸展树但是没有进行分析。百分之七十五的代码都提供给了读者,留下了相似的部分让学生来完善。树额外覆盖的范围,例如文件的压缩和对策树推迟到第十章来介绍。对于一个外部存储的数据结构在最后几章讨论。

   Chapter 5 is arelatively short chapter concerning hash tables. Some analysis is performed andextendible hashing is covered at the end of the chapter.

    第五章是一个关于哈希表的相对短的章节。本章的最后的部分进行了一些关于哈希表的分析以及包括了一些可扩散列的内容。

   Chapter 6 is aboutpriority queues. Binary heaps are covered, and there is additional material onsome of the theoretically interesting implementations of priority queues.

    第六章是关于优先队列的内容。其中包括了二叉堆以及一些附加的关于优先队列的理论上来说很有趣的实现的材料。

   Chapter 7 coverssorting. It is very specific with respect to coding details and analysis. All the important generalpurpose sorting algorithms are coveredand compared. Three algorithms are analyzed in detail: insertion sort,Shellsort, and quicksort. External sorting is covered at the end of thechapter.

    第七章研究了排序。它对编码细节和分析来说都是特别的。所有重要的万能排序算法都涉及到了并且进行了相互的比较。针对插入排序,希尔排序和快速排序三种算法进行了详细的分析。外部排序在最后一章讲到。

   Chapter 8 discusses thedisjoint set algorithm with proof of the running time. This is a short andspecific chapter that can be skipped if Kruskal's algorithm is not discussed.

    第八章讨论了不相交集合算法运行时间的证明。它是一个很短也很特殊的章节,如果没有学过克鲁斯卡算法这一章可能会被跳过。

   Chapter 9 covers graphalgorithms. Algorithms on graphs are interesting not only because theyfrequently occur in practice but also because their running time is so heavilydependent on the proper use of data structures. Virtually all of the standardalgorithms are presented along with appropriate data structures, pseudocode,and analysis of running time. To place these problems in a proper context, ashort discussion on complexity theory (including NP-completeness andundecidability) is provided.

    第九章讲了图算法。图算法是很有趣的,不只是因为它频繁的在实践中出现,也是因为它的运行时间严重依赖于数据结构的合理使用。实际上所有优秀的算法都是连同恰当的数据结构,伪代码和运行时间的分析一起出现的。为了把这些问题放到一个合适的环境中,提供了一个关于复杂理论(包括完全性和不可判定型)的简短的讨论。

   Chapter 10 coversalgorithm design by examining common problem-solving techniques. This chapteris heavily fortified with examples. Pseudocode is used in these later chaptersso that the student's appreciation of an example algorithm is not obscured by implementationdetails.

    第十章讲了通过测试普通的解决问题技术的算法设计。这一章提供了更多的例子。后面的章节使用了很多的伪代码,是为了让学生们去欣赏算法示例而不是去研究它的实现细节。

   Chapter 11 deals withamortized analysis. Three data structures from Chapters 4 and 6 and theFibonacci heap, introduced in this chapter, are analyzed.

   第十一章研究了平摊分析。本章介绍并分析了来自于第四章和第六章的三个数据结构以及斐波那契堆。

   Chapters 1-9 provideenough material for most one-semester data structures courses. If time permits,then Chapter 10 can be covered. A graduate course on algorithm analysis couldcover Chapters 7-11. The advanced data structures analyzed in Chapter 11 caneasily be referred to in the earlier chapters. The discussion of NP-completeness in Chapter 9 is far too brief to be used in such a course.Garey and Johnson's book on NP-completeness can be used to augment this text.

    第一到九章提供了一学期的数据结构课程的充足的资料。如果时间允许可以讲第十章。对于研究生的算法分析课程,应该讲七到十一章。十一章的高级的数据结构分析也会在前面的章节简单的涉及到。第九章关于完全性在这种课程中的讨论太短了。Garey和Johnson的关于完全性的书可以作为对本书的扩展。

 

Exercises

练习

      Exercises, providedat the end of each chapter, match the order in which material is presented. Thelast exercises may address the chapter as a whole rather than a specificsection. Difficult exercises are marked with an asterisk, and more challengingexercises have two asterisks.

    练习题,每章的最后都有,并且是按照文章顺序排列的。最后的练习题或许是把整章内容整合成一个整体而不是一个特殊的部分。比较难的习题都标有星号,更具挑战性的习题标有两个星号。

    A solutions manualcontaining solutions to almost all the exercises is available separately fromThe Benjamin/Cummings Publishing Company.

Benjamin和Cummings的出版公司出版的解答手册包含了几乎所有习题的解决方法。

 

References

参考文献

    References are placedat the end of each chapter. Generally the references either are historical,representing the original source of the material, or they represent extensionsand improvements to the results given in the text. Some references representsolutions to exercises.

    参考文献在每章末尾。一般每一个参考书都是有历史性的,有的是材料的出处,有的是本文正文内容的扩展和提高。一些参考书是习题的解决方法。

 

Acknowledgments

鸣谢

     I would like to thankthe many people who helped me in the preparation of this and previous versionsof the book. The professionals at Benjamin/Cummings made my book a considerablyless harrowing experience than I had been led to expect. I'd like to thank myprevious editors, Alan Apt and John Thompson, as well as Carter Shanklin, whohas edited this version, and Carter's assistant, Vivian McDougal, for answeringall my questions and putting up with my delays. Gail Carrigan atBenjamin/Cummings and Melissa G. Madsen and Laura Snyder at PublicationServices did a wonderful job with production. The C version was handled by JoeHeathward and his outstanding staff, who were able to meet the productionschedule despite the delays caused by Hurricane Andrew.

    非常感谢那些在准备第一版和本版书的过程中帮助过我的人。Benjamin和Cummings的同行使我的书出版比我预期的要顺利得多。感谢上一版的编辑Alan Apt和John Thompson,还有Carter Shanklin ,其中Carter Shanklin编辑了这一版,还有Carter的助理,Vivian McDougal,回答了我所有的问题还忍受了我的延期。  在Benjamin/Cummings 的Gail Carrigan和Melissa G.Madsen 和出版服务部的Laura Snyder都为本书做了很大的贡献。C版本的数据结构是由Joe Heathward和他能够看到产品计划的优秀的职员负责的,尽管Hurricane Andrew造成了延期。

     I would like to thankthe reviewers, who provided valuable comments, many of which have beenincorporated into the text. Alphabetically, they are Vicki Allan (Utah StateUniversity), Henry Bauer (University of Wyoming), Alex Biliris (BostonUniversity), Jan Carroll (University of North Texas), Dan Hirschberg(University of California, Irvine), Julia Hodges (Mississippi StateUniversity), Bill Kraynek (Florida International University), Rayno D. Niemi(Rochester Institute of Technology), Robert O. Pettus (University of SouthCarolina), Robert Probasco (University of Idaho), Charles Williams (GeorgiaState University), and Chris Wilson (University of Oregon). I would particularlylike to thank Vicki Allan, who carefully read every draft and provided verydetailed suggestions for improvement.

    感谢审稿人,他们提供了非常有价值的注释,这些注释已经被收录到了文章当中。照字母顺序排列,他们是Vicki Allan,Henry Bauer,Alex Biliris,Jan Carroll.DanHirschberg,Julia Hodges,Bill Kraynek,Rayno D.Niemi,Robert O.Pettus,RobertProbasco,Charles Williams和Chris Wilson.特别感谢Vicki Allan,他认真地阅读了每一个手稿并且为本书的提高提供了非常详细的建议。

     At FIU, many peoplehelped with this project. Xinwei Cui and John Tso provided me with their classnotes. I'd like to thank Bill Kraynek, Wes Mackey, Jai Navlakha, and Wei Sunfor using drafts in their courses, and the many students who suffered throughthe sketchy early drafts. Maria Fiorenza, Eduardo Gonzalez, Ancin Peter, TimRiley, Jefre Riser, and Magaly Sotolongo reported several errors, and Mike Hallchecked through an early draft for programming errors. A special thanks goes toYuzheng Ding, who compiled and tested every program in the original book,including the conversion of pseudocode to Pascal. I'd be remiss to forgetCarlos Ibarra and Steve Luis, who kept the printers and the computer systemworking and sent out tapes on a minute's notice.

        在佛罗里达国际大学,许多人都给我提供了帮助。XinweiCui和John Tso给我提他们的课堂笔记。我想感谢BillKraynek,Wes Mackey,Jai Navlakha和Wei Sun,他们在他们的课堂上使用了我的手稿,使得许多学生试用了还算说得过去的初稿。MariaFiorenza, Eduardo Gonzalez, Ancin Peter, Tim Riley, Jefre Riser, 和 Magaly Sotolongo找出了几个错误,Mike Hall在初稿中找出了错误的程序。特别感谢Yuzheng Ding,他编译并测试了原版书中的每一个程序,包括伪代码到Pascal的转换。差点忘记了Carlos Ibarra 和Steve Luis,他们一刻不停地操作着打印机和电脑系统并且及时发放出磁带。

     This book is a product of a love for datastructures and algorithms that can be obtained only from top educators. I'dlike to take the time to thank Bob Hopkins, E. C. Horvath, and Rich Mendez, whotaught me at Cooper Union, and Bob Sedgewick, Ken Steiglitz, and Bob Tarjanfrom Princeton.

        这本书是对数据结构和算法的热爱的产物,这完全来自于教过我的老师们。我想感谢在库伯联盟学院教过我的Bob Hopkins, E. C. Horvath, 和Rich Mendez,以及在普林斯顿大学教过我的Bob Sedgewick, Ken Steiglitz, 和Bob Tarjan。

     Finally, I'd like tothank all my friends who provided encouragement during the project. Inparticular, I'd like to thank Michele Dorchak, Arvin Park, and Tim Snyder forlistening to my stories; Bill Kraynek, Alex Pelin, and Norman Pestaina forbeing civil next-door (office) neighbors, even when I wasn't; Lynn and Toby Berkfor shelter during Andrew, and the HTMC for work relief.

     最后,我要感谢在整个过程中给我鼓励的所有朋友们。尤其是要感谢倾听我的故事的Michele Dorchak, Arvin Park,和Tim Snyder,还有一直包容我的好同事们。还要感谢在Andrew期间Lynn和TobyBerk对我的帮助,以及HTMC对我的帮助。

     Any mistakes in thisbook are, of course, my own. I would appreciate reports of any errors you find;my e-mail address is [email protected].

    当然,书中的任何错误都是由于我个人的原因。我非常感激您能指出书中的错误,我的邮箱是[email protected]

 

M.A.W.

M.A.W. 

Miami , Florida

佛罗里达州迈阿密

September 1992

1992年九月

你可能感兴趣的:(数据结构,数据结构与算法分析)