COMPUTER SCIENCE &
INFORMATION TECHNOLOGY
Programing and
Data Structures
Comprehensive Theory
with Solved Examples and Practice Questions
www.madeeasypublications.org
MADE EASY Publications Pvt. Ltd.
Corporate Office: 44-A/4, Kalu Sarai (Near Hauz Khas Metro
Station), New Delhi-110016 | Ph. : 9021300500
Email : [email protected] | Web : www.madeeasypublications.org
First Edition : 2015
Programming and Data Structures Second Edition : 2016
Third Edition : 2017
EDITIONS
© Copyright by MADE EASY Publications Pvt. Ltd.
Fourth Edition : 2018
All rights are reserved. No part of this publication may be
Fifth Edition : 2019
reproduced, stored in or introduced into a retrieval system,
Sixth Edition : 2020
or transmitted in any form or by any means (electronic,
Seventh Edition : 2021
mechanical, photo-copying, recording or otherwise),
Eighth Edition : 2022
without the prior written permission of the above mentioned
Ninth Edition : 2023
publisher of this book.
Tenth Edition : 2024
MADE EASY Publications Pvt. Ltd. has taken due care
in collecting the data and providing the solutions, before
publishing this book. Inspite of this, if any inaccuracy or
printing error occurs then MADE EASY Publications Pvt.
Ltd. owes no responsibility. We will be grateful if you could
point out any such error. Your suggestions will be appreciated.
Programming and Data Structures
CHAPTER 1 3.3 Simple Representation of a Stack.................................... 100
3.4 ADT of Stack............................................................................ 100
Programming Methodology������������������������������� 2-78
3.5 Operations of Stack............................................................... 100
1.1 Data Segments in Memory..................................................... 2
3.6 Average Stack Lifetime of an Element........................... 105
1.2 Scope of Variable........................................................................ 4
1.3 C Variable....................................................................................... 6 3.7 Applications of Stack............................................................ 106
1.4 Operators in C.............................................................................. 9 3.8 Tower of Hanoi....................................................................... 116
1.5 Address arithmetic in C..........................................................16
Student Assignments............................................................. 119
1.6 Value of Variable in C Language..........................................16
1.7 Flow Control in C......................................................................17
1.8 Function.......................................................................................25
CHAPTER 4
1.9 Recursion.....................................................................................31
Queue���������������������������������������������������������127-146
1.10 C Scope Rules.............................................................................34
4.1 Introduction............................................................................ 127
1.11 Storage Class..............................................................................37
1.12 Pointers........................................................................................45 4.2 Operations of Queue............................................................ 127
1.13 Sequence Points in C...............................................................58 4.3 Application of Queue........................................................... 129
1.14 Declarations and Notations..................................................60
4.4 Circular Queue........................................................................ 129
1.15 Const Qualifier...........................................................................61
4.5 Implement Queue using Stacks....................................... 130
1.16 Strings in C..................................................................................62
4.6 Implement Stack Using Queues....................................... 131
Student Assignments................................................................64
4.7 Average Lifetime of an Element in Queue.................... 134
CHAPTER 2 4.8 Types of Queue....................................................................... 134
4.9 Double Ended Queue (Dequeue).................................... 135
Arrays���������������������������������������������������������������79-97
4.10 Priority Queue......................................................................... 136
2.1 Definition of Array....................................................................79
Student Assignments............................................................. 139
2.2 Declaration of Array.................................................................79
2.3 Properties of Array...................................................................80
2.4 Accessing Elements of an Array..........................................83
CHAPTER 5
Student Assignments................................................................92 Linked Lists................................................147-180
5.1 Introduction............................................................................ 147
CHAPTER 3
5.2 Linked Lists.............................................................................. 148
Stack�������������������������������������������������������������98-126 5.3 Uses of Linked lists................................................................ 148
3.1 Introduction...............................................................................98
5.4 Singly Linked List or One Way Chain.............................. 148
3.2 Operation on Stack..................................................................98
5.5 Circular Single Linked List.................................................. 157
iii
Programming and Data Structures
5.6 Doubly Linked Lists or Two-way chain.......................... 159 6.10 Binary Tree Representations.............................................. 193
5.7 List Implementation of Queues........................................ 164 6.11 Implicit Array Representation of Binary Trees................. 194
5.8 List Implementation of Stacks.......................................... 165 6.12 Threaded Binary Trees......................................................... 196
5.9 List Implementation of Priority Queues........................ 166 6.13 Representing Lists as Binary Trees................................... 196
5.10 Other operation on Linked List........................................ 166 6.14 Binary Search Tree................................................................. 199
5.11 Polynomial Addition Using Linked List.......................... 167 6.15 AVL Tree (Adelson Velski Landis)...................................... 208
5.12 Polynomial Multiplication Using Linked List............... 168 Student Assignments............................................................. 223
Student Assignments............................................................. 170
CHAPTER 7
CHAPTER 6
Hashing Techniques................................. 236-252
Trees........................................................... 181-235 7.1 Introduction............................................................................ 236
6.1 Introduction............................................................................ 181 7.2 Hash Function......................................................................... 236
6.2 Glossary..................................................................................... 181 7.3 Collisions................................................................................... 237
6.3 Applications of Tree.............................................................. 182 7.4 Collision Resolution Techniques...................................... 237
6.4 Tree Traversals for Forests................................................... 183
7.5 Hashing Function.................................................................. 244
6.5 Binary Trees.............................................................................. 184
7.6 Comparison of Collision Resolution
6.6 Types of Binary Trees............................................................ 184
Techniques............................................................................... 246
6.7 Applications of Binary Tree................................................ 186
7.7 Various Hash Function......................................................... 246
6.8 Internal and External Nodes.............................................. 190
Student Assignments............................................................. 248
6.9 Expression Trees..................................................................... 192
iv