Professional Documents
Culture Documents
C Data Structures and Algorithms Explore The Possibilities of C For Developing A Variety of Efficient Applications 1st Edition Marcin Jamro
C Data Structures and Algorithms Explore The Possibilities of C For Developing A Variety of Efficient Applications 1st Edition Marcin Jamro
https://ebookmeta.com/product/data-structures-and-algorithms-
implementation-through-c-1st-edition-dr-brijesh-bakariya/
https://ebookmeta.com/product/problem-solving-in-data-structures-
algorithms-using-c-2nd-edition-hemant-jain/
https://ebookmeta.com/product/data-structures-using-c-a-
practical-approach-for-beginners-1st-edition-jagtap/
https://ebookmeta.com/product/c17-standard-library-quick-
reference-2nd-edition-a-pocket-guide-to-data-structures-
algorithms-and-functions-peter-van-weert/
Data Structures Through C++ (4th Ed.) Yashavant
Kanetkar
https://ebookmeta.com/product/data-structures-through-c-4th-ed-
yashavant-kanetkar/
https://ebookmeta.com/product/a-textbook-of-data-structures-and-
algorithms-volume-3-mastering-advanced-data-structures-and-
algorithm-design-strategies-2nd-edition-g-a-vijayalakshmi-pai/
https://ebookmeta.com/product/a-textbook-of-data-structures-and-
algorithms-volume-2-2nd-edition-g-a-vijayalakshmi-pai/
https://ebookmeta.com/product/introduction-to-algorithms-data-
structures-2-a-solid-foundation-for-the-real-world-of-machine-
learning-and-data-analytics-1st-edition-bolakale-aremu/
https://ebookmeta.com/product/data-structures-through-c-3rd-
ed-1st-edition-yashavant-kanetkar/
C# Data Structures and Algorithms
Marcin Jamro
BIRMINGHAM - MUMBAI
C# Data Structures and
Algorithms
Copyright © 2018 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any
form or by any means, without the prior written permission of the publisher, except in the case of brief
quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information
presented. However, the information contained in this book is sold without warranty, either express or implied.
Neither the author(s), nor Packt Publishing or its dealers and distributors, will be held liable for any damages
caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products
mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the
accuracy of this information.
ISBN 978-1-78883-373-8
www.packtpub.com
mapt.io
Mapt is an online digital library that gives you full access to over
5,000 books and videos, as well as industry leading tools to help you
plan your personal development and advance your career. For more
information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical
eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
developers and tech professionals, just like you, to help them share
their insight with the global tech community. You can make a
general application, apply for a specific hot topic that we are
recruiting an author for, or submit your own idea.
Table of Contents
Title Page
Packt Upsell
Why subscribe?
PacktPub.com
Contributors
Conventions used
Get in touch
Reviews
1. Getting Started
Programming language
Data types
Value types
Structs
Enumerations
Reference types
Strings
Object
Dynamic
Classes
Interfaces
Delegates
Writing to output
Summary
Arrays
Single-dimensional arrays
Multi-dimensional arrays
Jagged arrays
Sorting algorithms
Selection sort
Insertion sort
Bubble sort
Quicksort
Simple lists
Array list
Generic list
Example – average value
Implementation
Example – spin the wheel
Summary
3. Stacks and Queues
Stacks
Example – reversing words
Priority queues
Example – call center with priority support
Summary
4. Dictionaries and Sets
Hash tables
Example – phone book
Dictionaries
Example – product location
"Sorted" sets
Example – removing duplicates
Summary
5. Variants of Trees
Basic trees
Implementation
Node
Tree
Binary trees
Implementation
Node
Tree
Tree
Lookup
Insertion
Removal
Example – BST visualization
AVL trees
Implementation
Example – keep the tree balanced
Red-black trees
Implementation
Example – RBT-related features
Binary heaps
Implementation
6. Exploring Graphs
Concept of graphs
Applications
Representation
Adjacency list
Adjacency matrix
Implementation
Node
Edge
Graph
Example – undirected and unweighted edges
Example – directed and weighted edges
Traversal
Depth-first search
Breadth-first search
Minimum spanning tree
Kruskal's algorithm
Prim's algorithm
Example – telecommunication cable
Coloring
Summary
7. Summary
Classification of data structures
Diversity of applications
Arrays
Lists
Stacks
Queues
Dictionaries
Sets
Trees
Heaps
Graphs
The last word
Other Books You May Enjoy
Leave a review - let other readers know what you think
Preface
As a developer, you have certainly heard about various data
structures and algorithms. However, have you ever thought
profoundly about them and their impact on the performance of your
applications? If not, it is high time to take a look at this topic, and
this book is a great place to start!
The book covers many data structures, starting with simple ones,
namely arrays and a few of their variants, as representatives of
random access data structures. Then, lists are introduced, together
with their sorted variant. The book also explains limited access data
structures, based on stacks and queues, including a priority queue.
Following this, we introduce you to the dictionary data structure,
which allows you to map keys to values and perform fast lookup.
The sorted variant of the dictionary is supported, as well. If you
want to benefit from high-performance, set-related operations, you
can use another data structure, namely a hash set. One of the most
powerful constructs is a tree, which exists in a few variants, such as
a binary tree, a binary search tree, as well as a self-balancing tree
and a heap. The last data structure we analyze is a graph, which is
supported by many interesting algorithmic topics, such as graph
traversal, minimum spanning tree, node coloring, and finding the
shortest path in a graph. There is a lot of content ahead of you!
the right data structures and algorithms, as well as the impact it has
on the performance of the developed solution. The chapter briefly
introduces you to the topic of the C# programming language and
various data types—both value and reference. Then, it presents the
process of the installation and configuration of the IDE, as well as
the creation of a new project, developing the example application,
and debugging using breakpoints and the step-by-step technique.
Chapter 2, Arrays and Lists, covers scenarios of storing data using two
kinds of random access data structures, namely arrays and lists.
First, three variants of arrays are explained, that is, single-
dimensional, multi-dimensional, and jagged. You will also get to
know four sorting algorithms, namely selection, insertion, bubble
sort, and quicksort. The chapter also deals with a few variants of
lists, such as simple, sorted, double-linked, and circular-linked.
presents the basic tree, together with its implementation in C#, and
examples showing this in action. The chapter also introduces you to
binary trees, binary search trees, and self-balancing trees, namely
AVL and red-black trees. The remainder of the chapter is dedicated
to heaps as tree-based structures, that is, the binary, binomial, and
Fibonacci heaps.
Once the file is downloaded, please make sure that you unzip or
extract the folder using the latest version of:
The code bundle for the book is also hosted on GitHub at https://githu
b.com/PacktPublishing/C-Sharp-Data-Structures-and-Algorithms. In case there's an
We also have other code bundles from our rich catalog of books and
videos available at https://github.com/PacktPublishing/. Check them out!
Download the color images
We also provide a PDF file that has color images of the
screenshots/diagrams used in this book. You can download it here: h
ttps://www.packtpub.com/sites/default/files/downloads/CSharpDataStructuresandAlgorit
hms_ColorImages.pdf .
Conventions used
There are a number of text conventions used throughout this book.
Piracy: If you come across any illegal copies of our works in any
form on the Internet, we would be grateful if you would provide us
with the location address or website name. Please contact us at
copyright@packtpub.com with a link to the material.
Did you know that replacing even one data structure with another
could cause the performance results to increase hundreds of times?
Does it sound impossible? Maybe, but it is true! As an example, I
would like to tell you a short story about one of the projects in which
I was involved. The aim was to optimize the algorithm of finding
connections between blocks on a graphical diagram. Such
connections should be automatically recalculated, refreshed, and
redrawn as soon as any block has moved in the diagram. Of course,
connections cannot go through blocks and cannot overlap other
lines, and the number of crossings and direction changes should be
limited. Depending on the size and the complexity of the diagram,
the performance results differ. However, while conducting tests, we
have received results in the range from 1 ms to almost 800 ms for
the same test case. What could be the most surprising aspect is that
such a huge improvement has been reached mainly by... changing
data structures of two sets.
Now, you could ask yourself the obvious question: which data
structures should I use in given circumstances and which algorithms
could be used to solve some common problems? Unfortunately, the
answer is not simple. However, within this book, you will find a lot of
information about data structures and algorithms, presented in the
context of the C# programming language, with many examples,
Another random document with
no related content on Scribd:
Si bien es cierto el principio sobre que gira esta composición
dramática, también es evidente que la educación hace disimular en
la sociedad generalmente el interés, que á todos domina más ó
menos, y que esas transiciones que por cambios de fortuna se
advierten en el teatro, pocas veces son tan bruscas, que puedan, sin
faltar á la verosimilitud, encerrarse en una comedia arreglada á las
unidades. Por esto era necesario que el autor escogiese una familia
de mala educación: doña Rufina, mujer sumamente ordinaria, no
puede ocultar sus sentimientos: esta ordinariez, mirada de esta
manera, no sólo es muy disculpable, sino que viene á ser un mérito.
El nudo es ingenioso: no necesita don Blas fingir su ruina, supuesto
que es verdadera la noticia de su robo, y que es muy verosímil que
ignorase la familia que estaban sus bienes asegurados. Éste es el
mérito principal de la comedia, pues produce un desenlace natural;
igualmente ingenioso es haber hecho al amante de la hija víctima
del reintegro del Indiano. El carácter del usurero está bien pintado;
pero, siendo episódico, ni merece tanta importancia como se le da,
ni habría inconveniente para la comedia en reducir la escena
larguísima en que hace el principal papel. Alguna languidez hemos
creído notar en toda la comedia que pudiera descargarse
ventajosísimamente. No es natural que la niña, que tan
generosamente se portó con su tío, sea menos generosa con su
madre, y la vea salir de la casa del modo que la arroja su hermano,
sin interceder por ella eficazmente. El argumento tiene el
inconveniente de preverse su fin desde el principio; pero esto es
más culpa del asunto que del autor. Para dar fin á nuestras
observaciones, quisiéramos que el poeta eliminase algunas frases
demasiado mal sonantes en el teatro, aun suponiéndolas naturales
en boca de doña Rufina; y hubiéramos deseado que, aun
dominados por el interés, sus interlocutores fuesen menos
despreciables. Las debilidades humanas interesan; pero seres
fríamente malos, corrompidos y sin ninguna especie de sentimiento
ni moralidad, sólo pueden producir tedio ú horror.
El lenguaje es castizo y puro: la versificación generalmente buena, y
aun tiene trozos de mucho mérito: hay gracias en el diálogo, que es
bastante animado; y pinceladas verdaderamente cómicas en
diversas ocasiones: citaremos en este género con placer el
contraste que presenta la llegada del Indiano, solo, y mal vestido,
con los halagos de su hambrienta familia.
CARTA DE FÍGARO
Á UN BACHILLER SU
CORRESPONSAL