SlideShare una empresa de Scribd logo
1 de 12
Descargar para leer sin conexión
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.
Data Structures and Algorithms Guide

Más contenido relacionado

La actualidad más candente

Data Structure: Algorithm and analysis
Data Structure: Algorithm and analysisData Structure: Algorithm and analysis
Data Structure: Algorithm and analysisDr. Rajdeep Chatterjee
 
Data structure and algorithm using java
Data structure and algorithm using javaData structure and algorithm using java
Data structure and algorithm using javaNarayan Sau
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to AlgorithmsVenkatesh Iyer
 
Basic terminologies & asymptotic notations
Basic terminologies & asymptotic notationsBasic terminologies & asymptotic notations
Basic terminologies & asymptotic notationsRajendran
 
Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and AlgorithmDhaval Kaneria
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Dr. Pankaj Agarwal
 
Algorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAlgorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAdelina Ahadova
 
Time space trade off
Time space trade offTime space trade off
Time space trade offanisha talwar
 
Applications of data structures
Applications of data structuresApplications of data structures
Applications of data structuresWipro
 
Algorithem complexity in data sructure
Algorithem complexity in data sructureAlgorithem complexity in data sructure
Algorithem complexity in data sructureKumar
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)swapnac12
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm AnalysisMary Margarat
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
Big o notation
Big o notationBig o notation
Big o notationkeb97
 
Complexity analysis - The Big O Notation
Complexity analysis - The Big O NotationComplexity analysis - The Big O Notation
Complexity analysis - The Big O NotationJawad Khan
 

La actualidad más candente (20)

Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
 
Data Structure: Algorithm and analysis
Data Structure: Algorithm and analysisData Structure: Algorithm and analysis
Data Structure: Algorithm and analysis
 
Data structure and algorithm using java
Data structure and algorithm using javaData structure and algorithm using java
Data structure and algorithm using java
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
Basic terminologies & asymptotic notations
Basic terminologies & asymptotic notationsBasic terminologies & asymptotic notations
Basic terminologies & asymptotic notations
 
Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and Algorithm
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis
 
Algorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAlgorithm Complexity and Main Concepts
Algorithm Complexity and Main Concepts
 
Time space trade off
Time space trade offTime space trade off
Time space trade off
 
Applications of data structures
Applications of data structuresApplications of data structures
Applications of data structures
 
Algorithem complexity in data sructure
Algorithem complexity in data sructureAlgorithem complexity in data sructure
Algorithem complexity in data sructure
 
Recursion
RecursionRecursion
Recursion
 
Time andspacecomplexity
Time andspacecomplexityTime andspacecomplexity
Time andspacecomplexity
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm Analysis
 
Big o notation
Big o notationBig o notation
Big o notation
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Computational Complexity
Computational ComplexityComputational Complexity
Computational Complexity
 
Big o notation
Big o notationBig o notation
Big o notation
 
Complexity analysis - The Big O Notation
Complexity analysis - The Big O NotationComplexity analysis - The Big O Notation
Complexity analysis - The Big O Notation
 

Destacado

Data structure introduction
Data structure introductionData structure introduction
Data structure introductionramyasanthosh
 
AP Computer Science Test Prep - Part 3 - Data Structure & Algorithm
AP Computer Science Test Prep - Part 3 - Data Structure & AlgorithmAP Computer Science Test Prep - Part 3 - Data Structure & Algorithm
AP Computer Science Test Prep - Part 3 - Data Structure & AlgorithmNR Computer Learning Center
 
Security Compensation - How to Invest in Start-Up Security
Security Compensation - How to Invest in Start-Up SecuritySecurity Compensation - How to Invest in Start-Up Security
Security Compensation - How to Invest in Start-Up SecurityChristopher Grayson
 
Meaningful Elearning with Digital Badges & Missions
Meaningful Elearning with Digital Badges & MissionsMeaningful Elearning with Digital Badges & Missions
Meaningful Elearning with Digital Badges & MissionsShelly Sanchez Terrell
 
Data localization and translation
Data localization and translationData localization and translation
Data localization and translationMotti Danino
 
"Internationalisation with PHP and Intl" source code
"Internationalisation with PHP and Intl" source code"Internationalisation with PHP and Intl" source code
"Internationalisation with PHP and Intl" source codeDaniel_Rhodes
 
Number Series: How To Solve Questions with Short Tricks
Number Series: How To Solve Questions with Short TricksNumber Series: How To Solve Questions with Short Tricks
Number Series: How To Solve Questions with Short TricksEntrance Exam Info
 
Multi language for php with gettext
Multi language for php with gettextMulti language for php with gettext
Multi language for php with gettextBinh Quan Duc
 
Handling multibyte CSV files in PHP
Handling multibyte CSV files in PHPHandling multibyte CSV files in PHP
Handling multibyte CSV files in PHPDaniel_Rhodes
 
The Big Documentation Extravaganza
The Big Documentation ExtravaganzaThe Big Documentation Extravaganza
The Big Documentation ExtravaganzaStephan Schmidt
 
Problem Solving with Algorithms and Data Structures
Problem Solving with Algorithms and Data StructuresProblem Solving with Algorithms and Data Structures
Problem Solving with Algorithms and Data StructuresYi-Lung Tsai
 
Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)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 BehatGrand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with BehatRyan Weaver
 
People code events flowchart
People code events flowchartPeople code events flowchart
People code events flowchartSatish Ap
 
Internationalisation with PHP and Intl
Internationalisation with PHP and IntlInternationalisation with PHP and Intl
Internationalisation with PHP and IntlDaniel_Rhodes
 
17 online learning resources and websites you should check out
17 online learning resources and websites you should check out17 online learning resources and websites you should check out
17 online learning resources and websites you should check outTiffany St James
 
Logical reasoning number series
Logical reasoning number seriesLogical reasoning number series
Logical reasoning number seriesPraveesh Palakeel
 
10 Principles of English Teaching (SLA Research)
10 Principles of English Teaching (SLA Research)10 Principles of English Teaching (SLA Research)
10 Principles of English Teaching (SLA Research)Phung Huy
 

Destacado (20)

Data structure introduction
Data structure introductionData structure introduction
Data structure introduction
 
AP Computer Science Test Prep - Part 3 - Data Structure & Algorithm
AP Computer Science Test Prep - Part 3 - Data Structure & AlgorithmAP Computer Science Test Prep - Part 3 - Data Structure & Algorithm
AP Computer Science Test Prep - Part 3 - Data Structure & Algorithm
 
Security Compensation - How to Invest in Start-Up Security
Security Compensation - How to Invest in Start-Up SecuritySecurity Compensation - How to Invest in Start-Up Security
Security Compensation - How to Invest in Start-Up Security
 
Meaningful Elearning with Digital Badges & Missions
Meaningful Elearning with Digital Badges & MissionsMeaningful Elearning with Digital Badges & Missions
Meaningful Elearning with Digital Badges & Missions
 
Data localization and translation
Data localization and translationData localization and translation
Data localization and translation
 
Php Docs
Php DocsPhp Docs
Php Docs
 
"Internationalisation with PHP and Intl" source code
"Internationalisation with PHP and Intl" source code"Internationalisation with PHP and Intl" source code
"Internationalisation with PHP and Intl" source code
 
Number Series: How To Solve Questions with Short Tricks
Number Series: How To Solve Questions with Short TricksNumber Series: How To Solve Questions with Short Tricks
Number Series: How To Solve Questions with Short Tricks
 
Number series
Number seriesNumber series
Number series
 
Multi language for php with gettext
Multi language for php with gettextMulti language for php with gettext
Multi language for php with gettext
 
Handling multibyte CSV files in PHP
Handling multibyte CSV files in PHPHandling multibyte CSV files in PHP
Handling multibyte CSV files in PHP
 
The Big Documentation Extravaganza
The Big Documentation ExtravaganzaThe Big Documentation Extravaganza
The Big Documentation Extravaganza
 
Problem Solving with Algorithms and Data Structures
Problem Solving with Algorithms and Data StructuresProblem Solving with Algorithms and Data Structures
Problem Solving with Algorithms and Data Structures
 
Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)
 
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with BehatGrand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
 
People code events flowchart
People code events flowchartPeople code events flowchart
People code events flowchart
 
Internationalisation with PHP and Intl
Internationalisation with PHP and IntlInternationalisation with PHP and Intl
Internationalisation with PHP and Intl
 
17 online learning resources and websites you should check out
17 online learning resources and websites you should check out17 online learning resources and websites you should check out
17 online learning resources and websites you should check out
 
Logical reasoning number series
Logical reasoning number seriesLogical reasoning number series
Logical reasoning number series
 
10 Principles of English Teaching (SLA Research)
10 Principles of English Teaching (SLA Research)10 Principles of English Teaching (SLA Research)
10 Principles of English Teaching (SLA Research)
 

Similar a Data Structures and Algorithms Guide

Basic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusBasic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusNANDINI SHARMA
 
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMSTanya Makkar
 
Measuring algorithm performance
Measuring algorithm performanceMeasuring algorithm performance
Measuring algorithm performanceHabitamuAsimare
 
Daa unit 6_efficiency of algorithms
Daa unit 6_efficiency of algorithmsDaa unit 6_efficiency of algorithms
Daa unit 6_efficiency of algorithmssnehajiyani
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsNagendraK18
 
Ch-2 final exam documet compler design elements
Ch-2 final exam documet compler design elementsCh-2 final exam documet compler design elements
Ch-2 final exam documet compler design elementsMAHERMOHAMED27
 
Asymptotic Analysis
Asymptotic AnalysisAsymptotic Analysis
Asymptotic Analysissonugupta
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematicalbabuk110
 
Data_Structure_and_Algorithms_Lecture_1.ppt
Data_Structure_and_Algorithms_Lecture_1.pptData_Structure_and_Algorithms_Lecture_1.ppt
Data_Structure_and_Algorithms_Lecture_1.pptISHANAMRITSRIVASTAVA
 
Asymptotic Analysis in Data Structure using C
Asymptotic Analysis in Data Structure using CAsymptotic Analysis in Data Structure using C
Asymptotic Analysis in Data Structure using CMeghaj Mallick
 
Algorithm Analysis
Algorithm AnalysisAlgorithm Analysis
Algorithm AnalysisMegha V
 
Weekends with Competitive Programming
Weekends with Competitive ProgrammingWeekends with Competitive Programming
Weekends with Competitive ProgrammingNiharikaSingh839269
 

Similar a Data Structures and Algorithms Guide (20)

Basic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusBasic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV Syllabus
 
DATA STRUCTURE.pdf
DATA STRUCTURE.pdfDATA STRUCTURE.pdf
DATA STRUCTURE.pdf
 
DATA STRUCTURE
DATA STRUCTUREDATA STRUCTURE
DATA STRUCTURE
 
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpall...
Algorithm Class at KPHB  (C, C++ Course Training Institute in KPHB, Kukatpall...Algorithm Class at KPHB  (C, C++ Course Training Institute in KPHB, Kukatpall...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpall...
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 
Measuring algorithm performance
Measuring algorithm performanceMeasuring algorithm performance
Measuring algorithm performance
 
Daa unit 6_efficiency of algorithms
Daa unit 6_efficiency of algorithmsDaa unit 6_efficiency of algorithms
Daa unit 6_efficiency of algorithms
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Ch-2 final exam documet compler design elements
Ch-2 final exam documet compler design elementsCh-2 final exam documet compler design elements
Ch-2 final exam documet compler design elements
 
Asymptotic Analysis
Asymptotic AnalysisAsymptotic Analysis
Asymptotic Analysis
 
The bog oh notation
The bog oh notationThe bog oh notation
The bog oh notation
 
Unit ii algorithm
Unit   ii algorithmUnit   ii algorithm
Unit ii algorithm
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematical
 
Data_Structure_and_Algorithms_Lecture_1.ppt
Data_Structure_and_Algorithms_Lecture_1.pptData_Structure_and_Algorithms_Lecture_1.ppt
Data_Structure_and_Algorithms_Lecture_1.ppt
 
Asymptotic Analysis in Data Structure using C
Asymptotic Analysis in Data Structure using CAsymptotic Analysis in Data Structure using C
Asymptotic Analysis in Data Structure using C
 
Algorithm Analysis
Algorithm AnalysisAlgorithm Analysis
Algorithm Analysis
 
Weekends with Competitive Programming
Weekends with Competitive ProgrammingWeekends with Competitive Programming
Weekends with Competitive Programming
 

Más de klirantga

Mechanical Engineering : Engineering mechanics, THE GATE ACADEMY
Mechanical Engineering  : Engineering mechanics, THE GATE ACADEMYMechanical Engineering  : Engineering mechanics, THE GATE ACADEMY
Mechanical Engineering : Engineering mechanics, THE GATE ACADEMYklirantga
 
Instrumentation Engineering : Transducers, THE GATE ACADEMY
 Instrumentation Engineering : Transducers, THE GATE ACADEMY Instrumentation Engineering : Transducers, THE GATE ACADEMY
Instrumentation Engineering : Transducers, THE GATE ACADEMYklirantga
 
Instrumentation Engineering : Signals & systems, THE GATE ACADEMY
Instrumentation Engineering : Signals & systems, THE GATE ACADEMYInstrumentation Engineering : Signals & systems, THE GATE ACADEMY
Instrumentation Engineering : Signals & systems, THE GATE ACADEMYklirantga
 
Electrical and Electronics Engineering : Power electronics, THE GATE ACADEMY
Electrical and Electronics Engineering : Power electronics, THE GATE ACADEMYElectrical and Electronics Engineering : Power electronics, THE GATE ACADEMY
Electrical and Electronics Engineering : Power electronics, THE GATE ACADEMYklirantga
 
Electronics and Communication Engineering : Digital circuits, THE GATE ACADEMY
Electronics and Communication Engineering : Digital circuits, THE GATE ACADEMYElectronics and Communication Engineering : Digital circuits, THE GATE ACADEMY
Electronics and Communication Engineering : Digital circuits, THE GATE ACADEMYklirantga
 
Electronics and Communication Engineering : Control systems, THE GATE ACADEMY
 Electronics and Communication Engineering  : Control systems, THE GATE ACADEMY Electronics and Communication Engineering  : Control systems, THE GATE ACADEMY
Electronics and Communication Engineering : Control systems, THE GATE ACADEMYklirantga
 
Electronics and Communication Engineering : Communications, THE GATE ACADEMY
Electronics and Communication Engineering : Communications, THE GATE ACADEMYElectronics and Communication Engineering : Communications, THE GATE ACADEMY
Electronics and Communication Engineering : Communications, THE GATE ACADEMYklirantga
 
Electronics and Communication Engineering : Analog circuits, THE GATE ACADEMY
 Electronics and Communication Engineering : Analog circuits, THE GATE ACADEMY Electronics and Communication Engineering : Analog circuits, THE GATE ACADEMY
Electronics and Communication Engineering : Analog circuits, THE GATE ACADEMYklirantga
 
Computer Science Engineering: Discrete mathematics & graph theory, THE GATE A...
Computer Science Engineering: Discrete mathematics & graph theory, THE GATE A...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 ACADEMYCivil Engineering : Rcc & steel structures, THE GATE ACADEMY
Civil Engineering : Rcc & steel structures, THE GATE ACADEMYklirantga
 
Gate material civil engineering, environmental engineering
Gate material   civil engineering, environmental engineeringGate material   civil engineering, environmental engineering
Gate material civil engineering, environmental engineeringklirantga
 

Más de klirantga (11)

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

Último

General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 

Último (20)

General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 

Data Structures and Algorithms Guide

  • 1.
  • 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,  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
  • 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,  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
  • 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,  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
  • 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,  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
  • 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,  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 
  • 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,  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
  • 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,  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 
  • 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,  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
  • 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,  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.