Data Structures and Algorithms (Python)
Data Structures and Algorithms (Python)
(CD3291 – Data Structures and Algorithms & CD3281 – Data Structures and Algorithm Laboratory)
(Regulation 2021)
Dr. S. Nithyanantham,
Associate Professor
School of Engineering
Department of Computer Science and Engineering
Kalasalingam Academy of Research and Education
Anand Nagar, Krishnankoil.
Assistant Professor
Department of Artificial Intelligence and Data Science Engineering
Erode Sengunthar Engineering College
Perundurai.
A.R.S. Publications
No. 11, Veerabathra Nagar, Part II,
8th Street, Medavakkam,
Chennai – 600 100, Tamil Nadu, India.
Phone: 044 – 48587467, Mobile: 9840025186
eMail: arspublications@gmail.com
web: www.arspublications.com
PREFACE
This book “Data Structures and Algorithms” is about basic idea towards data representation in
program and its manipulation. It provides a clear view towards Abstract Data Type and Object-
Oriented Programming on Python. It provides a preliminary study on linear data structures, sorting,
searching, hashing, Tree and Graph Structures along with Python implementation.
Unit II Summary on Linear structures and its working mechanism. Provides an hands on
understanding towards the Array List, Linked List, Stack and Queue. Linked list were
represented with singly, doubly, circularly, stack and queue through Python.
Unit III Brief knowledge over sorting and searching. Bubble, Selection, Insertion, Merge,
procedures for linear search, binary search, hash functions and collision handling.
Unit IV Transitory awareness on Tree and its traversal. Provides a procedure in Python to
construct Binary Tree, AVL Tree, Heap, B Tree & B+ Tree and Tree Traversal.
Unit V Provides a study over graph and its traversal mechanisms. Python hands on
experience over estimating shortest path and constructing minimum spanning tree
Unit VI It provides an implementation idea over recursive algorithm, List, Stack and Queue.
Understanding towards the several sorting and searching algorithm using python.
Primarily, we would like to thank God. In the process of putting this book together, we realized
how true this gift of writing is for us to share our knowledge. You give us the power to believe in our
passion and pursue our dreams. We could never have done this without the faith we have in you, the
Almighty.
We wholeheartedly thank next God, thy Parents, for showing faith with us and giving
us liberty to choose what we desire. We salute you all for the selfless love, care, pain and sacrifice you
did to shape our life.
We sincerely thank our Colleagues, Friends and Well-wishers for their understanding, patience
in addition, constant encouragement.
Finally, we offer our special thanks to Thiru. A. Ramesh, A. R. S. Publishers and his Colleagues
for their tireless effort in overseeing the production of the book.
The authors would be happy to collect opinion for supplementary improvement of the book.
Dr. S. Nithyanantham
1.4.2 Constructors 7
1.4.3 Inheritance 11
1.4.4 Encapsulation 20
1.4.5 Abstraction 21
1.4.6 Polymorphism 22
1.4.7 Namespaces 23
1.7.3 Example 3: Calculate the number of binary digits in n’s binary representation 59
2.2.4 Inserting 15
2.2.5 Deleting 16
2.2.6 Application 17
2.3 Circular linked lists 18
2.3.5 Deleting 27
2.3.6 Application 27
2.4 Doubly linked lists 28
2.4.7 Application 37
2.5.4 Expressions 49
UNIT III 2
SORTING AND SEARCHING 2
3.1 Sorting 2
3.1.1 Bubble sort 3
3.2 Searching 30
3.2.1 Linear search 31
3.2.2 Binary search 33
3.3 Hashing 37
3.3.4 Rehashing 56
3.3.5 Efficiency 58
UNIT IV 3
TREE STRUCTURES 3
4.1 Tree ADT 3
4.1.1 Terms 4
4.1.2 Properties 5
4.2 Binary Tree ADT 6
4.2.1 Characteristics 7
4.2.2 Various types of Binary Tree 8
4.3.2 Rotation 33
4.3.3 Insert 37
4.3.4 Delete 39
4.4 Heaps 51
4.4.1 Heapify 53
4.5.1 B-Tree 70
4.5.2 B+ Tree 78
4.5.3 B Tree VS B+ Tree 81
UNIT V 2
GRAPH STRUCTURES 2
5.1 Graph 2
5.1.1 Graph ADT 4
UNIT - 6 3
DATA STRUCTURES AND ALGORITHMS LABORATORY 3
Algorithms in Python”, An Indian Adaptation, John Wiley & Sons Inc., 2021.
2. Lee, Kent D., Hubbard, Steve, “Data Structures and Algorithms with Python” Springer
Edition 2015.
3. Rance D. Necaise, “Data Structures and Algorithms Using Python”, John Wiley & Sons,
2011.
4. Aho, Hopcroft, and Ullman, “Data Structures and Algorithms”, Pearson Education, 1983.
6. Mark Allen Weiss, “Data Structures and Algorithm Analysis in C++”, Fourth Edition,