Algorithms For Competitive Programming 1st Edition David Esparza Alba - Instantly access the full ebook content in just a few seconds
Algorithms For Competitive Programming 1st Edition David Esparza Alba - Instantly access the full ebook content in just a few seconds
com
https://textbookfull.com/product/algorithms-for-competitive-
programming-1st-edition-david-esparza-alba/
OR CLICK HERE
DOWLOAD EBOOK
https://textbookfull.com/product/competitive-programming-in-
python-128-algorithms-to-develop-your-coding-skills-1st-edition-
christoph-durr/
textbookfull.com
https://textbookfull.com/product/basic-exercises-for-competitive-
programming-python-1st-edition-jan-pol/
textbookfull.com
https://textbookfull.com/product/algorithms-illuminated-part-3-greedy-
algorithms-and-dynamic-programming-1st-edition-tim-roughgarden/
textbookfull.com
Options and Derivatives Programming in C Algorithms and
Programming Techniques for the Financial Industry 1st
Edition Carlos Oliveira (Auth.)
https://textbookfull.com/product/options-and-derivatives-programming-
in-c-algorithms-and-programming-techniques-for-the-financial-
industry-1st-edition-carlos-oliveira-auth/
textbookfull.com
https://textbookfull.com/product/strategic-management-a-competitive-
advantage-approach-concepts-sixteenth-edition-david/
textbookfull.com
https://textbookfull.com/product/algorithms-illuminated-part-3-greedy-
algorithms-and-dynamic-programming-tim-roughgarden/
textbookfull.com
https://textbookfull.com/product/forced-migration-across-mexico-1st-
edition-ximena-alba-villalever/
textbookfull.com
Algorithms
for Competitive Programming
1 Introduction 7
1.1 Programming Contests . . . . . . . . . . . . . . . . . 7
1.2 Coding Interviews . . . . . . . . . . . . . . . . . . . 8
1.3 Online Judges . . . . . . . . . . . . . . . . . . . . . . 8
1.4 C and C++ . . . . . . . . . . . . . . . . . . . . . . . 10
1.5 Chapter Notes . . . . . . . . . . . . . . . . . . . . . 10
2 Fundamentals 13
2.1 Recursion . . . . . . . . . . . . . . . . . . . . . . . . 14
2.1.1 Memoization . . . . . . . . . . . . . . . . . . 15
2.2 Algorithm Analysis . . . . . . . . . . . . . . . . . . . 16
2.2.1 Asymptotic Notations . . . . . . . . . . . . . 17
2.2.2 Master Theorem . . . . . . . . . . . . . . . . 19
2.2.3 P and NP . . . . . . . . . . . . . . . . . . . . 21
2.3 Bitwise Operations . . . . . . . . . . . . . . . . . . . 22
2.3.1 AND (&) operator . . . . . . . . . . . . . . . 22
2.3.2 OR (|) operator . . . . . . . . . . . . . . . . . 23
2.3.3 XOR operator . . . . . . . . . . . . . . . . . 24
2.3.4 Two’s complement . . . . . . . . . . . . . . . 25
2.4 Chapter Notes . . . . . . . . . . . . . . . . . . . . . 26
2.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 27
3 Data Structures 29
3.1 Linear Data Structures . . . . . . . . . . . . . . . . . 30
3.1.1 Stack . . . . . . . . . . . . . . . . . . . . . . 30
3.1.2 Queue . . . . . . . . . . . . . . . . . . . . . . 32
3.1.3 Linked List . . . . . . . . . . . . . . . . . . . 33
3.2 Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3.2.1 Tree Traversal . . . . . . . . . . . . . . . . . 41
3.2.2 Heap . . . . . . . . . . . . . . . . . . . . . . . 44
v
vi CONTENTS
4 Sorting Algorithms 89
4.1 Bubble Sort . . . . . . . . . . . . . . . . . . . . . . . 90
4.2 Selection Sort . . . . . . . . . . . . . . . . . . . . . . 92
4.3 Insertion Sort . . . . . . . . . . . . . . . . . . . . . . 94
4.4 Quick Sort . . . . . . . . . . . . . . . . . . . . . . . . 95
4.5 Counting Sort . . . . . . . . . . . . . . . . . . . . . . 98
4.6 Merge Sort . . . . . . . . . . . . . . . . . . . . . . . 99
4.7 Heap Sort . . . . . . . . . . . . . . . . . . . . . . . . 103
4.8 Sorting With the algorithm Library . . . . . . . . . 108
4.8.1 Overloading operator < . . . . . . . . . . . . 109
4.8.2 Adding a function to sort . . . . . . . . . . . 111
4.9 Chapter Notes . . . . . . . . . . . . . . . . . . . . . 112
4.10 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 114
8 Geometry 199
8.1 Point Inside a Polygon . . . . . . . . . . . . . . . . . 201
8.1.1 Point in Convex Polygon . . . . . . . . . . . 201
8.1.2 Point in Polygon . . . . . . . . . . . . . . . . 202
8.1.3 Point Inside a Triangle . . . . . . . . . . . . . 205
8.2 Area of a Polygon . . . . . . . . . . . . . . . . . . . 206
8.3 Line Intersection . . . . . . . . . . . . . . . . . . . . 207
8.4 Horner’s Rule . . . . . . . . . . . . . . . . . . . . . . 210
8.5 Centroid of a Convex Polygon . . . . . . . . . . . . . 210
8.6 Convex Hull . . . . . . . . . . . . . . . . . . . . . . . 210
8.6.1 Andrew’s Monotone Convex Hull Algorithm . 211
8.6.2 Graham’s Scan . . . . . . . . . . . . . . . . . 213
8.7 Chapter Notes . . . . . . . . . . . . . . . . . . . . . 218
8.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 220
xi
xii LIST OF FIGURES
xv
xvi LISTINGS
1
2 LISTINGS
Preface
Nowadays more and more companies, and not only in the soft-
ware industry, need to develop mobile applications, or create ways
to improve their communications channels, or analyze great amount
of data in order to offer their customers a better service or a new
product. Well, in order to do that, computer programming plays
an indispensable role, and we are not talking about knowing just
the commands of a programming language, but being able to think
and analyze what is the best way to solve a problem, and in this
way transmit those ideas into a computer in order to create some-
thing that can help people.
3
4 LISTINGS
Prerequisites
This book assumes previous knowledge on any programming lan-
guage. For each algorithm it is given a brief description of how it
works and a source code, this with the intention to put on practice
the theory behind the algorithms, it doesn’t contain any explana-
tion of the programming language used, with the exception of some
built-in functions.
reader to take a look to all of the online judges listed in the chap-
ter and try to solve at least one problem in each one of them.
Online Content
The source code of the exercises and appendices can be found in
the GitHub page:
https://github.com/Cheetos/afcp
Introduction
http://www.ioinformatics.org/history.shtml
7
8 1. INTRODUCTION
https://icpc.baylor.edu/
Language: English
LEGERDEMAIN,
IN PERFECTION.
B Y H ENRY D EAN .
The E LEVENTH E DITION , with large Additions and
Amendments.
PHILADELPHIA:
PRINTED FOR MATHEW CAREY, NO. 118,
MARKET-STREET.
1795.
THE
P R E FA C E
TO THE
R E A D E R.
K IND R EADER ,
Having in my former book of L EGERDEMAIN , promiſed
you farther improvements, accordingly I have diſcov‐
ered herein to you the greateſt and moſt wonderful
ſecrets of this A RT , never written or publiſhed by any
man before: therefore I do not doubt but herein you
will find pleaſure to your full ſatisfaction; which is all
my deſire.
H ENRY D EAN .
The Whole ART of
LEGERDEMAIN;
OR,
HOCUS POCUS
I N PERFECTION, &c.
Legerdemain is an operation whereby one may seem to work won‐
derful, impossible, and incredib
le things, by agility, nimbleness, and
slight of hand. The parts of this ingenio us art, are principally four.
First, In conveyance of balls.
Secondly, In conveyance of money.
Thirdly, In cards,
Fourthly, In confederacy.
Lay your three balls on the table, then say, Gentlemen, you see
here are three balls, and here are three cups, that is, a cup for each
ball, and a ball for each cup. Then, taking that ball that you had in
your right hand, (which you are always to keep private) and clapping
it under the first cup, then taking up one of the three balls, with
your right hand, seeming to put it into your left hand, but retain it
still in your right, shutting your left hand in due time, then say,
Presto, be gone.
Then taking the second cup up, say, Gentlemen, you see there is
nothing under my cup; so clap the ball that you have in your right
hand under it, and then take the second ball up with your right
hand, and seem to put it into your left, but retain it in your right
hand, shutting your left in due time, as before, saying, Verda, be
gone.
Then take the third cup, saying, Gentlemen, you see there is
nothing under my last cup; then clapping the ball you have in your
right hand under it, then take the third ball up with your right hand,
and seeming to put it into your left hand, but retain it in your right;
shutting your left hand in due time, as before, saying, Presto, make
haste; so you have your three balls come under your three cups, as
thus: and so lay your three cups down on the table.
Then with your right hand take up the first cup, and there clap
that ball under, that you have in your right hand; then saying,
Gentlemen, this being the first ball, I will put it into my pocket; but
that you must still keep in your hand to play withal.
So take up the second cup with your right hand, and clap that
ball you have concealed under it, and then take up the second ball
with your right hand, and say, this likewise, I take and put into my
pocket.
Likewise, take up the third cup, and clapping the cup down
again, convey that ball you have in your right hand under the cup,
then taking the third ball, say, Gentlemen, this being the last ball, I
take and put this into my pocket. Afterwards say to the company,
Gentlemen, by a little of my fine powder of experience, I will
command these balls under the cups again. As thus,
So lay them all along upon the table to the admiration of all the
beholders.
Then take up the first cup, and clap the ball you have in your
right hand under it, then taking the first ball up with your right hand,
seem to put the same into your left hand, but retain it still in your
right, then say, Vade, quick be gone when I bid you, and run under
the cup.
Then taking that cup up again, and flinging that you have in your
right hand under it, you must take up the second ball, and seem to
put it into your left hand, but retain it in your right hand, saying,
Gentlemen, see how the ball runs on the table.
So seemingly fling it away, and it will appear as thus.
So taking the same cup again, then clapping the ball under
again, as before, then taking the third ball in your right hand, and
seem to put it under your left, but still retain it in your right, then
with your left hand seem to fling it in the cup, and it will appear
thus; all the three balls to be under one cup.
And if you can perform these actions with the cups, you may
change the balls into apples pears, or plumbs, or to living birds, to
what your fancy leads you to. I would have given you more
examples, but I think these are sufficient for the ingenious, so that,
by these means, you may perform all manner of actions with the
cups.
Note. The artificial cups cannot well be described by words, but
you may have them of me, for they are accounted the greatest
secrets in this art: therefore, I advise you to keep them as such, for
this was never known to the world before.
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.
textbookfull.com