SlideShare a Scribd company logo
1 of 30
Introduction to Algorithms
By
Nilesh Dalvi
Lecturer, Patkar-Varde College.Lecturer, Patkar-Varde College.
http://www.slideshare.net/nileshdalvi01
Java and DataJava and Data
StructuresStructures
Algorithm
The algorithm is defined as the a collection of
unambiguous instructions occurring in some specific
sequence and such an algorithm should produce
output for given set of input in finite amount of time.
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Algorithm
• write an algorithm to count the sum of n numbers
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Algorithm sum (1, n)
{
//Problem Desc: Algorithm for finding sum of n numbers
//Input: 1 to n numbers
//Output: Sum of n numbers
result := 0;
for i:= 1 to n do i:= i + 1
result := result + i;
}
Algorithm
• write an algorithm to check whether the given no is
even or odd.
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Algorithm EvenOddTest(val)
{
//Problem Desc: Algorithm for checking whether the given no is even or odd.
//Input: 1 to n number
//Output: Even or odd number
if(val % 2 == 0)
write("No is even");
esle
write ("No is odd");
}
Algorithm
• write an algorithm for sorting the given elements
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Algorithm Sort (a, n)
{
//Problem Desc: Algorithm for sorting the elements.
//Input: An array
//Output: Sorted array
for i:=1 to n do
{
for j:= i +1 to n-1 do
{
if(a[i]) > a[j]) then
{
temp := a[i];
a[i] := a[j];
a[j] := temp;
}
}
write("List is sorted!");
}
}
Algorithm
• write an algorithm for calculating factorial of n
numbers
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Algorithm factCalc (n)
{
//Problem Desc: For calculating factorial of given no
//Input: Number
//Output: Factorial of given number
if n := 1 then
return 1;
else
return n * factCalc(n - 1);
}
Algorithm
• write an algorithm for multiply two matrices
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Algorithm mulMatrix (A, B, n)
{
//Problem Desc: Multilpy two matrices
//Input: Matrix A and Matrix B
//Output: Matrix C
for i := 1 to n do
for j := 1 to n do
C[i][j] := 0;
for k := 1 to n do
C[i][j] := C[i][j] + A[i][k] * B[k][j];
}
Fundamentals of analysis of algorithms
• The efficiency of an algorithm can be decided by
measuring the performance of an algorithm.
• We can measure the performance of an algorithm by
computing two factors
– Amount of time required by an algorithm to execute (time
complexity)
– Amount of storage required by an algorithm (space
complexity)
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Space Complexity
• Space complexity can be defined as amount of memory
required by an algorithm to run.
• To compute space complexity we use two factors : constant
space and variable space
• Constant space includes instructions, variables and constants
• Variable space includes dynamic allocations, function recursion.
• Space requirement, s(p) = C + sp
• sp is the space dependent upon instance characteristics.
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Time Complexity
• The time complexity of an algorithm is the amount of computer
time required by an algorithm to run complete the task.
• The time complexity, T(p), taken by a program p is the sum of
the compile time and the run time.
• Total Time, T(p) = compile time + run (execution) time
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Asymptotic Notations:
• To choose the best algorithm, we need to check efficiency of
each algorithm.
• Efficiency can be measured by computing space and time
complexity.
• So, Asymptotic notation is a shorthand way to represent the
time complexity.
• Using asymptotic notations we can give time complexity as
“fastest possible”, “slowest possible” or “average time”.
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Big Oh Notation:
• Denoted by ‘O’
• Method if representing upper time of representing the upper
bound of algorithms running time.
• Using big Oh notation we can give longest amount of time taken
by the algorithm to complete.
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Omega Notation:
• Denoted by ‘Ω’
• It is used to represent the lower bound of algorithm running
time.
• Using omega (Ω) notation we can denote shortest amount of
time taken by algorithm.
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Theta Notation:
• Denoted by ‘Θ’
• By this method the running time is between upper bound and
lower bound.
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Data Structure
• Data may be organized in many different ways.
• A data structure is a arrangement of data in a
computer memory or on a disk.
• The logical or mathematical model of a particular
organization of data is called data structure.
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Data Structure
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Data Structure Operation
Data appearing in data structures are processed by
means of operations.
Operations are:
•Traversing: Accessing each record exactly once so that
certain items in the record may be processed.
•Searching: Finding the location of the record with a
given key value, or finding the locations of all records
which satisfy one or more conditions.
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Data Structure Operation
• Inserting: Adding the new record to the structure.
• Deleting: Removing a record from the structure.
Special operations:
• Sorting: Arranging the records in some logical order
• Merging: Combining the records in two-different
sorted files into a single-sorted file.
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Linear
1. Array:
2. Stack
3. Queue
4. Linked List
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Array
• An array is a collection of homogeneous type of data
elements.
• An array is consisting of a collection of elements .
• Operation Performed On Array:
1. Traversing
2. Search
3. Insertion
4. Deletion
5. Sorting
6. Merging
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
1
2
3
4
5
Representation of array
Stack
• A Stack is a list of elements in which an element may
be inserted or deleted at one end which is known as
TOP of the stack.
• Operation Performed On Array:
1. Push: add an element in stack
2. Pop: remove an element in stack
3. Peek :Current processed element
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
a
b
c TOP
Queue
• A queue is a linear list of element in which insertion
can be done at one end which is known as REAR and
deletion can be done which is known as FRONT.
• Operation:
1. Insertion : add a new element in queue
2. Deletion: Removing an element in queue
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Queue
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Linked List
• A Linked list is a linear collection of data elements .
• It has two part one is info and other is link part.
• info part gives information and link part is address of
next node
• Operation:
1. Traversing
2. Searching
3. Insertion
4. Deletion
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Non-Linear
1. Graph
2. Tree
3. Table
4. Set
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Graph
• A graph is a collection of sets V and E where V is a
finite non-empty set of vertices and E is finite non-
empty set of edges.
• Vertices – node in graph
• Edges – Two adjacent nodes are joined by edges.
• Graph G = {V, E}
• Operation:
1. Insertion
2. Deletion
3. Searching
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Tree
• Tree is a finite set of one or more nodes such that
– There is a specially designed node called root.
– The remaining nodes are partitioned into n>=0 disjoint sets T1, T2, T3,
…., Tn are called the sub-trees of the Root.
• Operation:
1. Insertion
2. Deletion
3. Searching
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Tables
• This is kind of data structure plays an important role in
information retrieval.
• Types of tables:
– Rectangular
– Jagged
– Inverted
– Hash
• Operation:
1. Insertion
2. Deletion
3. Searching
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Key Value
0 “Abc”
1 “Pqr”
Sets
• Heap is a complete binary tree
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Q & A

More Related Content

What's hot

Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structuresagorolabs
 
String handling(string buffer class)
String handling(string buffer class)String handling(string buffer class)
String handling(string buffer class)Ravi Kant Sahu
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Michelle Anne Meralpis
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programmingNeelesh Shukla
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming ConceptsBhushan Nagaraj
 
Object Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaObject Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaGlenn Guden
 
Session 05 - Strings in Java
Session 05 - Strings in JavaSession 05 - Strings in Java
Session 05 - Strings in JavaPawanMM
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending ClassesNilesh Dalvi
 
Farhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd YearFarhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd Yeardezyneecole
 
05 Java Language And OOP Part V
05 Java Language And OOP Part V05 Java Language And OOP Part V
05 Java Language And OOP Part VHari Christian
 

What's hot (19)

7. Multithreading
7. Multithreading7. Multithreading
7. Multithreading
 
11. Arrays
11. Arrays11. Arrays
11. Arrays
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
14. Linked List
14. Linked List14. Linked List
14. Linked List
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
 
Arrays in Java
Arrays in Java Arrays in Java
Arrays in Java
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
 
String handling(string buffer class)
String handling(string buffer class)String handling(string buffer class)
String handling(string buffer class)
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
List classes
List classesList classes
List classes
 
Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programming
 
Generics
GenericsGenerics
Generics
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
Object Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaObject Oriented Programming Concepts using Java
Object Oriented Programming Concepts using Java
 
Session 05 - Strings in Java
Session 05 - Strings in JavaSession 05 - Strings in Java
Session 05 - Strings in Java
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending Classes
 
Farhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd YearFarhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd Year
 
05 Java Language And OOP Part V
05 Java Language And OOP Part V05 Java Language And OOP Part V
05 Java Language And OOP Part V
 

Viewers also liked

6. Exception Handling
6. Exception Handling6. Exception Handling
6. Exception HandlingNilesh Dalvi
 
5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and Intefaces5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and IntefacesNilesh Dalvi
 
Presentation for handyman
Presentation for handymanPresentation for handyman
Presentation for handymansteven cornett
 
Palacio Gyeongbokgung (Seoul)
Palacio Gyeongbokgung (Seoul) Palacio Gyeongbokgung (Seoul)
Palacio Gyeongbokgung (Seoul) F. Ovies
 
Partes del computador
Partes del computadorPartes del computador
Partes del computadorCamilo Ospina
 
презентация от РПК групп
презентация от РПК групппрезентация от РПК групп
презентация от РПК группIgor Levchuk
 
Devcommerce 2016: Migração plataforma Magazine Luiza e seu laboratório de in...
Devcommerce 2016: Migração plataforma Magazine Luiza e seu  laboratório de in...Devcommerce 2016: Migração plataforma Magazine Luiza e seu  laboratório de in...
Devcommerce 2016: Migração plataforma Magazine Luiza e seu laboratório de in...André Fatala
 

Viewers also liked (14)

6. Exception Handling
6. Exception Handling6. Exception Handling
6. Exception Handling
 
5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and Intefaces5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and Intefaces
 
MEDIO AMBIENTE
MEDIO AMBIENTEMEDIO AMBIENTE
MEDIO AMBIENTE
 
Color clipping
Color clippingColor clipping
Color clipping
 
Presentation for handyman
Presentation for handymanPresentation for handyman
Presentation for handyman
 
Palacio Gyeongbokgung (Seoul)
Palacio Gyeongbokgung (Seoul) Palacio Gyeongbokgung (Seoul)
Palacio Gyeongbokgung (Seoul)
 
Partes del computador
Partes del computadorPartes del computador
Partes del computador
 
Liderazgo terminado
Liderazgo terminadoLiderazgo terminado
Liderazgo terminado
 
презентация от РПК групп
презентация от РПК групппрезентация от РПК групп
презентация от РПК групп
 
Ntick tecnología
Ntick tecnologíaNtick tecnología
Ntick tecnología
 
Ciudadanía digital
Ciudadanía digitalCiudadanía digital
Ciudadanía digital
 
Token03
Token03Token03
Token03
 
Strings
StringsStrings
Strings
 
Devcommerce 2016: Migração plataforma Magazine Luiza e seu laboratório de in...
Devcommerce 2016: Migração plataforma Magazine Luiza e seu  laboratório de in...Devcommerce 2016: Migração plataforma Magazine Luiza e seu  laboratório de in...
Devcommerce 2016: Migração plataforma Magazine Luiza e seu laboratório de in...
 

Similar to 10. Introduction to Datastructure

Data structure and algorithm using java
Data structure and algorithm using javaData structure and algorithm using java
Data structure and algorithm using javaNarayan Sau
 
DSJ_Unit I & II.pdf
DSJ_Unit I & II.pdfDSJ_Unit I & II.pdf
DSJ_Unit I & II.pdfArumugam90
 
Array sorting
Array sortingArray sorting
Array sortingALI RAZA
 
316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasex316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasexabhaysonone0
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsJulie Iskander
 
Data Structures in C
Data Structures in CData Structures in C
Data Structures in CJabs6
 
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...DrkhanchanaR
 
Data structure and algorithm.
Data structure and algorithm. Data structure and algorithm.
Data structure and algorithm. Abdul salam
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)jehan1987
 
Unit 2 linear data structures
Unit 2   linear data structuresUnit 2   linear data structures
Unit 2 linear data structuresSenthil Murugan
 
Data structure and algorithm All in One
Data structure and algorithm All in OneData structure and algorithm All in One
Data structure and algorithm All in Onejehan1987
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTSwapnil Mishra
 
DATA STRUCTURES unit 1.pptx
DATA STRUCTURES unit 1.pptxDATA STRUCTURES unit 1.pptx
DATA STRUCTURES unit 1.pptxShivamKrPathak
 
Radix and Merge Sort
Radix and Merge SortRadix and Merge Sort
Radix and Merge SortGelo Maribbay
 

Similar to 10. Introduction to Datastructure (20)

Data structure and algorithm using java
Data structure and algorithm using javaData structure and algorithm using java
Data structure and algorithm using java
 
lecture 01.1.ppt
lecture 01.1.pptlecture 01.1.ppt
lecture 01.1.ppt
 
DSJ_Unit I & II.pdf
DSJ_Unit I & II.pdfDSJ_Unit I & II.pdf
DSJ_Unit I & II.pdf
 
Searching Algorithms
Searching AlgorithmsSearching Algorithms
Searching Algorithms
 
Array sorting
Array sortingArray sorting
Array sorting
 
316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasex316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasex
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Data Structures in C
Data Structures in CData Structures in C
Data Structures in C
 
Data Structures 6
Data Structures 6Data Structures 6
Data Structures 6
 
DAA Notes.pdf
DAA Notes.pdfDAA Notes.pdf
DAA Notes.pdf
 
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
 
Data structure and algorithm.
Data structure and algorithm. Data structure and algorithm.
Data structure and algorithm.
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)
 
Unit 2 linear data structures
Unit 2   linear data structuresUnit 2   linear data structures
Unit 2 linear data structures
 
Data structure and algorithm All in One
Data structure and algorithm All in OneData structure and algorithm All in One
Data structure and algorithm All in One
 
Complexity
ComplexityComplexity
Complexity
 
ch11.ppt
ch11.pptch11.ppt
ch11.ppt
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGEST
 
DATA STRUCTURES unit 1.pptx
DATA STRUCTURES unit 1.pptxDATA STRUCTURES unit 1.pptx
DATA STRUCTURES unit 1.pptx
 
Radix and Merge Sort
Radix and Merge SortRadix and Merge Sort
Radix and Merge Sort
 

More from Nilesh Dalvi

Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++Nilesh Dalvi
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator OverloadingNilesh Dalvi
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructorsNilesh Dalvi
 
Classes and objects
Classes and objectsClasses and objects
Classes and objectsNilesh Dalvi
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cppNilesh Dalvi
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops conceptsNilesh Dalvi
 

More from Nilesh Dalvi (9)

2. Basics of Java
2. Basics of Java2. Basics of Java
2. Basics of Java
 
Templates
TemplatesTemplates
Templates
 
File handling
File handlingFile handling
File handling
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
 

Recently uploaded

ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
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
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
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
 

Recently uploaded (20)

ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
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
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
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...
 

10. Introduction to Datastructure

  • 1. Introduction to Algorithms By Nilesh Dalvi Lecturer, Patkar-Varde College.Lecturer, Patkar-Varde College. http://www.slideshare.net/nileshdalvi01 Java and DataJava and Data StructuresStructures
  • 2. Algorithm The algorithm is defined as the a collection of unambiguous instructions occurring in some specific sequence and such an algorithm should produce output for given set of input in finite amount of time. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 3. Algorithm • write an algorithm to count the sum of n numbers Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm sum (1, n) { //Problem Desc: Algorithm for finding sum of n numbers //Input: 1 to n numbers //Output: Sum of n numbers result := 0; for i:= 1 to n do i:= i + 1 result := result + i; }
  • 4. Algorithm • write an algorithm to check whether the given no is even or odd. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm EvenOddTest(val) { //Problem Desc: Algorithm for checking whether the given no is even or odd. //Input: 1 to n number //Output: Even or odd number if(val % 2 == 0) write("No is even"); esle write ("No is odd"); }
  • 5. Algorithm • write an algorithm for sorting the given elements Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm Sort (a, n) { //Problem Desc: Algorithm for sorting the elements. //Input: An array //Output: Sorted array for i:=1 to n do { for j:= i +1 to n-1 do { if(a[i]) > a[j]) then { temp := a[i]; a[i] := a[j]; a[j] := temp; } } write("List is sorted!"); } }
  • 6. Algorithm • write an algorithm for calculating factorial of n numbers Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm factCalc (n) { //Problem Desc: For calculating factorial of given no //Input: Number //Output: Factorial of given number if n := 1 then return 1; else return n * factCalc(n - 1); }
  • 7. Algorithm • write an algorithm for multiply two matrices Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm mulMatrix (A, B, n) { //Problem Desc: Multilpy two matrices //Input: Matrix A and Matrix B //Output: Matrix C for i := 1 to n do for j := 1 to n do C[i][j] := 0; for k := 1 to n do C[i][j] := C[i][j] + A[i][k] * B[k][j]; }
  • 8. Fundamentals of analysis of algorithms • The efficiency of an algorithm can be decided by measuring the performance of an algorithm. • We can measure the performance of an algorithm by computing two factors – Amount of time required by an algorithm to execute (time complexity) – Amount of storage required by an algorithm (space complexity) Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 9. Space Complexity • Space complexity can be defined as amount of memory required by an algorithm to run. • To compute space complexity we use two factors : constant space and variable space • Constant space includes instructions, variables and constants • Variable space includes dynamic allocations, function recursion. • Space requirement, s(p) = C + sp • sp is the space dependent upon instance characteristics. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 10. Time Complexity • The time complexity of an algorithm is the amount of computer time required by an algorithm to run complete the task. • The time complexity, T(p), taken by a program p is the sum of the compile time and the run time. • Total Time, T(p) = compile time + run (execution) time Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 11. Asymptotic Notations: • To choose the best algorithm, we need to check efficiency of each algorithm. • Efficiency can be measured by computing space and time complexity. • So, Asymptotic notation is a shorthand way to represent the time complexity. • Using asymptotic notations we can give time complexity as “fastest possible”, “slowest possible” or “average time”. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 12. Big Oh Notation: • Denoted by ‘O’ • Method if representing upper time of representing the upper bound of algorithms running time. • Using big Oh notation we can give longest amount of time taken by the algorithm to complete. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 13. Omega Notation: • Denoted by ‘Ω’ • It is used to represent the lower bound of algorithm running time. • Using omega (Ω) notation we can denote shortest amount of time taken by algorithm. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 14. Theta Notation: • Denoted by ‘Θ’ • By this method the running time is between upper bound and lower bound. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 15. Data Structure • Data may be organized in many different ways. • A data structure is a arrangement of data in a computer memory or on a disk. • The logical or mathematical model of a particular organization of data is called data structure. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 16. Data Structure Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 17. Data Structure Operation Data appearing in data structures are processed by means of operations. Operations are: •Traversing: Accessing each record exactly once so that certain items in the record may be processed. •Searching: Finding the location of the record with a given key value, or finding the locations of all records which satisfy one or more conditions. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 18. Data Structure Operation • Inserting: Adding the new record to the structure. • Deleting: Removing a record from the structure. Special operations: • Sorting: Arranging the records in some logical order • Merging: Combining the records in two-different sorted files into a single-sorted file. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 19. Linear 1. Array: 2. Stack 3. Queue 4. Linked List Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 20. Array • An array is a collection of homogeneous type of data elements. • An array is consisting of a collection of elements . • Operation Performed On Array: 1. Traversing 2. Search 3. Insertion 4. Deletion 5. Sorting 6. Merging Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). 1 2 3 4 5 Representation of array
  • 21. Stack • A Stack is a list of elements in which an element may be inserted or deleted at one end which is known as TOP of the stack. • Operation Performed On Array: 1. Push: add an element in stack 2. Pop: remove an element in stack 3. Peek :Current processed element Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). a b c TOP
  • 22. Queue • A queue is a linear list of element in which insertion can be done at one end which is known as REAR and deletion can be done which is known as FRONT. • Operation: 1. Insertion : add a new element in queue 2. Deletion: Removing an element in queue Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 24. Linked List • A Linked list is a linear collection of data elements . • It has two part one is info and other is link part. • info part gives information and link part is address of next node • Operation: 1. Traversing 2. Searching 3. Insertion 4. Deletion Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 25. Non-Linear 1. Graph 2. Tree 3. Table 4. Set Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 26. Graph • A graph is a collection of sets V and E where V is a finite non-empty set of vertices and E is finite non- empty set of edges. • Vertices – node in graph • Edges – Two adjacent nodes are joined by edges. • Graph G = {V, E} • Operation: 1. Insertion 2. Deletion 3. Searching Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 27. Tree • Tree is a finite set of one or more nodes such that – There is a specially designed node called root. – The remaining nodes are partitioned into n>=0 disjoint sets T1, T2, T3, …., Tn are called the sub-trees of the Root. • Operation: 1. Insertion 2. Deletion 3. Searching Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 28. Tables • This is kind of data structure plays an important role in information retrieval. • Types of tables: – Rectangular – Jagged – Inverted – Hash • Operation: 1. Insertion 2. Deletion 3. Searching Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Key Value 0 “Abc” 1 “Pqr”
  • 29. Sets • Heap is a complete binary tree Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 30. Q & A