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
Ad

Recommended

Introduction to datastructure and algorithm
Introduction to datastructure and algorithm
Pratik Mota
 
Data structure and algorithm
Data structure and algorithm
Trupti Agrawal
 
Lecture 2 data structures and algorithms
Lecture 2 data structures and algorithms
Aakash deep Singhal
 
Cupdf.com introduction to-data-structures-and-algorithm
Cupdf.com introduction to-data-structures-and-algorithm
TarikuDabala1
 
Data Structure and Algorithms
Data Structure and Algorithms
ManishPrajapati78
 
Algorithm Analyzing
Algorithm Analyzing
Haluan Irsad
 
Multi layered perceptron (mlp)
Multi layered perceptron (mlp)
Handson System
 
DATA STRUCTURE AND ALGORITHM FULL NOTES
DATA STRUCTURE AND ALGORITHM FULL NOTES
Aniruddha Paul
 
Complexity of Algorithm
Complexity of Algorithm
Muhammad Muzammal
 
Data Structure: Algorithm and analysis
Data Structure: Algorithm and analysis
Dr. Rajdeep Chatterjee
 
Data structure and algorithm using java
Data structure and algorithm using java
Narayan Sau
 
Introduction to Algorithms
Introduction to Algorithms
Venkatesh Iyer
 
Basic terminologies & asymptotic notations
Basic terminologies & asymptotic notations
Rajendran
 
Introduction to data structures and Algorithm
Introduction to data structures and Algorithm
Dhaval Kaneria
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis
Dr. Pankaj Agarwal
 
Algorithm Complexity and Main Concepts
Algorithm Complexity and Main Concepts
Adelina Ahadova
 
Time space trade off
Time space trade off
anisha talwar
 
Applications of data structures
Applications of data structures
Wipro
 
Algorithem complexity in data sructure
Algorithem complexity in data sructure
Kumar
 
Recursion
Recursion
Nalin Adhikari
 
Time andspacecomplexity
Time andspacecomplexity
LAKSHMITHARUN PONNAM
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
swapnac12
 
Data Structures and Algorithm Analysis
Data Structures and Algorithm Analysis
Mary Margarat
 
Big o notation
Big o notation
hamza mushtaq
 
Algorithm analysis
Algorithm analysis
sumitbardhan
 
Computational Complexity
Computational Complexity
Kasun Ranga Wijeweera
 
Big o notation
Big o notation
keb97
 
Complexity analysis - The Big O Notation
Complexity analysis - The Big O Notation
Jawad Khan
 
Data structure introduction
Data structure introduction
ramyasanthosh
 
AP Computer Science Test Prep - Part 3 - Data Structure & Algorithm
AP Computer Science Test Prep - Part 3 - Data Structure & Algorithm
NR Computer Learning Center
 

More Related Content

What's hot (20)

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

Viewers also liked (20)

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

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

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

More from klirantga (11)

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

Recently uploaded (20)

“THE BEST CLASS IN SCHOOL”. _
“THE BEST CLASS IN SCHOOL”. _
Colégio Santa Teresinha
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
BINARY files CSV files JSON files with example.pptx
BINARY files CSV files JSON files with example.pptx
Ramakrishna Reddy Bijjam
 
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
Assisting Individuals and Families to Promote and Maintain Health – Unit 7 | ...
Assisting Individuals and Families to Promote and Maintain Health – Unit 7 | ...
RAKESH SAJJAN
 
ICT-8-Module-REVISED-K-10-CURRICULUM.pdf
ICT-8-Module-REVISED-K-10-CURRICULUM.pdf
penafloridaarlyn
 
Wax Moon, Richmond, VA. Terrence McPherson
Wax Moon, Richmond, VA. Terrence McPherson
TerrenceMcPherson1
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
Overview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo Slides
Celine George
 
What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
Introduction to problem solving Techniques
Introduction to problem solving Techniques
merlinjohnsy
 
2025 June Year 9 Presentation: Subject selection.pptx
2025 June Year 9 Presentation: Subject selection.pptx
mansk2
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
Sourav Kr Podder
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
BINARY files CSV files JSON files with example.pptx
BINARY files CSV files JSON files with example.pptx
Ramakrishna Reddy Bijjam
 
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
Assisting Individuals and Families to Promote and Maintain Health – Unit 7 | ...
Assisting Individuals and Families to Promote and Maintain Health – Unit 7 | ...
RAKESH SAJJAN
 
ICT-8-Module-REVISED-K-10-CURRICULUM.pdf
ICT-8-Module-REVISED-K-10-CURRICULUM.pdf
penafloridaarlyn
 
Wax Moon, Richmond, VA. Terrence McPherson
Wax Moon, Richmond, VA. Terrence McPherson
TerrenceMcPherson1
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
Overview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo Slides
Celine George
 
What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
Introduction to problem solving Techniques
Introduction to problem solving Techniques
merlinjohnsy
 
2025 June Year 9 Presentation: Subject selection.pptx
2025 June Year 9 Presentation: Subject selection.pptx
mansk2
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
Sourav Kr Podder
 

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.