Data structure and algorithm analysis C language English 2 Adapted China Edition Mark Allen Weiss - The latest ebook edition with all chapters is now available
Data structure and algorithm analysis C language English 2 Adapted China Edition Mark Allen Weiss - The latest ebook edition with all chapters is now available
https://ebookultra.com/download/data-structures-and-problem-solving-
using-c-2nd-international-edition-edition-mark-allen-weiss/
https://ebookultra.com/download/data-structures-and-algorithm-
analysis-in-c-fourth-edition-international-edition-chandavarkar/
https://ebookultra.com/download/data-structures-and-algorithm-
analysis-in-c-3rd-edition-dr-clifford-a-shaffer/
https://ebookultra.com/download/discovering-language-the-structure-of-
modern-english-1st-edition-lesley-jeffries/
https://ebookultra.com/download/data-analysis-and-applications-2-1st-
edition-edition-bozeman/
https://ebookultra.com/download/andrea-zanzotto-the-language-of-
beauty-s-apprentice-beverly-c-allen/
https://ebookultra.com/download/data-structures-and-algorithm-
analysis-in-java-
%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84%e4%b8%8e%e7%ae%97%e6%b3%95%e5%88%
86%e6%9e%90-java%e8%af%ad%e8%a8%80%e6%8f%8f%e8%bf%b0-
%e6%95%b0%e6%8d%ae%e7%bb%93/
https://ebookultra.com/download/techniques-of-saxophone-playing-
english-and-german-edition-marcus-weiss/
Data structure and algorithm analysis C language English
2 Adapted China Edition Mark Allen Weiss Digital
Instant Download
Author(s): Mark Allen Weiss
ISBN(s): 9787115139849, 7115139849
Edition: 2
File Details: PDF, 20.07 MB
Year: 2005
Language: english
. ‘Ta
I P w
A
‘4’ III
..
.— V V
Data Structures
arid
Algorithm AnaIVsIs In C
9::
=
4
I. . : I.
- in: •1
= : .... I•
I-
II
S.
-- t
:4l_ S : ::Er
I I I
=tfl*
I I 11 I I I -——•—ll
I I .1
ISBN 7—115—13984—9 I I I I I I I I I I I I 1 I •I
lg_ •.59
ISW7-1 15-13984-9/’1P4957
‘iLfft:49.(K) )L
9 787115 139849 >
-
TURING;0]
(Second Edition)
..L+I- ‘-1
I,-, h:i
(3&•2&)
[] Mark Allen Weiss
(QWJ&. itfltJLWi)
ISBN 7-115-13984-9
t1-fl43J
iFIIMiA! (t1t&
4&***Ji—C 2 }&)
A B&4±+1J!i&t ,tihlflV9iWfll 14 4
WIS 100061 k !pgilt 315ptpress com.cn
l lit hltp://www.ptpress.com.cn
njAt1 uDJrpAi
1gj1rj ,jffi2ffi
)F4-: 800x1000 1/16
141*: 32.5
: 7271$ 2005W8Jj3W1&
a4Tu 01-2005-3578 -
ISBN 7-115-13984-9/TP 4957
ffr 49.OO5L
jNR*)M: (010)88593802 P MM: (010)67129223
Adapter’s Foreword
Purpose
The original of this book is an excellent work of Mark Allen Weiss. All the
fundamental topics are covered. The ADT concepts and the analysis of the
algorithms (especially the average analysis)
case emphasized. The extensive
are
re-composition is made to trim the contents of the book so that it better fits a
second-year undergraduate course in data structures and algoritlun analysis for the
Chinese students.
What’sNew
The recomposition includes two major changes. First, the review section
structure
of mathematics has been canceled since sophomore students in China have taken
sufficient courses in mathematics in their first-year study, including calculus, linear
algebra, and discrete mathematics. Secondly, the original Chapter 5 is moved to
follow Chapter 7, in order to show hashing as a method to break the lower bound
of searching by comparisons only.
Other minor changes include adding some interesting data structures and
methods, and rearranging part of the contents. Introduction of the sparse matrix
representation is added as an example of application of mu.ltilists in Section 3.2.
At the mean time, bucket sort and radix sort are discussed in more details in
example in Section 3.2. In Chapter 4, the two sections about tree traversals, namely
Sections 4.1.2 and 4.6, are merged into one and are inserted into Section 4.2.3.
Threaded binary tree is then formally introduced instead of being mentioned in
exercises only. At the beginning of Chapter 7 (which was Chapter 5 in the original
Acknowledgments
We feel grateful to Mark Allen Weiss, the author of the original book, and Pearson
Education, the original publisher, for their great support on this recomposition. It is
their understanding and generosity that make it possible for more Chinese students to
Finally I would like to thank everyone at Turing Book Company, the publisher of
this adapted edition, who have put in great effort to make this kind of cooperation
possible.
It is my very first attempt on making a recomposition of a textbook. If you have
any suggestions for improvements, I would very much appreciate your comments.
Yue Chen
chenyuecs.zju.edu.cn
Zhejiang University
PREFACE
Purpose/Goals
This book describes data structures, methods of organizing large amounts of data,
and algorithm analysis, the estimation of the running time of algorithms. As computers
become faster and faster, the need for programs that canhandle large amounts
of input becomes more acute. Paradoxically, this requires more careful attention to
efficiency, since inefficiencies in programs become most obvious when input sizes are
large. By analyzing an algorithm before it is actually coded, students can decide if a
particular solution will be feasible. For example, in this text students look at specific
problems and see how careful implementations can reduce the time constraint for
large amounts of data from 16 years to less than a second. Therefore, no algorithm
or data structure is presented without an explanation of its running time. In some
cases, minute details that affect the running time of the implementation are explored.
Approach
I believe it is important for students to learn how to program for themselves, not
discuss realistic programming issues without including sample code. For this reason,
the book usually provides about one-half to three-quarters of an implementation,
and the student is encouraged to supply the rest. Chapter 12, which is new to this
edition, discusses additional data structures with an emphasis on implementation
details.
PREFACE
if (x=y)
are generally used in the text, since the loss of clarity is compensated by only a
not
few keystrokes and no increased speed. I believe that this book demonstrates that
unreadable code can be ivoided by exercising reasonable care.
Overview
Chapter 5 is about priority queues. Binary heaps are covered, and there is
additional material on of the theoretically interesting implementations of
some
priority queues. The Fibonacci heap is discussed in Chapter 11, and the pairing heap
is discussed in Chapter 12.
PREFACE lx
Chapter 6 covers sorting. It is very specific with respect to coding details and
and
analysis. All the important general-purpose sorting algorithms are covered
are analyzed in detail: insertion sort, Shellsort, heapsort,
compared. Four algorithms
and quicksort. The analysis of the average-case running time of heapsort is new to
this edition. External sorting is covered at the end of the chapter.
hash tables. Some analysis is
Chapter 7 is a relatively short chapter concerning
at the end of the chapter.
performed, and extendible hashing is covered
Chapter 8 discusses the disjoint set algorithm with proof of the running time.
This is a short and specific chapter that can be skipped if Kruskal’s algorithm is not
discussed.
Chapter 9 covers graph algorithms. Algorithms on graphs are interesting, not
only because they frequently occur in practice but also because their running time is
so heavily dependent on the proper use of data structures. Virtually all of the standard
algorithms are presented along with appropriate data structures, pseudocode, and
analysis of running time. To place these problems in a proper context, a short
discussion on complexity theory (including NP-completeness and undecidability) is
provided.
Chapter 10 covers algorithm design by examining common problem-solving
techniques. This chapter is heavily fortified with examples. Pseudocode is used in
these later chapters so that the student’s appreciation of an example algorithm is not
obscured by implementation details.
Chapter 11 deals with amortized analysis. Three data from Chapters
structures
Chapter 12 is new to this edition. It covers search tree algorithms, the k-d tree,
and the pairing heap. This chapter departs from the rest of the text by providing
complete and careful implementations for the search trees and pairing heap. The
material is structured so that the instructor can integrate sections into discussions
from other chapters. For example, the top-down red black tree in Chapter 12 can
be discussed under AVL trees (in Chapter 4).
Chapters 1—9
provide enough material for most one-semester data structures
courses. If time permits, then Chapter 10 be covered. A graduate course
can
text.
Exercises
Exercises, provided at the end of each chapter, match the order in which material
is presented. The last exercises may address the chapter as a whole rather than a
specific section. Difficult exercises are marked with an asterisk, and more challenging
exercises have two asterisks.
PREFACE
References
References are placed at the end of each chapter. Generally the references either
are historical, representing the original of the material, or they represent
source
extensions and improvements to the results given in the text. Some references
represent solutions to exercises.
Code Availability
The example program code in this book is available via anonymous ftp
at ftp://ftp.csfiu.edu/pub/weiss/WEISS_2E.tar.Z
Acknowledgments
Many, many people have helped me in the preparation of books in this series. Some
are listed in other versions of the book; thanks to all.
For this edition, I would like to thank my editors at Addison-Wesley, Carter
Shanklin and Susan Hartman. Ten Hyde did another wonderful job with the
production, and Matthew Harris and his staff at Publication Services did their usual
fine work putting the final pieces together.
M.A.W.
Miami, Florida
July, 1996
CONTENTS
Adapter’s Foreword
Preface
Introduction 1
1.1. What’s the Book About? 1
Summary 7
Exercises 7
References 8
2 Algorithm Analysis 9
xi
CONTENTS
3.2. TheLisLwT 36
3.2.1. Simple Array Implementation of Lists 37
3.2.2. Linked Lists 37
3.2.3. Programming Details 38
3.2.4. Common Errors 43
3.2.5. DoublyLinked Lists 45
3.2.6. Circularly Linked Lists 46
3.2.7. Examples 46
3.2.8. Cursor Implementation of Linked Lists 50
3.3. The StackAnT 56
3.3.1. stack Model 56
3.3.2. Implementation of Stacks 57
3.3.3. Applications 65
3.4. The QueueMT 73
3.4.1. Queue Model 73
3.4.2. Array Implementation of Queues 73
3.4.3. Applications of Queues 78
Summary 79
Exercises 79
4 Trees 83
4.1. Preliminaries 83
4.1.1. Terminology 83
4.1.2. TreeThtversalswithanApplication 84
4.2. Binary Trees 85
4.2.1. Implementation 86
4.2.2. Expression Trees 87
4.2.3. Tree Traversals 90
Summary 133
Exercises 134
References 141
6 Sorting 187
6.1. Preliminaries 187
6.2. Insertion Sort 188
-
7 Hashing 235
7.1. General Idea 235
7.2. Hash Function 237
7.3. Separate Chaining 239
7.4. Open Addressing 244
7.4.1. Linear Probing 244
7.4.2. Quadratic Probing 247
7.4.3. Double Hashing 251
CONTENTS XV
Summary 339
Exercises 339
References 345
Summary 415
Exercises 417
References 424
CONTEWFS xvii
Introduction
In thischapter, we discuss the aims and goals of this text and briefly review
Suppose you have a group of N numbers and would like to determine the kit largest.
This is known as the selection problem. Most students who have had a programming
course or two would have no difficulty writing a
program to solve this problem.
sort the array in decreasing order by some simple algorithm such as bubblesort, and
then return the element in position k.
A somewhat better algorithm might be to read the first k elements into an array
and sort them (in decreasing order). Next, each remaining element is read one by
one. As a element arrives, it is ignored if it is smaller than the kit element
new
in the array. Otherwise, it is placed in its correct spot in the array, bumping one
element of the array. When the algorithm ends, the element in the kth position
out
natural questions, then, which algorithm is better and, more important, is either
are
and that. The word this begins at row 1, column 1, or (1,1), and extends to (1,4);
two goes from (1,1) to (3,1); fat goes from (4,1) to (2,3); and that goes from (4,4)
to (1,1).
Again, there are at least two straightfonvard algorithms that solve the problem.
For each word in the word list, we check each ordered triple (row, column,
orientation) for the presence of the word. This amounts to lots of nested for loops
but is basically straightforward.
Alternatively, for each ordered quadruple (row, column, orientation, number
of characters) that doesn’t run off an end of the puzzle, we can test whether the
word indicated is in the word list. Again, this amounts to lots of nested for loops. It
is possible to save some time if the maximum number of characters in any word is
known.
It is relatively easy to code up either method of solution and solve many of the
real-life puzzles commonly published in magazines. These typically have 16 rows, 16
columns, and 40 or so words. Suppose, however, we consider the variation where
only the puzzle board is given and the word list is essentially an English dictionary.
Both of the solutions proposed require considerable time to solve this problem and
therefore are not acceptable. However, it is possible, even with a large word list, to
solve the problem in a matter of seconds.
An important concept is that, in many problems, writing a working program is
not good enough. If the program is to be runon a large data set, then the running
time becomes an issue. Throughout this book we will see how to estimate the
running time of a program for large inputs and, more important, how to compare
the running times of two programs without actually coding them. We will see
techniques for drastically improving the speed of a program and for determining
program bottlenecks. These techniques will enable us to find the section of the code
on which to concentrate our
optimization efforts.
1 2 3 4
1 t Ii 1 s
2 w a t s
3 o a h g
4 f g d t
1.2. A BRIEF INTRODUCTION TO RECURSION 3
C =
S(F 32)19
Given this formula, it is trivial to write a C function; with declarations and braces
removed, the one-line formula translates to one line of C.
Mathematical functions are sometimes defined in a less standard form. As an
example, we can define a function F, valid on nonnegative integers, that satisfies
F(O) 0 and F(X)
=
2F(X 1) + V. From this definition we see that F(1)
=
1, =
F(2) =
6, F(3) =
21, and F(4) =
58. A function that is defined in terms of itself
is called recursive. C allows functions to be recursive.* It is important to remember
that what C provides is merely an attempt to follow the recursive spirit. Not all
mathematically recursive functions are efficiently (or correctly) implemented by
C’s simulation of recursion. The idea is that the recursive function F ought to be
expressible in only a few lines, just like a nonrecursive function. Figure 1.2 shows
the recursive implementation of F.
Lines I and 2 handle what is known as the base case, that is, the value for
which the function is directly known without resorting to recursion. Just as declaring
F(X) 2F(X
=
1) + X2 is meaningless, mathematically, without including the fact
that F(0) 0, the recursive C function doesn’t make sense without a base case.
=
There are several important and possibly confusing points about recursion. A
common question is: Isn’tthis just circular logic? The answer is that although we are
a function in terms of itself, we are not defining a
defining particular instance of the
function in terms of itself. In other words, evaluating F(S) by computing F(S) would
be circular. Evaluating F(S) by computing F(4) is not circular—unless, of course,
F(4) is evaluated by eventually computing F(S). The important two most issues are
‘Using recursion for numerical calculations is usually a bad idea. We have done so to illustrate the basic
points.
Other documents randomly have
different content
Nälkä, nälkä, nälkä kiihtyy.
Mutta miss' on uhriraukat,
missä polot piillen viihtyy?
Miks' on huolissansa haukat?
Joko — taikka.
He nauravat uhkaa.
"Nöyrry!"
"Langennut".
Herahti kyynel.
Pikkutyttönen, pikkutyttönen,
herahti kyynel silmähän sulle.
Arvasin sen:
elämä raskas on myöskin mulle.
Köyhä olet, onneton, pikkutyttönen,
kerjäten etsit sa onnea turhaan,
väsähtäen.
Riistäjä rintasi riemut murhaa.
Miksikä?
Sääli teitä.
Pilli soimaan.
Tuhka tanssii.
Valitellaan, vaikeroidaan
mielipuolin puuskin, raivoin,
tositoimiss' olla voidaan
käsin vankoin, vaan ei aivoin.
Miks ihmetellään —?
Updated editions will replace the previous one—the old editions will
be renamed.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com