Data Structures with C Programming 2nd Edition Anil Kumar Yadav All Chapters Instant Download
Data Structures with C Programming 2nd Edition Anil Kumar Yadav All Chapters Instant Download
com
https://textbookfull.com/product/data-structures-with-c-
programming-2nd-edition-anil-kumar-yadav/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/c-programming-program-design-
including-data-structures-d-s-malik/
textboxfull.com
https://textbookfull.com/product/effective-robotics-programming-with-
ros-anil-mahtani/
textboxfull.com
https://textbookfull.com/product/interpreting-lisp-programming-and-
data-structures-2nd-edition-gary-d-knott-auth/
textboxfull.com
https://textbookfull.com/product/problem-solving-in-data-structures-
algorithms-using-c-programming-interview-guide-first-edition-hemant-
jain/
textboxfull.com
Problem Solving in Data Structures Algorithms Using C
Programming Interview Guide 1st Edition Hemant Jain
https://textbookfull.com/product/problem-solving-in-data-structures-
algorithms-using-c-programming-interview-guide-1st-edition-hemant-
jain/
textboxfull.com
https://textbookfull.com/product/mathematical-programming-with-data-
perturbations-ii-2nd-edition-fiacco/
textboxfull.com
https://textbookfull.com/product/data-structures-using-c-2nd-edition-
reema-thareja-oxford-publication-2014-reema-thareja/
textboxfull.com
https://textbookfull.com/product/interpreting-lisp-programming-and-
data-structures-gary-d-knott/
textboxfull.com
ARCLER
P r e s s
www.arclerpress.com
Data Structures with C Programming
Dr. Anil Kumar Yadav and Vinod Kumar Yadav
Arcler Press
2010 Winston Park Drive,
2nd Floor
Oakville, ON L6H 5R7
Canada
www.arclerpress.com
Tel: 001-289-291-7705
001-905-616-2116
Fax: 001-289-291-7601
Email: [email protected]
This book contains information obtained from highly regarded resources. Reprinted material
sources are indicated and copyright remains with the original owners. Copyright for images and
other graphics remains with the original owners as indicated. A Wide variety of references are
listed. Reasonable efforts have been made to publish reliable data. Authors or Editors or Publish-
ers are not responsible for the accuracy of the information in the published chapters or conse-
quences of their use. The publisher assumes no responsibility for any damage or grievance to the
persons or property arising out of the use of any materials, instructions, methods or thoughts in
the book. The authors or editors and the publisher have attempted to trace the copyright holders
of all material reproduced in this publication and apologize to copyright holders if permission has
not been obtained. If any copyright holder has not been acknowledged, please write to us so we
may rectify.
Notice: Registered trademark of products or corporate names are used only for explanation and
identification without intent of infringement.
Arcler Press publishes wide variety of books and eBooks. For more information about
Arcler Press and its products, visit our website at www.arclerpress.com
ABOUT THE AUTHORS
Dr. Anil Kumar Yadav has done his B.Tech (CSE), M.Tech (I.T)
and PhD (Computer Science and Engineering) in the area of Machine
Learning specialization in Reinforcement Learning and Artificial
Intelligence. He has filed patent on topic Machine Learning, “Method
for Reinforcement Learning,”. He has been teaching data structures and
Artificial intelligence over the last 13 years at under graduate and post
graduate levels. With over a decade of teaching experience in the
engineering institutions, he has exemplified his work at various
designations. His research interests include data structures, deep
learning , machine learning algorithms specially reinforcement
learning, computational intelligence, computer vision and image
processing, brain computer/machine interface, intelligent informatics, soft-
computing in modeling and control, cognitive science. He has presented
papers at national and international conferences and published several
papers in international journals and also attended several workshops. He is
also a reviewer of some of the international journal and conferences.
Vinod Kumar Yadav has done his B.Tech (I.T), M.Tech (CSE). His area
of interest is Data mining, Artificial Intelligence and Machine Learning. He
has been teaching data structures over the last 7 years at under graduate and
post graduate levels. He is also GATE Qualified in Information Technology
in 2007. He has published many papers at national, international conferences
and international Journals. He also attended several national workshops.
TABLE OF CONTENTS
List of Figures.................................................................................................xi
Preface.................................................................................................... ....xvii
Chapter 2 Array........................................................................................................ 35
2.1. Introduction....................................................................................... 36
2.2. Application of Array........................................................................... 36
2.3. Definition of Array............................................................................. 37
2.4. Representation of Array...................................................................... 37
2.5. Ordered List....................................................................................... 56
2.6. Sparse Matrices.................................................................................. 57
2.7. Garbage Collection............................................................................ 60
Chapter 3 Recursion................................................................................................. 63
3.1. Introduction....................................................................................... 64
3.2. Recursion.......................................................................................... 64
3.3. Tower of Hanoi ................................................................................. 72
3.4. Backtracking ..................................................................................... 74
Chapter 4 Stack........................................................................................................ 77
4.1. Introduction....................................................................................... 78
4.2. Definition of Stack............................................................................. 78
4.3. Operations on Stack.......................................................................... 80
4.4. Disadvantages of Stack...................................................................... 94
4.5. Applications of Stack......................................................................... 94
4.6. Expressions (Polish Notation)............................................................. 95
4.7. Evaluation of Postfix Expression......................................................... 98
4.8. Decimal To Binary Conversion........................................................... 99
4.9. Reversing The String......................................................................... 102
viii
Chapter 8 Graph..................................................................................................... 213
8.1. Introduction..................................................................................... 214
8.2. Definition of Graph......................................................................... 214
8.3. Representation of Graphs................................................................. 221
8.4. Graph Traversal................................................................................ 224
8.5. Spanning Tree.................................................................................. 229
8.6. Shortest Path Problem...................................................................... 240
8.7. Application Of Graph...................................................................... 243
Index...................................................................................................... 309
ix
LIST OF FIGURES
xi
Figure 2.4 Output of Program 2.3.
Figure 2.5 Array positions.
Figure 2.6 3 x 4 array two-dimensional.
Figure 2.7 Row major store in an array.
Figure 2.8 Column major store in an array.
Figure 2.9 Output of Program 2.4.
Figure 2.10 Output of Program 2.5
Figure 2.11 Output of Searching.
Figure 2.12 Output of Program Insertion.
Figure 2.13 Output of Program Deletion.
Figure 2.14 Output of Program Deletion.
Figure 2.15 Polynomial representation.
Figure 2.16 Sparse matrix.
Figure 2.17 Output of Sparse Matrix or not.
Figure 3.1 Output of a Factorial number Using Iteration Method.
Figure 3.2 Output of a Factorial number Using Recursion Method.
Figure 3.3 Output of Fibonacci Series.
Figure 3.4 Output for Check Prime number.
Figure 3.5 Initial Setup of Tower of Hanoi
Figure 3.6 After applying first Step position of Tower
Figure 3.7 After applying second step position of tower
Figure 3.8 After applying third step position of tower.
Figure 3.9 After applying fourth step position of tower.
Figure 3.10 Tree Example.
Figure 4.1 Stack Containing Items.
Figure 4.2 Stack using a 1-dimensional array.
Figure 4.3 Stack empty condition
Figure 4.4 Stack full condition.
Figure 4.5 Performing Push Operation.
Figure 4.6 Performing Pop Operation.
Figure 4.7 Stack Operation.
xii
Figure 4.8 Output Example 4.1.
Figure 4.9 Output of stack operation using linked list.
Figure 4.10 Output of Decimal to Binary
Figure 4.11 Output Reverse a String.
Figure 5.1 Queue structure.
Figure 5.2 Array Implementation of Queue.
Figure 5.3 (a) Queue in Memory.
Figure 5.3 (b) Queue after deleting the first element.
Figure 5.3 (c) Queue after inserting an element.
Figure 5.4 Output of Queue Operations.
Figure 5.5 Output of Queue operation using Linked List.
Figure 5.6 Linear Queue.
Figure 5.7 Circular Queue.
Figure 5.8 Output of Circular Queue Operations
Figure 5.9 D-Queue.
Figure 5.10 (a) Input-restricted D-queue.
Figure 5.10 (b) Output-restricted D-queue.
Figure 5.11 Output of D-Queue Operations.
Figure 5.12 Output of Priority Queue.
Figure 6.1 Structure of a Node
Figure 6.2 Representation of link list.
Figure 6.3 Output of Linked List.
Figure 6.4 A singly-linked list containing three integer values.
Figure 6.5 Output of Single linked list operations.
Figure 6.6 Output of Circular Linked List Operations.
Figure 6.7 Doubly Linked List.
Figure 6.8 Output of Doubly linked list Operations.
Figure 6.9 Structure of a polynomial node.
Figure 6.10 List structure of polynomial.
Figure 6.11 Linked representation of a polynomial two variable.
Figure 7.1 Tree.
Figure 7.2 a, b and c represent a forest.
xiii
Figure 7.3 An example of Tree.
Figure 7.4 Binary tree.
Figure 7.5 Strictly Binary Tree
Figure 7.6 Almost Complete.
Figure 7.7 Complete Binary Tree.
Figure 7.8 Extended Binary Tree.
Figure 7.9 (a) Left -skewed binary tree (b) Right – skewed binary tree.
Figure 7.10 General Tree.
Figure 7.11 Expression Tree.
Figure 7.12 Sequential representation of a binary tree.
Figure 7.13 Structure of a node binary tree.
Figure 7.14 Linked List Representation.
Figure 7.15 Binary Tree (a) and (b).
Figure 7.16 Binary Tree (a) and (b).
Figure 7.17 Binary Tree (a) and (b).
Figure 7.18 Finally Binary Tree.
Figure 7.19 Computing pointer in a binary tree.
Figure 7.20 A threaded binary tree.
Figure 7.21 Binary Search Tree.
Figure 7.22 Binary Search Tree.
Figure 7.23 Before deletion.
Figure 7.24 After deletion.
Figure 7.25 Before deletion.
Figure 7.26 After deletion of a node from the tree.
Figure 7.27 Before deletion.
Figure 7.28 After the deletion of a node from the tree.
Figure 7.29 Red-Black Tree.
Figure 7.30 AVL tree.
Figure 7.31 Not an AVL tree.
Figure 7.32 Classification of Rotation.
Figure 7.33 Balanced AVL search tree.
Figure 7.34 AVL search tree after performing LL rotation.
xiv
Figure 7.35 Balanced AVL search tree.
Figure 7.36 AVL search tree after performing RR rotation
Figure 7.37 Balanced AVL search tree.
Figure 7.38 AVL search tree after performing LR rotation.
Figure 7.39 Balanced AVL search tree.
Figure 7.40 AVL search tree after performing RL rotation.
Figure 7.41 AVL tree Exercise of 7.4
Figure 7.42 Weight Balance Tree.
Figure 8.1 Simple Graph.
Figure 8.2 A Directed Graph.
Figure 8.3 An Undirected Graph.
Figure 8.4 A Complete Graph.
Figure 8.5 A Sub Graph.
Figure 8.6 A connected graph.
Figure 8.7 A Multigraph.
Figure 8.8 A Graph with four Vertices.
Figure 8.9 A directed graph with four Vertices.
Figure 8.10 A Null Graph.
Figure 8.11 An Isomorphic Graph.
Figure 8.12 A Homeomorphic Graph.
Figure 8.13 An Undirected Graph.
Figure 8.14 A Directed Graph.
Figure 8.15 Linked list representation of Figure 8.14.
Figure 8.16 An Undirected Graph.
Figure 8.17 Linked list of Figure 8.16.
Figure 8.18 Graph with six vertices.
Figure 8.19 An undirected graph.
Figure 8.20 An undirected graph.
Figure 8.21 An undirected graph.
Figure 8.22(a) Undirected Graph.
Figure 8.22(b) Spanning Tree.
Figure 8.23 Undirected Graph.
xv
Figure 8.24 Minimum spanning tree Graph of 8.23.
Figure 8.25 Undirected Graph G.
Figure 8.26 A Minimum Spanning tree of Figure 8.25.
Figure 8.27 Undirected Graph G.
Figure 8.28 Undirected Graph G.
Figure 8.29 A Minimum Spanning tree of Figure 8.27
Figure 8.30 Unweighted graph
Figure 8.31 A Graph.
Figure 9.1 Output of Bubble Sort.
Figure 9.2 Output of Insertion Sort.
Figure 9.3 Output of Selection Sort.
Figure 9.4 Output of Merge Sort element.
Figure 9.5 Output of merge sort for two unsorted list.
Figure 9.6 Quick Sort.
Figure 9.7 Output of Quick Sort element.
Figure 9.8 Output of Heap Sort.
Figure 9.9 Output of Radix sort elements.
Figure 10.1 Output for Binary search.
Figure 10.2 A small phone directory book as a hash table.
Figure 10.3 Chaining.
Figure 10.4 Rehashing.
xvi
PREFACE
The significant role of Data Structures is famous for Computer Science and
Engineering. This book is about the structure, actions and the principle of a
different data type that help improve the ability to write an efficient algorithm,
program and Analysis algorithm and program complexity. In this book, we
present the fundamental concepts, operations, and algorithms for different types
of data structures. This makes an understanding of this subject more lucid and
makes it more interesting. This book, intended for the first course in the data
structure at the junior or senior undergraduate level.
This book prepared according to the syllabus of various Universities and
conceived as a textbook for the course of Bachelor of Engineering or Technology
of different branches of computer science. The contents of the book have been
thoroughly organized and spread over ten chapters. Each chapter begins with
the basics and describes with syntax, diagrams, and examples. Each concept
of data structure has implemented in the C programming language. The book
not only covers the scope of the subject but also explains the philosophy of the
subject.
We trust the textbook would meet the requirements of both the teachers and
the students. We would very much appreciate receiving any suggestions for
improvement in the book from teachers, students, and other readers.
We wish to express our deep thanks to all those who helped in making this book
a reality.
We express our gratitude to our publisher and the team of publications that have
taken great pains in publishing the book with speed and accuracy.
1
CHAPTER
DATA STRUCTURES
CONTENTS
1.1. Introduction......................................................................................... 2
1.2. Data Structure Basic Terminology........................................................ 2
1.3. Data Structure...................................................................................... 3
1.4. Introduction To Algorithm.................................................................... 8
1.5. Basic Concept of Function................................................................. 13
1.6. Basic Concept of Pointers.................................................................. 19
1.7. Introduction To Structure.................................................................... 22
1.8. Dynamic Memory Allocation In Data Structure................................. 28
2 Data Structures with C Programming
1.1. INTRODUCTION
In the Computer Programming or Software development, Data Structures is
one of the most valuable roles for computer engineers. Use of appropriate
data structures enables a computer system to perform its task more efficiently,
by influencing the ability of computers to store and retrieve data from any
location in its memory. A data structure is a method of how storing data on
a computer so that it can be used efficiently. In Computer Programming we
are using different types of data to perform, store, access and sent data and
information. Computers cannot do without data, so organizing that data is
very important. If that data is not organized effectively, it is very difficult to
perform any task on that data. If it is organized effectively then any operation
can be performed easily on that data.
The time and space are factors which determine the efficiencies of the
program. The time required for execution of the program cannot be computed
in terms of seconds because of the following factors.
1. The hardware of the machine.
2. The amount of time required by each machine instruction.
3. The amount of time required by the compilers to execute the
instruction.
4. The instruction set.
FIN
ALANIC (MATHILDE)
Francine chez les gens de rien, roman 12 »
AURIOL (G.), TRISTAN BERNARD, COURTELINE (G.), RENARD (J.), VEBER
(P.)
X…, roman impromptu 12 »
BARBUSSE (HENRI)
Le Feu, roman (360e mille) 12 »
Les bourreaux (13e mille) 10 »
Jésus (35e mille) 12 »
BEAUNIER (ANDRÉ)
L’amie de La Rochefoucauld 12 »
BINET-VALMER
Coligny (Un grand Français) 12 »
BIRABEAU (ANDRÉ)
Toutes les mêmes, Monsieur 12 »
BLASCO-IBAÑEZ (V.)
La reine Calafia, roman. Traduit de l’espagnol par C.-A. Pelecier 12 »
BORDEAUX (HENRY), de l’Acad. française
La fée de Port-Cros, roman. Nouv. édit. illustrée 12 »
BOUTET (FRÉDÉRIC)
Le harem éparpillé, roman 12 »
CHÉRAU (GASTON), de l’Acad. Goncourt
Monseigneur voyage, roman (16e mille) 12 »
COLETTE
La fin de chéri, roman (45e m.) 7 50
DAUDET (LÉON), de l’Acad. Goncourt
Le Sang de la nuit, roman (15e m.) 12 »
DEKOBRA (MAURICE)
Le rire dans le brouillard (22e m.) 12 »
DÉMIANS D’ARCHIMBAUD (M.)
Le roman d’une jeune fille pauvre 12 »
DORMOY (MARIE)
L’exorcisée, roman 12 »
DUVERNOIS (HENRI)
Morte la bête 12 »
FARRÈRE (CLAUDE)
Cent millions d’or (32e mille) 12 »
Le dernier Dieu, roman (60e mille) 12 »
L’extraordinaire aventure d’Achmet Pacha Djemaleddine. Nouv. édit.
illustrée (33e m.) 12 »
FISCHER (MAX ET ALEX)
Dans une baignoire, notes et impression de théâtre 12 »
FOLEŸ (CHARLES)
Guilleri Guilloré, roman 12 »
FORT (PAUL)
Les fleurs de lys (Ballades françaises V). Édition définitive 10 »
FRAPIÉ (LÉON)
La divinisée, roman d’une femme 12 »
FRAPPA (JEAN-JOSÉ)
A Paris, sous l’œil des métèques, roman (40e mille) 12 »
GÉNIAUX (CHARLES)
Les feux s’éteignent, roman 12 »
GONCOURT (EDMOND ET JULES DE)
Préfaces et manifestes littéraires (Édition définitive) 10 »
GYP
Le journal d’un philosophe, roman (19e mille) 12 »
HIRSCH (CHARLES-HENRY)
Confession d’un voleur 12 »
LEMONNIER (LÉON)
La femme sans péché, roman 12 »
LENORMAND (H.-R.)
A l’écart 12 »
MARGUERITTE (VICTOR)
La garçonne, roman (625e mille) 12 »
Le compagnon, roman (225e m.) 12 »
Le couple, roman (160e mille) 12 »
Jean-Jacques et l’amour (30e m.) 10 »
MAURRAS (CHARLES)
Anthinéa, d’Athènes à Florence (23e mille) 12 »
MAXIME-DAVID (JEANNE)
Un homme comme quelques autres, roman 12 »
MIRBEAU (OCTAVE)
Les écrivains (2e série) 12 »
MIRZA RIZA KHAN-ARFA (Princesse)
Un violon chanta, roman 12 »
MORENO (MARGUERITE)
La statue de sel et le bonhomme de neige. Souvenirs de ma vie et de
quelques autres 12 »
NAUDEAU (LUDOVIC)
L’Italie fasciste ou l’autre danger 12 »
OSSENDOWSKI (FERDINAND ANTONI)
Derrière la muraille chinoise, roman contemporain. Traduit par M.
Robert Renard 12 »
QUINEL (CHARLES)
Pour amuser le percepteur 10 »
RACHILDE
Monsieur Vénus, roman (42e mille) 9 »
REBOUX (Paul)
Trio, roman (20e mille) 12 »
ROBERT (LOUIS DE)
Ni avec toi ni sans toi, roman 12 »
ROSNY AINÉ (J.-H.), de l’Acad. Goncourt
Une jeune fille à la page, roman (10e mille) 12 »
ROSTAND (MAURICE)
L’ange du suicide, roman 10 »
SÉGUR (NICOLAS)
Platon cherche l’amour, roman 12 »
TITAŸNA
Voyage autour de mon amant, roman 10 »
TRILBI (T.)
La jolie bêtise, roman 12 »
VALDAGNE (PIERRE)
Entre l’amour et les affaires, roman 12 »
ZAMACOÏS (MIGUEL)
Un singulier roman d’amour 12 »
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.
• 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.
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