Algorithms on Trees and Graphs: With Python Code 2nd Edition Gabriel Valiente instant download
Algorithms on Trees and Graphs: With Python Code 2nd Edition Gabriel Valiente instant download
https://ebookmeta.com/product/algorithms-on-trees-and-graphs-
with-python-code-2nd-edition-gabriel-valiente/
https://ebookmeta.com/product/applied-cryptography-protocols-
algorithms-and-source-code-in-c-2nd-edition-bruce-schneier/
https://ebookmeta.com/product/practical-channel-aware-resource-
allocation-with-matlab-and-python-code-michael-ghorbanzadeh/
https://ebookmeta.com/product/dewey-for-artists-1st-edition-mary-
jane-jacob/
Oblivious A Contemporary M M Best Friends to Lovers Gay
Romance Novel 1st Edition Leslie Mcadam
https://ebookmeta.com/product/oblivious-a-contemporary-m-m-best-
friends-to-lovers-gay-romance-novel-1st-edition-leslie-mcadam/
https://ebookmeta.com/product/treatment-of-voice-disorders-
second-edition-robert-thayer-sataloff/
https://ebookmeta.com/product/potential-exports-and-nontariff-
barriers-to-trade-maldives-national-study-1st-edition-asian-
development-bank/
https://ebookmeta.com/product/death-notice-zhou-haohui/
https://ebookmeta.com/product/come-to-papa-a-man-of-the-month-
club-novella-a-small-town-age-gap-romance-1st-edition-matilda-
martel/
Valiant Indian Warriors Philosophies, Approaches, and
Victories First Edition C. B. Bhange
https://ebookmeta.com/product/valiant-indian-warriors-
philosophies-approaches-and-victories-first-edition-c-b-bhange/
Texts in Computer Science
Gabriel Valiente
Algorithms
on Trees
and Graphs
With Python Code
Second Edition
Texts in Computer Science
Series Editors
David Gries, Department of Computer Science, Cornell University, Ithaca, NY,
USA
Orit Hazzan , Faculty of Education in Technology and Science, Technion—Israel
Institute of Technology, Haifa, Israel
More information about this series at http://www.springer.com/series/3191
Gabriel Valiente
Algorithms on Trees
and Graphs
With Python Code
Second Edition
123
Gabriel Valiente
Department of Computer Science
Technical University of Catalonia
Barcelona, Spain
This Springer imprint is published by the registered company Springer Nature Switzerland AG
The registered company address is: Gewerbestrasse 11, 6330 Cham, Switzerland
To my child Aleksandr,
six years old,
who is eager to grow
and read it all
Preface to the Second Edition
The first edition of this book has been extensively used for graduate teaching and
research all over the world in the last two decades. We have listed hundreds of
citing publications in Appendix C, including books, scientific articles in journals
and conference proceedings, M.Sc. and Ph.D. theses, and even United States
patents.
In this new edition, we have substituted detailed pseudocode for both the literate
programming description and the implementation of the algorithms using the
LEDA library of efficient data structures and algorithms. Although the pseudocode
is detailed enough to allow for a straightforward implementation of the algorithms
in any modern programming language, we have added a proof-of-concept imple-
mentation in Python of all the algorithms in Appendix A. This is, therefore, a
thoroughly revised and extended edition.
Regarding new material, we have added an adjacency map representation of
trees and graphs, and both maximum cardinality and maximum weight bipartite
matching as an additional application of graph traversal techniques. Further, we
have revised the end-of-chapter problems and exercises and have included solutions
to all the problems in Appendix B.
It has been a pleasure for the author to work out editorial matters together with
Sriram Srinivas and, especially, Wayne Wheeler of Springer Nature, whose
standing support and encouragement have made this new edition possible.
Last, but not least, any minor errors found so far have been corrected in this
second edition, the bibliographic notes and references have been updated, and the
index has been substantially enhanced. Even though the author and the publisher
have taken much care in the preparation of this book, they make no representation,
express or implied, with regard to the accuracy of the information contained herein
and cannot accept any legal responsibility or liability for incidental or consequential
damages arising out of the use of the information, algorithms, or program code
contained in this book.
vii
Preface to the First Edition
ix
x Preface to the First Edition
References
Part I Introduction
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1 Trees and Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Basic Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.3 Representation of Trees and Graphs . . . . . . . . . . . . . . . . . . . . . . 23
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Bibliographic Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2 Algorithmic Techniques . . . ........ . . . . . . . . . . . . . . . . . . . . . . . 45
2.1 The Tree Edit Distance Problem . . . . . . . . . . . . . . . . . . . . . . . . 45
2.2 Backtracking . . . . . . . ........ . . . . . . . . . . . . . . . . . . . . . . . 55
2.3 Branch-and-Bound . . . ........ . . . . . . . . . . . . . . . . . . . . . . . 61
2.4 Divide-and-Conquer . . ........ . . . . . . . . . . . . . . . . . . . . . . . 64
2.5 Dynamic Programming ........ . . . . . . . . . . . . . . . . . . . . . . . 70
Summary . . . . . . . . . . . . . . . ........ . . . . . . . . . . . . . . . . . . . . . . . 77
Bibliographic Notes . . . . . . . ........ . . . . . . . . . . . . . . . . . . . . . . . 77
Problems . . . . . . . . . . . . . . . ........ . . . . . . . . . . . . . . . . . . . . . . . 78
Exercises . . . . . . . . . . . . . . . ........ . . . . . . . . . . . . . . . . . . . . . . . 79
References . . . . . . . . . . . . . . ........ . . . . . . . . . . . . . . . . . . . . . . . 80
xiii
xiv Contents
Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
4 Tree Isomorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
4.1 Tree Isomorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
4.1.1 Ordered Tree Isomorphism . . . . . . . . . . . . . . . . . . . . . . 113
4.1.2 Unordered Tree Isomorphism . . . . . . . . . . . . . . . . . . . . 116
4.2 Subtree Isomorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
4.2.1 Top-Down Subtree Isomorphism . . . . . . . . . . . . . . . . . . 125
4.2.2 Top-Down Unordered Subtree Isomorphism . . . . . . . . . 127
4.2.3 Bottom-Up Subtree Isomorphism . . . . . . . . . . . . . . . . . 135
4.2.4 Bottom-Up Unordered Subtree Isomorphism . . . . . . . . . 138
4.3 Maximum Common Subtree Isomorphism . . . . . . . . . . . . . . . . . 144
4.3.1 Top-Down Maximum Common Subtree
Isomorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
4.3.2 Top-Down Unordered Maximum Common Subtree
Isomorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
4.3.3 Bottom-Up Maximum Common Subtree
Isomorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
4.3.4 Bottom-Up Unordered Maximum Common Subtree
Isomorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
4.4 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Bibliographic Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176