SlideShare a Scribd company logo
Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMY
DATA STRUCTURE
&
ALGORITHM
For
Computer Science
&
Information Technology
By
www.thegateacademy.com
Syllabus DSA
THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
: 080-65700750,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com
Syllabus for Data Structures and Algorithms
Programming in C; Functions, Recursion, Parameter passing, Scope, Binding; Abstract data types,
Arrays, Stacks, Queues, Linked Lists, Trees, Binary search trees, Binary heaps.
Analysis, Asymptotic notation, Notions of space and time complexity, Worst and average case
analysis; Design: Greedy approach, Dynamic programming, Divide-and-conquer; Tree and graph
traversals, Connected components, Spanning trees, Shortest paths; Hashing, Sorting, Searching.
Analysis of GATE Papers
(Data Structures and Algorithms)
Year Percentage of marks Overall Percentage
2013 18.00
11.33%
2012 19.00
2011 13.0
2010 18.00
2009 4.67
2008 4.67
2007 4.67
2006 8.00
2005 7.33
2004 16.67
2003 10.67
Contents DSA
THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
: 080-65700750,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page I
CC OO NN TT EE NN TT SS
Chapters Page No.
#1. Data Structure and Algorithm Analysis 1 – 32
 Assymptotic Notation 1 – 5
 Algorithm Analysis 5 – 10
 Notation of Abstract Data Types 10 – 14
 Recurrence 14 – 17
 Assignment 1 18 – 23
 Assignment 2 24 – 27
 Answer keys 28
 Explanations 28 – 32
#2. Stacks and Queues 33 – 55
 Stacks 33
 Stack ADT Implementations 34 – 36
 The Stack Purmutation 36 – 40
 Running Time Analysis 40 – 41
 Binary Expression Tree 41 – 45
 Queue 45
 Different Type of Queue Implementations 46 – 48
 Assignment 1 49 – 51
 Assignment 2 51 – 52
 Answer keys 53
 Explanations 53 – 55
#3. Trees 56 – 84
 Extended Binary Tree 56
 Binary Tree 56 – 58
 Height Analysis 59 – 60
 Binary Tree Construction Using Inorder 60 – 70
 Assignment 1 71 – 75
 Assignment 2 76 – 78
 Answer keys 79
 Explanations 79 - 84
#4. Height Balanced Trees (AVL Trees, B and B+
) 85 – 113
 AVL Trees 85 – 94
 B – Tree 94 – 96
 Maximizing B-Tree Degree 96 – 102
 B+Tree 102 – 103
Contents DSA
THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
: 080-65700750,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page II
 Maximizing B+ Tree Degree 103 – 104
 Assignment 1 105 – 107
 Assignment 2 107 – 108
 Answer keys 109
 Explanations 109 – 113
#5. Priority Queues (Heaps) 114 – 135
 Introduction 114
 Binary Heap 114 – 118
 Array Representation of Binary Heap 118 – 119
 MinHeap Vs MaxHeap 119
 Basic Heap Operation 119 – 121
 Building a Heap by Inserting Items One at the Time 121 – 125
 Sum of the Height of All Nodes of a Perfect Binary Tree 125 – 126
 Assignment 1 127 – 129
 Assignment 2 130 – 131
 Answer keys 132
 Explanations 132 – 135
#6. Sorting Algorithms 136 – 149
 Bubble Sort 136 – 137
 Insertion Sort 137 – 139
 Selection Sort 139 – 140
 Merge Sort 140 – 141
 Heap Sort 141
 Quick Sort 141 – 142
 Assignment 1 143 – 144
 Assignment 2 145 – 146
 Answer keys 147
 Explanations 147 – 149
#7. Graph Algorithms 150 – 170
 Important Definitions 150 – 151
 Representation of Graphs 151
 Single Source Shortest Path Algorithm 151 – 154
 Minimum Spanning Tree 154 – 159
 Assignment 1 160 – 163
 Assignment 2 163 – 166
 Answer keys 167
 Explanations 167 – 170
#8. Dynamic Programming 171 – 194
 Introduction 171
 Idea of Dynamic Programming 171 – 172
Contents DSA
THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
: 080-65700750,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page III
 Matrix Chain Multiplication Algorithm 172 – 175
 Greedy Algorithm 175 – 183
 NP-Completeness 183 – 186
 Other NP- Complete Problems 186 – 189
 Hashing 189 – 194
Module Test 195 – 209
 Test Questions 195 – 205
 Answer Keys 206
 Explanations 206 – 209
Reference Books 210
Chapter-1 DSA
THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
: 080-65700750,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page 1
CHAPTER 1
Data Structure and Algorithm Analysis
Once an algorithm is given for a problem and decided to be correct, then an important step is to
determine how much in the way of resources, such as time or space, the algorithm will be
required.
The analysis required to estimate use of these resources of an algorithm is generally a
theoretical issue and therefore a formal framework is required. In this framework, we shall
consider a normal computer as a model of computation that will have the standard repertoire of
simple instructions like addition, multiplication, comparison and assignment, but unlike the case
with real computer, it takes exactly one unit time unit to do anything (simple) and there are no
fancy operations such as matrix inversion or sorting, that clearly cannot be done in one unit
time. We also always assume infinite memory.
Asymptotic Notation
The asymptotic notations are used to represent the relative growth rate between functions.
Big–Oh
Represent upper bound on the running time and the memory being consumed by the algorithms.
O(n) essentially conveys that the growth rate of running time/memory consumption rate will
not be more than “n” for all inputs of size n for a given algorithm. However, it may be less than
this.
More formally Big-Oh is defined as follows:
The function   ( )f n O g n if and only if    .f n c g n for all 0,n n n where 0,c n are
positive constants.
Thus, if   ( )f n O g n statement is said to be true then the growth rate of function g(n) is
surely higher than/equal to f(n).
Example 1
  3 2f n n 
3 2 4n n  for all 2n 
 3 2n O n   Here 04, 2c n 
Example 2
  2
3 5f n n n  
2 2
3 5 2n n n   for 3n 
Chapter-1 DSA
THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
: 080-65700750,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page 2
 2 2
3 5n n O n    Here 02, 3c n 
Example 3
  2
3.4n
f n n 
2
3.4 5.4n n
n 
 2
3.4 4n n
n O   for 1n 
Example 4
 2
3 2 4n n O n  
Because here doesn’t exist any positive 0n and cso that Big-Oh equation gets satisfied.
Remarks:
For the function 4n+3,
4n+3 is  O n
4n+3 is also  2
O n and  3
O n
Even though 4n+3 is  2
O n and  3
O n but the best answer for , 4n+3 is  O n only, as
 O n shows most tighter upper bound than the other in the question.
Big-Oh Properties
1. If  f n is   O g n then  .a f n is also   O g n
2. If  f n is   O g n and  h n is   O p n then          max ,f n h n O g n p n 
Example 5
   2
f n =n , h n =logn
 2 2
n logn O n 
3. If  f n is   O g n and  h n is   O p n then    .f n h n is     .O g n p n
Chapter-1 DSA
THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
: 080-65700750,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page 3
4. If  f n is   O g n and  g n is   O h n then  f n is also   O h n
5. log k
n is  logO n
6. If  f n is any polynomial of degree m,   1
1 1 0. ....m m
m mf n a n a n a n a
    ,
then f n is  m
O n
In general one should remember order of the following functions which will help while solving
the relative growth rate of more complicated functions.
               2 3 k n
O 1 ,O logn ,O n ,O nlogn ,O n ,O n ....O n ,O 2
All the functions are arranged in increasing order of growth rate.
If an algorithm has the time complexity  1O , then the time complexity is said to be constant,
that means running time is independent of input size.
Big Omega 
Big Omega represents lower bound on the running time and the memory being consumed by the
algorithms. Ω n essentially conveys that the growth rate of running time/memory
consumption rate will not be less than “n” for all inputs of size n for a given algorithm. However,
it may be greater than this.
More formally Big-Omega is defined as follows:
If  f x and  g x are any two functions and  f x is   ,g x
If    .f x c g x for x k where c and k are any two positive constants.
Thus, if  f x is   g x statement is said to be true then the growth rate of function g(x) is
surely lower than/equal to f(x).
Example 6:
f n n
n n for n
2 2n y n  for 1n 
2 4n  is Ω n here 2, 1c k 
we can also say that 2 4n n  for 1n  then 1, 1c k 
Chapter-1 DSA
THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
: 080-65700750,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page 4
Remarks:
If  f n is   O g n , then  g n is   f n .
Example: 7
2
n is  3
O n
3
n is  2
n
Theta Notation ( )
Theta represents tightest bound on the running time and the memory being consumed by the
algorithms. (n) essentially conveys that the growth rate of running time/memory consumption
rate will be equal to “n” for all inputs of size n for a given algorithm. It actually conveys that both
lower and upper bounds are equal.
More formally Theta is defined as follows:
If  f x and  g x are two functions, and
if    .f x c g x for 0x x , then
    f x g x  here c and x0 are two positive constants.
Thus, if     f x g x  statement is said to be true then the growth rate of function g(x) is
surely equal to f(x) and not less or not more than f(x).
Example 8
f(n) = n2 + n + 1; g(n) = 5n2 + 1; h(n) = 2logn + n2
Then, f(n) = (g(n)) because both have same degree and hence will have same growth rate.
f(n) = (h(n)) statement is also true because both have same degree and hence will have same
growth rates.
h(n) can be simplified as follows:
2logn is n only,
Let 2logn = n ---------> 1
By taking log on both sides in equation 1.
logn*loge2 = logen
Chapter-1 DSA
THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
: 080-65700750,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page 5
Then, after simplifying the above equation
logn = logen/ loge2 = logn.
Remarks
 If     f x g x  then  g x is also   f x
 If     f x g x  we can say that  f x is   O g x and  f x is
  g x and also g x is O f x and g x is Ω f x
Algorithm Definition
An algorithm is a finite set of steps or instructions to accomplish a particular task represented in
a step by step procedure. Algorithm possesses the following basic properties:
 An algorithm may have some input.
 An algorithm should produce at least one output.
 Each statement should be clear without any ambiguity.
 An algorithm in contrast to a program should terminate in a finite amount of time.
Algorithm Analysis
The following two components need to be analyzed for determining algorithm efficiency. If we
have more than one algorithms for solving a problem then we really need to consider these two
before utilizing one of them.
 Running time complexity
The time required for running an algorithm.
 Space complexity
The amount of space required at run-time by an algorithm for solving a given problem.
In general these measurements are expressed in terms of asymptotic notations, like Big-Oh,
theta, Omega etc.
Therefore, h(n) = n + n2.
Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMY

More Related Content

What's hot (20)

PPT
Complexity of Algorithm
Muhammad Muzammal
 
PDF
Data Structure: Algorithm and analysis
Dr. Rajdeep Chatterjee
 
PPTX
Data structure and algorithm using java
Narayan Sau
 
PPT
Introduction to Algorithms
Venkatesh Iyer
 
PPT
Basic terminologies & asymptotic notations
Rajendran
 
PPT
Introduction to data structures and Algorithm
Dhaval Kaneria
 
PDF
Introduction to Algorithms Complexity Analysis
Dr. Pankaj Agarwal
 
PPTX
Algorithm Complexity and Main Concepts
Adelina Ahadova
 
PPTX
Time space trade off
anisha talwar
 
PPTX
Applications of data structures
Wipro
 
PDF
Algorithem complexity in data sructure
Kumar
 
PPTX
Recursion
Nalin Adhikari
 
PPT
Time andspacecomplexity
LAKSHMITHARUN PONNAM
 
PPTX
Performance analysis(Time & Space Complexity)
swapnac12
 
PPT
Data Structures and Algorithm Analysis
Mary Margarat
 
PPTX
Big o notation
hamza mushtaq
 
PPT
Algorithm analysis
sumitbardhan
 
PPTX
Computational Complexity
Kasun Ranga Wijeweera
 
PPTX
Big o notation
keb97
 
PPTX
Complexity analysis - The Big O Notation
Jawad Khan
 
Complexity of Algorithm
Muhammad Muzammal
 
Data Structure: Algorithm and analysis
Dr. Rajdeep Chatterjee
 
Data structure and algorithm using java
Narayan Sau
 
Introduction to Algorithms
Venkatesh Iyer
 
Basic terminologies & asymptotic notations
Rajendran
 
Introduction to data structures and Algorithm
Dhaval Kaneria
 
Introduction to Algorithms Complexity Analysis
Dr. Pankaj Agarwal
 
Algorithm Complexity and Main Concepts
Adelina Ahadova
 
Time space trade off
anisha talwar
 
Applications of data structures
Wipro
 
Algorithem complexity in data sructure
Kumar
 
Recursion
Nalin Adhikari
 
Time andspacecomplexity
LAKSHMITHARUN PONNAM
 
Performance analysis(Time & Space Complexity)
swapnac12
 
Data Structures and Algorithm Analysis
Mary Margarat
 
Big o notation
hamza mushtaq
 
Algorithm analysis
sumitbardhan
 
Computational Complexity
Kasun Ranga Wijeweera
 
Big o notation
keb97
 
Complexity analysis - The Big O Notation
Jawad Khan
 

Viewers also liked (20)

PPT
Data structure introduction
ramyasanthosh
 
PPTX
AP Computer Science Test Prep - Part 3 - Data Structure & Algorithm
NR Computer Learning Center
 
PPTX
Security Compensation - How to Invest in Start-Up Security
Christopher Grayson
 
PDF
Meaningful Elearning with Digital Badges & Missions
Shelly Sanchez Terrell
 
PDF
Data localization and translation
Motti Danino
 
PPT
Php Docs
Pablo Viquez
 
PDF
"Internationalisation with PHP and Intl" source code
Daniel_Rhodes
 
PPTX
Number Series: How To Solve Questions with Short Tricks
Entrance Exam Info
 
PPTX
Number series
Are Lavanya
 
PPTX
Multi language for php with gettext
Binh Quan Duc
 
ODP
Handling multibyte CSV files in PHP
Daniel_Rhodes
 
PPT
The Big Documentation Extravaganza
Stephan Schmidt
 
PDF
Problem Solving with Algorithms and Data Structures
Yi-Lung Tsai
 
PDF
Data structure and algorithm.(dsa)
mailmerk
 
PDF
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Ryan Weaver
 
PDF
People code events flowchart
Satish Ap
 
ODP
Internationalisation with PHP and Intl
Daniel_Rhodes
 
PPTX
17 online learning resources and websites you should check out
Tiffany St James
 
PPTX
Logical reasoning number series
Praveesh Palakeel
 
PDF
10 Principles of English Teaching (SLA Research)
Phung Huy
 
Data structure introduction
ramyasanthosh
 
AP Computer Science Test Prep - Part 3 - Data Structure & Algorithm
NR Computer Learning Center
 
Security Compensation - How to Invest in Start-Up Security
Christopher Grayson
 
Meaningful Elearning with Digital Badges & Missions
Shelly Sanchez Terrell
 
Data localization and translation
Motti Danino
 
Php Docs
Pablo Viquez
 
"Internationalisation with PHP and Intl" source code
Daniel_Rhodes
 
Number Series: How To Solve Questions with Short Tricks
Entrance Exam Info
 
Number series
Are Lavanya
 
Multi language for php with gettext
Binh Quan Duc
 
Handling multibyte CSV files in PHP
Daniel_Rhodes
 
The Big Documentation Extravaganza
Stephan Schmidt
 
Problem Solving with Algorithms and Data Structures
Yi-Lung Tsai
 
Data structure and algorithm.(dsa)
mailmerk
 
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Ryan Weaver
 
People code events flowchart
Satish Ap
 
Internationalisation with PHP and Intl
Daniel_Rhodes
 
17 online learning resources and websites you should check out
Tiffany St James
 
Logical reasoning number series
Praveesh Palakeel
 
10 Principles of English Teaching (SLA Research)
Phung Huy
 
Ad

Similar to Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMY (20)

PDF
ESINF03-AlgAnalis.pdfESINF03-AlgAnalis.pdf
LusArajo20
 
PPT
Complexity analysis
KaranAgarwal71
 
PPT
Complete Book Lectures maths theory helpful for kids.ppt
AishaAnwar16
 
PPTX
Chapter two
mihiretu kassaye
 
PDF
Data Structure - Lecture 1 - Introduction.pdf
donotreply20
 
PPT
lecture 1
sajinsc
 
PPTX
Algorithms DM
Rokonuzzaman Rony
 
PPTX
Chapter one Department Computer Science
demissieejo
 
PPTX
Data structures notes for college students btech.pptx
KarthikVijay59
 
PPTX
Presentation_23953_Content_Document_20240906040454PM.pptx
rameshmanoj733
 
PDF
1-Algorithm Analysijhjhjhjhjhjhjhjhjhjs.pdf
NGUYNTHNHQUC2
 
PPT
19 algorithms-and-complexity-110627100203-phpapp02
Muhammad Aslam
 
PPT
Chapter 1 & 2 - Introduction dhjgsdkjfsaf.ppt
AbdisaAwel
 
PDF
DSA
rrupa2
 
PDF
Data Structure & Algorithms - Mathematical
babuk110
 
PPTX
DAA Week 2 slide for design algorithm and analysis.pptx
Abdulahad481035
 
PPTX
Algorithm Analysis
Megha V
 
PPTX
Intro to super. advance algorithm..pptx
ManishBaranwal10
 
PDF
DATA STRUCTURE
RobinRohit2
 
PDF
DATA STRUCTURE.pdf
ibrahim386946
 
ESINF03-AlgAnalis.pdfESINF03-AlgAnalis.pdf
LusArajo20
 
Complexity analysis
KaranAgarwal71
 
Complete Book Lectures maths theory helpful for kids.ppt
AishaAnwar16
 
Chapter two
mihiretu kassaye
 
Data Structure - Lecture 1 - Introduction.pdf
donotreply20
 
lecture 1
sajinsc
 
Algorithms DM
Rokonuzzaman Rony
 
Chapter one Department Computer Science
demissieejo
 
Data structures notes for college students btech.pptx
KarthikVijay59
 
Presentation_23953_Content_Document_20240906040454PM.pptx
rameshmanoj733
 
1-Algorithm Analysijhjhjhjhjhjhjhjhjhjs.pdf
NGUYNTHNHQUC2
 
19 algorithms-and-complexity-110627100203-phpapp02
Muhammad Aslam
 
Chapter 1 & 2 - Introduction dhjgsdkjfsaf.ppt
AbdisaAwel
 
DSA
rrupa2
 
Data Structure & Algorithms - Mathematical
babuk110
 
DAA Week 2 slide for design algorithm and analysis.pptx
Abdulahad481035
 
Algorithm Analysis
Megha V
 
Intro to super. advance algorithm..pptx
ManishBaranwal10
 
DATA STRUCTURE
RobinRohit2
 
DATA STRUCTURE.pdf
ibrahim386946
 
Ad

More from klirantga (11)

PDF
Mechanical Engineering : Engineering mechanics, THE GATE ACADEMY
klirantga
 
PDF
Instrumentation Engineering : Transducers, THE GATE ACADEMY
klirantga
 
PDF
Instrumentation Engineering : Signals & systems, THE GATE ACADEMY
klirantga
 
PDF
Electrical and Electronics Engineering : Power electronics, THE GATE ACADEMY
klirantga
 
PDF
Electronics and Communication Engineering : Digital circuits, THE GATE ACADEMY
klirantga
 
PDF
Electronics and Communication Engineering : Control systems, THE GATE ACADEMY
klirantga
 
PDF
Electronics and Communication Engineering : Communications, THE GATE ACADEMY
klirantga
 
PDF
Electronics and Communication Engineering : Analog circuits, THE GATE ACADEMY
klirantga
 
PDF
Computer Science Engineering: Discrete mathematics & graph theory, THE GATE A...
klirantga
 
PDF
Civil Engineering : Rcc & steel structures, THE GATE ACADEMY
klirantga
 
PDF
Gate material civil engineering, environmental engineering
klirantga
 
Mechanical Engineering : Engineering mechanics, THE GATE ACADEMY
klirantga
 
Instrumentation Engineering : Transducers, THE GATE ACADEMY
klirantga
 
Instrumentation Engineering : Signals & systems, THE GATE ACADEMY
klirantga
 
Electrical and Electronics Engineering : Power electronics, THE GATE ACADEMY
klirantga
 
Electronics and Communication Engineering : Digital circuits, THE GATE ACADEMY
klirantga
 
Electronics and Communication Engineering : Control systems, THE GATE ACADEMY
klirantga
 
Electronics and Communication Engineering : Communications, THE GATE ACADEMY
klirantga
 
Electronics and Communication Engineering : Analog circuits, THE GATE ACADEMY
klirantga
 
Computer Science Engineering: Discrete mathematics & graph theory, THE GATE A...
klirantga
 
Civil Engineering : Rcc & steel structures, THE GATE ACADEMY
klirantga
 
Gate material civil engineering, environmental engineering
klirantga
 

Recently uploaded (20)

PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
community health nursing question paper 2.pdf
Prince kumar
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Dimensions of Societal Planning in Commonism
StefanMz
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 

Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMY

  • 3. Syllabus DSA THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th Cross, 10th Main, Jayanagar 4th Block, Bangalore-11 : 080-65700750,  [email protected] © Copyright reserved. Web: www.thegateacademy.com Syllabus for Data Structures and Algorithms Programming in C; Functions, Recursion, Parameter passing, Scope, Binding; Abstract data types, Arrays, Stacks, Queues, Linked Lists, Trees, Binary search trees, Binary heaps. Analysis, Asymptotic notation, Notions of space and time complexity, Worst and average case analysis; Design: Greedy approach, Dynamic programming, Divide-and-conquer; Tree and graph traversals, Connected components, Spanning trees, Shortest paths; Hashing, Sorting, Searching. Analysis of GATE Papers (Data Structures and Algorithms) Year Percentage of marks Overall Percentage 2013 18.00 11.33% 2012 19.00 2011 13.0 2010 18.00 2009 4.67 2008 4.67 2007 4.67 2006 8.00 2005 7.33 2004 16.67 2003 10.67
  • 4. Contents DSA THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th Cross, 10th Main, Jayanagar 4th Block, Bangalore-11 : 080-65700750,  [email protected] © Copyright reserved. Web: www.thegateacademy.com Page I CC OO NN TT EE NN TT SS Chapters Page No. #1. Data Structure and Algorithm Analysis 1 – 32  Assymptotic Notation 1 – 5  Algorithm Analysis 5 – 10  Notation of Abstract Data Types 10 – 14  Recurrence 14 – 17  Assignment 1 18 – 23  Assignment 2 24 – 27  Answer keys 28  Explanations 28 – 32 #2. Stacks and Queues 33 – 55  Stacks 33  Stack ADT Implementations 34 – 36  The Stack Purmutation 36 – 40  Running Time Analysis 40 – 41  Binary Expression Tree 41 – 45  Queue 45  Different Type of Queue Implementations 46 – 48  Assignment 1 49 – 51  Assignment 2 51 – 52  Answer keys 53  Explanations 53 – 55 #3. Trees 56 – 84  Extended Binary Tree 56  Binary Tree 56 – 58  Height Analysis 59 – 60  Binary Tree Construction Using Inorder 60 – 70  Assignment 1 71 – 75  Assignment 2 76 – 78  Answer keys 79  Explanations 79 - 84 #4. Height Balanced Trees (AVL Trees, B and B+ ) 85 – 113  AVL Trees 85 – 94  B – Tree 94 – 96  Maximizing B-Tree Degree 96 – 102  B+Tree 102 – 103
  • 5. Contents DSA THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th Cross, 10th Main, Jayanagar 4th Block, Bangalore-11 : 080-65700750,  [email protected] © Copyright reserved. Web: www.thegateacademy.com Page II  Maximizing B+ Tree Degree 103 – 104  Assignment 1 105 – 107  Assignment 2 107 – 108  Answer keys 109  Explanations 109 – 113 #5. Priority Queues (Heaps) 114 – 135  Introduction 114  Binary Heap 114 – 118  Array Representation of Binary Heap 118 – 119  MinHeap Vs MaxHeap 119  Basic Heap Operation 119 – 121  Building a Heap by Inserting Items One at the Time 121 – 125  Sum of the Height of All Nodes of a Perfect Binary Tree 125 – 126  Assignment 1 127 – 129  Assignment 2 130 – 131  Answer keys 132  Explanations 132 – 135 #6. Sorting Algorithms 136 – 149  Bubble Sort 136 – 137  Insertion Sort 137 – 139  Selection Sort 139 – 140  Merge Sort 140 – 141  Heap Sort 141  Quick Sort 141 – 142  Assignment 1 143 – 144  Assignment 2 145 – 146  Answer keys 147  Explanations 147 – 149 #7. Graph Algorithms 150 – 170  Important Definitions 150 – 151  Representation of Graphs 151  Single Source Shortest Path Algorithm 151 – 154  Minimum Spanning Tree 154 – 159  Assignment 1 160 – 163  Assignment 2 163 – 166  Answer keys 167  Explanations 167 – 170 #8. Dynamic Programming 171 – 194  Introduction 171  Idea of Dynamic Programming 171 – 172
  • 6. Contents DSA THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th Cross, 10th Main, Jayanagar 4th Block, Bangalore-11 : 080-65700750,  [email protected] © Copyright reserved. Web: www.thegateacademy.com Page III  Matrix Chain Multiplication Algorithm 172 – 175  Greedy Algorithm 175 – 183  NP-Completeness 183 – 186  Other NP- Complete Problems 186 – 189  Hashing 189 – 194 Module Test 195 – 209  Test Questions 195 – 205  Answer Keys 206  Explanations 206 – 209 Reference Books 210
  • 7. Chapter-1 DSA THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th Cross, 10th Main, Jayanagar 4th Block, Bangalore-11 : 080-65700750,  [email protected] © Copyright reserved. Web: www.thegateacademy.com Page 1 CHAPTER 1 Data Structure and Algorithm Analysis Once an algorithm is given for a problem and decided to be correct, then an important step is to determine how much in the way of resources, such as time or space, the algorithm will be required. The analysis required to estimate use of these resources of an algorithm is generally a theoretical issue and therefore a formal framework is required. In this framework, we shall consider a normal computer as a model of computation that will have the standard repertoire of simple instructions like addition, multiplication, comparison and assignment, but unlike the case with real computer, it takes exactly one unit time unit to do anything (simple) and there are no fancy operations such as matrix inversion or sorting, that clearly cannot be done in one unit time. We also always assume infinite memory. Asymptotic Notation The asymptotic notations are used to represent the relative growth rate between functions. Big–Oh Represent upper bound on the running time and the memory being consumed by the algorithms. O(n) essentially conveys that the growth rate of running time/memory consumption rate will not be more than “n” for all inputs of size n for a given algorithm. However, it may be less than this. More formally Big-Oh is defined as follows: The function   ( )f n O g n if and only if    .f n c g n for all 0,n n n where 0,c n are positive constants. Thus, if   ( )f n O g n statement is said to be true then the growth rate of function g(n) is surely higher than/equal to f(n). Example 1   3 2f n n  3 2 4n n  for all 2n   3 2n O n   Here 04, 2c n  Example 2   2 3 5f n n n   2 2 3 5 2n n n   for 3n 
  • 8. Chapter-1 DSA THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th Cross, 10th Main, Jayanagar 4th Block, Bangalore-11 : 080-65700750,  [email protected] © Copyright reserved. Web: www.thegateacademy.com Page 2  2 2 3 5n n O n    Here 02, 3c n  Example 3   2 3.4n f n n  2 3.4 5.4n n n   2 3.4 4n n n O   for 1n  Example 4  2 3 2 4n n O n   Because here doesn’t exist any positive 0n and cso that Big-Oh equation gets satisfied. Remarks: For the function 4n+3, 4n+3 is  O n 4n+3 is also  2 O n and  3 O n Even though 4n+3 is  2 O n and  3 O n but the best answer for , 4n+3 is  O n only, as  O n shows most tighter upper bound than the other in the question. Big-Oh Properties 1. If  f n is   O g n then  .a f n is also   O g n 2. If  f n is   O g n and  h n is   O p n then          max ,f n h n O g n p n  Example 5    2 f n =n , h n =logn  2 2 n logn O n  3. If  f n is   O g n and  h n is   O p n then    .f n h n is     .O g n p n
  • 9. Chapter-1 DSA THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th Cross, 10th Main, Jayanagar 4th Block, Bangalore-11 : 080-65700750,  [email protected] © Copyright reserved. Web: www.thegateacademy.com Page 3 4. If  f n is   O g n and  g n is   O h n then  f n is also   O h n 5. log k n is  logO n 6. If  f n is any polynomial of degree m,   1 1 1 0. ....m m m mf n a n a n a n a     , then f n is  m O n In general one should remember order of the following functions which will help while solving the relative growth rate of more complicated functions.                2 3 k n O 1 ,O logn ,O n ,O nlogn ,O n ,O n ....O n ,O 2 All the functions are arranged in increasing order of growth rate. If an algorithm has the time complexity  1O , then the time complexity is said to be constant, that means running time is independent of input size. Big Omega  Big Omega represents lower bound on the running time and the memory being consumed by the algorithms. Ω n essentially conveys that the growth rate of running time/memory consumption rate will not be less than “n” for all inputs of size n for a given algorithm. However, it may be greater than this. More formally Big-Omega is defined as follows: If  f x and  g x are any two functions and  f x is   ,g x If    .f x c g x for x k where c and k are any two positive constants. Thus, if  f x is   g x statement is said to be true then the growth rate of function g(x) is surely lower than/equal to f(x). Example 6: f n n n n for n 2 2n y n  for 1n  2 4n  is Ω n here 2, 1c k  we can also say that 2 4n n  for 1n  then 1, 1c k 
  • 10. Chapter-1 DSA THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th Cross, 10th Main, Jayanagar 4th Block, Bangalore-11 : 080-65700750,  [email protected] © Copyright reserved. Web: www.thegateacademy.com Page 4 Remarks: If  f n is   O g n , then  g n is   f n . Example: 7 2 n is  3 O n 3 n is  2 n Theta Notation ( ) Theta represents tightest bound on the running time and the memory being consumed by the algorithms. (n) essentially conveys that the growth rate of running time/memory consumption rate will be equal to “n” for all inputs of size n for a given algorithm. It actually conveys that both lower and upper bounds are equal. More formally Theta is defined as follows: If  f x and  g x are two functions, and if    .f x c g x for 0x x , then     f x g x  here c and x0 are two positive constants. Thus, if     f x g x  statement is said to be true then the growth rate of function g(x) is surely equal to f(x) and not less or not more than f(x). Example 8 f(n) = n2 + n + 1; g(n) = 5n2 + 1; h(n) = 2logn + n2 Then, f(n) = (g(n)) because both have same degree and hence will have same growth rate. f(n) = (h(n)) statement is also true because both have same degree and hence will have same growth rates. h(n) can be simplified as follows: 2logn is n only, Let 2logn = n ---------> 1 By taking log on both sides in equation 1. logn*loge2 = logen
  • 11. Chapter-1 DSA THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th Cross, 10th Main, Jayanagar 4th Block, Bangalore-11 : 080-65700750,  [email protected] © Copyright reserved. Web: www.thegateacademy.com Page 5 Then, after simplifying the above equation logn = logen/ loge2 = logn. Remarks  If     f x g x  then  g x is also   f x  If     f x g x  we can say that  f x is   O g x and  f x is   g x and also g x is O f x and g x is Ω f x Algorithm Definition An algorithm is a finite set of steps or instructions to accomplish a particular task represented in a step by step procedure. Algorithm possesses the following basic properties:  An algorithm may have some input.  An algorithm should produce at least one output.  Each statement should be clear without any ambiguity.  An algorithm in contrast to a program should terminate in a finite amount of time. Algorithm Analysis The following two components need to be analyzed for determining algorithm efficiency. If we have more than one algorithms for solving a problem then we really need to consider these two before utilizing one of them.  Running time complexity The time required for running an algorithm.  Space complexity The amount of space required at run-time by an algorithm for solving a given problem. In general these measurements are expressed in terms of asymptotic notations, like Big-Oh, theta, Omega etc. Therefore, h(n) = n + n2.