Table of Contents Data Structures and Algorithms Made Easy - Java
Table of Contents Data Structures and Algorithms Made Easy - Java
And
Algorithms
Made Easy In JAVA
Data Structure and Algorithmic Puzzles
By
Narasimha Karumanchi
Copyright 2015 by .
All rights reserved.
Designed by
Acknowledgements
and , it is impossible to thank you adequately for everything you have done, from loving me
unconditionally to raising me in a stable household, where you persistent efforts traditional values and
taught your children to celebrate and embrace life. I could not have asked for better parents or rolemodels. You showed me that anything is possible with faith, hard work and determination.
This book would not have been possible without the help of many people. I would like to thank them for
their efforts in improving the end result. Before we do so, however, I should mention that I have done my
best to correct the mistakes that the reviewers have pointed out and to accurately describe the protocols
and mechanisms. I alone am responsible for any remaining errors.
First and foremost, I would like to express my gratitude to many people who saw me through this book, to
all those who provided support, talked things over, read, wrote, offered comments, allowed me to quote
their remarks and assisted in the editing, proofreading and design. In particular, I would like to thank the
following individuals.
-
M-Tech,
Founder, .
Preface
Dear Reader,
Please Hold on! I know many people do not read the preface. But I would strongly recommend that you
go through the preface of this book at least. The reason for this is that this preface has
to offer.
The main objective of the book is not to give you the theorems and proofs about and
. I have followed a pattern of improving the problem solutions with different complexities (for
each problem, you will find multiple solutions with different, and reduced complexities). Basically, its an
enumeration of possible solutions. With this approach, even if you get a new question it will show you a
way to think about all possible solutions. This book is very useful for interview preparation, competitive
exams preparation, and campus interview preparations.
As a if you read the complete book with good understanding, I am sure you will challenge the
interviewers and that is the objective of this book. If you read it as an , you will deliver better
lectures with an easy approach and as a result your students will appreciate the fact that they have opted
for Computer Science / Information Technology as their degree.
This book is very useful for the of and during their academic
preparations. In all the chapters you will see that more importance has been given to problems and their
analysis instead of theory. For each chapter, first you will read about the basic required theory and this
will be followed by a section on problem sets. There are approximately 700 algorithmic problems and all of
them are with solutions.
If you read as a preparing for competitive exams for Computer Science/Information Technology,
the content of this book covers the topics in full detail. While writing this book, my focus has
been to help students who are preparing for these exams.
In all the chapters you will see more importance given to problems and analyzing them instead of
concentrating more on theory. For each chapter, first you will see the basic required theory and then
followed by problems.
For many problems, solutions are provided with different levels of complexities. We start with
solution and slowly move towards the possible for that problem. For each problem
we will try to understand how much time the algorithm is taking and how much memory the algorithm is
taking.
It is that the reader does at least one complete reading of this book to get full understanding
of all the topics. In the subsequent readings, you can go directly to any chapter and refer. Even though,
enough readings were given for correcting the errors, there could be some minor typos in the book. If any
such typos are found, they will be updated at . . . I request you to constantly monitor
this site for any corrections, new problems and solutions. Also, please provide your valuable suggestions
at: @. .
Wish you all the best. I am sure that you will find this book useful.
-
M-Tech,
Founder of .
Table of Contents
1. Introduction ---------------------------------------------------------------------------------------------- 15
1.1 Variables ----------------------------------------------------------------------------------------------------------- 15
1.2 Data types --------------------------------------------------------------------------------------------------------- 15
1.3 Data Structure ---------------------------------------------------------------------------------------------------- 16
1.4 Abstract Data Types (ADTs) ------------------------------------------------------------------------------------ 16
1.5 What is an Algorithm? ------------------------------------------------------------------------------------------- 16
1.6 Why Analysis of Algorithms? ----------------------------------------------------------------------------------- 17
1.7 Goal of Analysis of Algorithms --------------------------------------------------------------------------------- 17
1.8 What is Running Time Analysis? ------------------------------------------------------------------------------ 17
1.9 How to Compare Algorithms? ---------------------------------------------------------------------------------- 17
1.10 What is Rate of Growth? --------------------------------------------------------------------------------------- 17
1.11 Commonly used Rate of Growths ---------------------------------------------------------------------------- 18
1.12 Types of Analysis ----------------------------------------------------------------------------------------------- 19
1.13 Asymptotic Notation -------------------------------------------------------------------------------------------- 19
1.14 Big-O Notation -------------------------------------------------------------------------------------------------- 19
1.15 Omega- Notation ---------------------------------------------------------------------------------------------- 21
1.16 Theta- Notation ----------------------------------------------------------------------------------------------- 21
1.17 Important Notes ------------------------------------------------------------------------------------------------- 22
1.18 Why is it called Asymptotic Analysis? ----------------------------------------------------------------------- 22
1.19 Guidelines for Asymptotic Analysis -------------------------------------------------------------------------- 23
1.20 Properties of Notations ----------------------------------------------------------------------------------------- 24
1.21 Commonly used Logarithms and Summations ------------------------------------------------------------ 24
1.22 Master Theorem for Divide and Conquer ------------------------------------------------------------------- 24
1.23 Problems on Divide and Conquer Master Theorem-------------------------------------------------------- 25
1.24 Master Theorem for Subtract and Conquer Recurrences ------------------------------------------------ 26
1.25 Variant of Subtraction and Conquer master theorem ---------------------------------------------------- 26
1.26 Method of Guessing and Confirm ---------------------------------------------------------------------------- 26
1.27 Amortized Analysis --------------------------------------------------------------------------------------------- 27
1.28 Problems on Algorithms Analysis ---------------------------------------------------------------------------- 28
4. Stacks------------------------------------------------------------------------------------------------------ 99
4.1 What is a Stack? ------------------------------------------------------------------------------------------------- 99
4.2 How Stacks are used? ------------------------------------------------------------------------------------------- 99
4.3 Stack ADT --------------------------------------------------------------------------------------------------------- 99
4.4 Exceptions -------------------------------------------------------------------------------------------------------- 100
4.5 Applications ------------------------------------------------------------------------------------------------------- 100
4.6 Implementation -------------------------------------------------------------------------------------------------- 100
4.7 Comparison of Implementations ------------------------------------------------------------------------------- 105
4.8 Problems on Stacks --------------------------------------------------------------------------------------------- 106