SlideShare a Scribd company logo
SKNSITS,Lonavala
Sub:FDS(210242) S.E(CE)(2019 Course)
Unit I
“Introduction to Algorithm &
Data Structure”
Prepared By
Prof. Ravishankar C.Bhaganagare
(Assistant Professor)
Department Of Computer Engg.
Academic Year 2022-2023
.
Introduction: From Problem to Program (Problem, Solution,
Algorithm, Data Structure and Program).
Data Structures: Data, Information, Knowledge, and Data structure,
Abstract Data Types (ADT), Data Structure Classification (Linear and
Static and Dynamic, Persistent and Ephemeral data
Non-linear,
structures)
Algorithms: Problem Solving, Introduction to algorithm,
Characteristics of algorithm, Algorithm design tools: Pseudo-code and
flowchart.
Complexity of algorithm: Space complexity, Time complexity,
Asymptotic notation- Big-O, Theta and Omega, finding complexity
using step count method, Analysis of programming constructs-Linear,
Quadratic, Cubic, Logarithmic.
Algorithmic Strategies: Introduction to algorithm design strategies-
Divide and Conquer, and Greedy strategy.
SYLLABUS
INTRODUCTION
Computer : A programmable device that can store, retrieve,
and process data.(Combination of H/w & S/w )
Hardware : things which we can touch.
Software : things which we cannt touch.(Can only see)
Programming: A programming language is a set of
commands, instructions, and other syntax use to create a
software program.
Data : Information in a form a computer can use
Information : Any knowledge that can be communicated
Introduction
Data type : The specification of how information is represented
in the computer as data and the set of operations that can be
applied to it Computer
Computer program : Data type specifications and instructions
for carrying out operations that are used by a computer to solve
a problem
Introduction
Machine language : The language, made up of
binarycoded instructions, that is used directly by the
computer
Assembly language : A low-level programming language
in which a mnemonic is used to represent each of the
machine language instructions for a particular computer
Assembler : A program that translates an assembly
language program into machine code
Introduction
Source code : Data type specifications and instructions
written in a high-level programming language
Object code : A machine language version of source
code.
Introduction
Compiler : A program that translates a program written
in a high-level language into machine code
DATA
STRUCTURE
DATA STRUCTURE
Data Structure is a way to store and
organize data so that it can be used efficiently.
Data :
“Data is nothing but collection of information i.e.
facts or figures.”
Data Object :
of storage that
“Data object is a region
contains a value or group of value”
NEED OF DATA STRUCTURE
1. Stores huge data
2. Stores data in systematic way
3. Retains logical relationship
4. Provides various structure
5. Static and dynamic formats
6. Better algorithms
ABSTRACT DATA TYPE
ADT :
“Abstract data types are mathematical models of a set
of data values or information that share similar behavior or qualities and
that can be specified and identified independent of specific
implementations. Abstract data types, or ADTs, are typically used in
algorithms.”
Another definition ofADT is
ADT is set of D, F andA.
D – domain = Data object
F – function = set of operation which cannt carried out on data object.
A– axioms = Properties and rule of the operation
TYPES OF DATA STRUCTURE
There are two types :
1. Primitives data structure
2. Non-primitive data structure
TYPES OF DATA STRUCTURE
1. Primitives data structure :
“Primitive data structures are those which are predefined way of
storing data by the system. ”
e.g. int, char, float etc
2. Non-primitive data structure :
“The data types that are derived from primary data types are known
as non-Primitive data types. These datatype are used to store group of
values.”
e.g. struct, array, linklist, stack, tree , graph etc.
Linear and Non-Linear Data
Structure
1. Linear Data Strucute :
“Linear data structuretraverses the data elements
sequentially, in which only one data element can directly be
reached”
Ex: Arrays, Linked Lists, stack, queue.
2. Non-Linear Data Strucute :
“Every data item is attached to several other data items in a
way that is specific for reflecting relationships.”
Ex: Graph , Tree
Linear vs Non-Linear Data
Structure
Static and Dynamic
Data Structure
1. Static data strucure :
“A static data structure is an organization or collection
of data in memory that is fixed in size.”
Ex: Arrays
2. Dynamic Data Strucute :
“ In Dynamic data structure the size of the structure in not
fixed and can be modified during the operations performed on it”
Ex: Linked list
Persistent and Ephemeral
Data Structure
1. Persistent data strucure :
“A persistent data structure is a data structure that
always preserves the previous version of itself when it is
modified..”
Ex: Linked list, tree
2. Ephemeral Data Strucute :
“ An ephemeral data structure is one of which only one
version is available at a time(it does not preserve previous
version).”
Ex: RAM , Cache memory
Relationship among Data, Data
Structure and Algorithms
Data is considered as set of facts and figures or data is value of
group of value which is in particular format.
Data structure is method of gathering as well as organizing data
in such manner that several operation can be performed
Problem is defined as a situation or condition which need to
solve to achieve the goals
Algorithm is set of ordered instruction which are written in
simple english language.
ALGORITHM
ALGORITHM – PROBLEM SOLVING
COMPUTER :
“Computer is multi purpose Electronic Machine which is
used for storing , organizing and processing data by set of
program
Problem :
“Problem is defined as situation or condition which needs
to solve to achive goal”
Steps in Problem Solving :
1. Define the problem
2. Data gathering
3. Decide effective solution
4. Implement and evaluate the solution
5. Review the result.
PROBLEM SOLVING TECHNIQUES
There are two types :
1. Algorithmic
2. Flowchart
Algorithms is set of instructions which are writeen in simple
english language.
Flowchart is graphical representation of the algorithms.
Some other Problem Solving
Techniques
1. Trial and error techniques
2. Divide and conquer techniques
3. Merging solution
4. The building block approach
5. Brain storming techniques
INTRODUCTION OF ALGORITHMS
DEFINITION :
“An algorithm is defined as a step-by-step procedure or method for
solving a problem by a computer in a finite number of steps.”
From the data structure point of view, following are some important
categories of algorithms −
Search − Algorithm to search an item in a data structure.
Sort − Algorithm to sort items in a certain order.
Insert − Algorithm to insert item in a data structure.
Update − Algorithm to update an existing item in a data structure.
Delete − Algorithm to delete an existing item from a data structure.
CHARACTRISTICS OF ALGORITHM
1.Unambiguous − Algorithm should be clear and unambiguous. Each of
its steps (or phases), and their inputs/outputs should be clear and must
lead to only one meaning.
2. Input −An algorithm should have 0 or more well-defined inputs.
3.Output −An algorithm should have 1 or more well-defined outputs,
and should match the desired output.
4. Finiteness −Algorithms must terminate after a finite number of steps.
5. Feasibility − Should be feasible with the available resources.
6.Independent −An algorithm should have step-by-step directions,
which should be independent of any programming code.
EXAMPLE OF ALGORITHM
Example
Let's try to learn algorithm-writing by using an example.
Problem − Design an algorithm to add two numbers and display the result.
Step 1 − START
Step 2 − declare three integers a, b & c
Step 3 − define values of a & b
Step 4 − add values of a & b
Step 5 − store output of step 4 to c
Step 6 − print c
Step 7 − STOP
ALGORITHM DESIGN TOOL
• There can be two tools :
1. Flowchart
2. Pseudo Code
Flowchart :
“ Flowchart is graphical representation of the algorithms”
Pseudo Code :
“It is simply an implementation of an algorithm in the form of
annotations and informative text written in plain English.
Prof. Anand Gharu
FLOWCHART
Symbol used in Flowchart :
8.unit-1-fds-2022-23.pptx
8.unit-1-fds-2022-23.pptx
EXAMPLE OF FLOWCHART
EXAMPLE FOR ALGORITH & FLOWCHART
Step1: Start
Step2: Initialize the count variable to zero
Step3: Initialize the sum variable to zero
Step4: Read a number say x
Step 5:Add 1 to the number in the count variable
Step6:Add the number x to the sum variable.
Step7: Is the count variable in the memory greater than
If
50? If yes, display the sum: go to step 8.
No, Repeat from step 4
Step8: Stop
Design an algorithm and flowchart to input
fifty numbers and calculate their sum.
WRITE A PROGRAM FOR ADDING 10 NUMBERS
WRITE A PROGRAM TO FIND FACTORIAL OF
NUMBER
DIFFERENT APPROCHES TO DESIGN ALGORITHMS
Types of approach :
1. Top down approach
2. Bottom up approach
TOP DOWN APPROACH BOTTOM UP APPROACH
1. Larger problem divided into smaller Smaller pieces are combined together
2. Execution Start from top to down Execution start from bottom to top
3. C is top down approach language C++ is bottom up approach language
4. Main() is written at beginning Main() is written at end of program
Complexity of
Algorithms
ALGORITHM ANALYSIS
• A Priori Analysis − This is a theoretical analysis of an algorithm.
Efficiency of an algorithm is measured by assuming that all other
factors, for example, processor speed, are constant and have no
effect on the implementation.
• A Posterior Analysis − This is an empirical analysis of an
algorithm. The selected algorithm is implemented using
programming language. This is then executed on target computer
machine. In this analysis, actual statistics like running time and space
required, are collected.
Prof. Anand Gharu
CASES OF ANALYSIS ALGORITHMS
.
There are 3 types
1. Worst case
2. Best case
3. Average case
Best Case − Minimum time required for program execution.
Average Case −Average time required for program execution.
Worst Case − Maximum time required for program execution
Standard measure of efficiency
There are two important complexity measures:
1. Time complexity
2. Space complexity
Time complexity :
“The time which is required for analysis of given problem
of particular size is known as time complexity”
Space complexity :
“The amount of computer memory required tp solve the
given problem of particular size is called as space complexity”
Time efficiency - a measure of amount of time for an algorithm to execute.
Space efficiency - a measure of the amount of memory needed for an algorithm to
execute.
8.unit-1-fds-2022-23.pptx
Asymptotic notations
Asymptotic Notations are languages that allow us to
analyze an algorithm's running time by identifying its
behavior as the input size for the algorithm increases. This is
also known as an algorithm's growth rate
Asymptotic Notation gives us the ability to answer
these questions.
Following are the commonly used asymptotic notations
to calculate the running time complexity of an
algorithm.
1. Ο Notation
2. Ω Notation
3. θ Notation
BIG – oh NOTATION
Big Oh Notation, Ο
The notation Ο(n) is the formal way to express the upper
bound of an algorithm's running time. It measures the worst
case time complexity or the longest amount of time an
algorithm can possibly take to complete.
Omega NOTATION
Omega Notation, Ω
The notation Ω(n) is the formal way to express the lower
bound of an algorithm's running time. It measures the best
case time complexity or the best amount of time an
algorithm can possibly take to comp
Theta NOTATION
Theta Notation, θ
The notation θ(n) is the formal way to express both the
lower bound and the upper bound of an algorithm's running
time. It is represented as follows −
Common Asymptotic Notation
Analysis of Programming Construct
Algorithmic
Strategies
ALGORITHMIC STRATEGIES
Algorithm design strategies are the general approaches used to
develop efficient solution to problem.
Algorithm Strategies are :
1. Divide and conquer
2. Merge sort
3. Recursive algorithm
4. Backtracking algorithms
5. Heuristic algorithms
6. Dynamic Programming algorithm
DIVIDE AND CONQUER
In divide and conquer approach, the problem in hand, is divided into
smaller sub-problems and then each problem is solved independently.
When we keep on dividing the subproblems into even smaller sub-
problems, we may eventually reach a stage where no more division is
possible. Those "atomic" smallest possible sub-problem (fractions) are
solved. The solution of all sub-problems is finally merged in order to
obtain the solution of an original problem.
DIVIDE AND CONQUER
Operation for strategy :
Divide – Break the problem into subproblem of same type
Conquer – Recursively solve these sub problem
Combine – Combine the solution of sub problem
are based on divide and conquer
Following algorithms
strategies :
1. Merge sort
2. Binary search
3. Quick sort
4. Closest pair
5. Tower of Hanoi
DIVIDE AND CONQUER
1. Merge sort :
Merge Sort is a Divide and Conquer algorithm. It divides input array in
two halves, calls itself for the two halves and then merges the two sorted
halves. The merge() function is used for merging two halves. The
merge(arr, l, m, r) is key process that assumes that arr[l..m] and
arr[m+1..r] are sorted and merges the two sorted sub-arrays into one.
DIVIDE AND CONQUER
2. Tower of Hanoi :
Tower of Hanoi is a mathematical puzzle where we have three rods and n
disks. The objective of the puzzle is to move the entire stack to another
rod, obeying the following simple rules:
1) Only one disk can be moved at a time.
2)Each move consists of taking the upper disk from one of the stacks and
placing it on top of another stack i.e. a disk can only be moved if it is the
uppermost disk on a stack.
3) No disk may be placed on top of a smaller disk.
DIVIDE AND CONQUER
2. Tower of Hanoi : Example
GREEDY STRATEGIES
Greedy algorithm :
An algorithm is designed to achieve optimum solution for a given
problem. In greedy algorithm approach, decisions are made from the
given solution domain. As being greedy, the closest solution that seems
to provide an optimum solution is chosen.
Example of greedy strategy :
1. Travelling Salesman Problem
2. Prim's Minimal Spanning Tree Algorithm
3. Kruskal's Minimal Spanning Tree Algorithm
4. Dijkstra's Minimal Spanning Tree Algorithm
5. Knapsack Problem
6. Job Scheduling Problem
GREEDY STRATEGIES
1. Minimum Spanning tree (Prims or Kruskal’s algorithms)
The cost of the spanning tree is the sum of the weights of all the edges
in the tree. There can be many spanning trees. Minimum spanning tree is
the spanning tree where the cost is minimum among all the spanning
trees. There also can be many minimum spanning trees.
GREEDY STRATEGIES
1. Kruskal’s algorithms :
Kruskal’s Algorithm builds the spanning tree by adding edges one by
one into a growing spanning tree. Kruskal's algorithm follows greedy
approach as in each iteration it finds an edge which has least weight and
add it to the growing spanning tree.
Algorithm Steps :
Sort the graph edges with respect to their weights.
Start adding edges to the MST from the edge with the smallest weight
until the edge of the largest weight.
Only add edges which doesn't form a cycle , edges which connect only
disconnected components.
GREEDY STRATEGIES
2. Kruskal’s algorithms : Example
.
GREEDY STRATEGIES
2. Kruskal’s algorithms : Example
.
GREEDY STRATEGIES
2. Prims algorithm: Prim’s Algorithm also use Greedy approach to find
the minimum spanning tree. In Prim’s Algorithm we grow the spanning
tree from a starting position. Unlike an edge in Kruskal's, we
add vertex to the growing spanning tree in Prim's.
Algorithm Steps:
1. Initialize the minimum spanning tree with a vertex chosen at random.
2.Find all the edges that connect the tree to new vertices, find the
minimum and add it to the tree.
3. Keep repeating step 2 until we get a minimum spanning tree.
GREEDY STRATEGIES
2. Prims algorithm: Example
GREEDY STRATEGIES
2. Prims algorithm: Example

More Related Content

PPTX
Library Management System.powerpoint.pptx
PDF
Project proposal of Library Management System.
PPTX
SPM_UNIT-1(1).pptx
PPTX
CRYPTOGRAPHY & NETWORK SECURITY - unit 1
PPT
SEARCHING AND SORTING ALGORITHMS
PDF
Expert systems Artificial Intelligence
PDF
Algorithms Lecture 6: Searching Algorithms
PPTX
MS EXCEL PPT PRESENTATION
Library Management System.powerpoint.pptx
Project proposal of Library Management System.
SPM_UNIT-1(1).pptx
CRYPTOGRAPHY & NETWORK SECURITY - unit 1
SEARCHING AND SORTING ALGORITHMS
Expert systems Artificial Intelligence
Algorithms Lecture 6: Searching Algorithms
MS EXCEL PPT PRESENTATION

What's hot (20)

PPTX
Searching and sorting
PPTX
PDF
Binary Search - Design & Analysis of Algorithms
PPTX
trees in data structure
PPTX
Binary Tree in Data Structure
PPTX
String
PPTX
Priority Queue in Data Structure
PPTX
Binary Search Algorithm.pptx
PPTX
Introduction to data structure ppt
PDF
Lecture notes data structures tree
PPTX
STACKS AND QUEUES.pptx
PPTX
Quick Sort
PPTX
Search Algorithms in AI.pptx
PPTX
sorting and its types
PPTX
Solving recurrences
PPTX
Data Structure and Algorithms Merge Sort
PDF
10. funtions and closures IN SWIFT PROGRAMMING
PPT
Hashing
PPTX
Tree - Data Structure
PDF
Searching and Sorting Techniques in Data Structure
Searching and sorting
Binary Search - Design & Analysis of Algorithms
trees in data structure
Binary Tree in Data Structure
String
Priority Queue in Data Structure
Binary Search Algorithm.pptx
Introduction to data structure ppt
Lecture notes data structures tree
STACKS AND QUEUES.pptx
Quick Sort
Search Algorithms in AI.pptx
sorting and its types
Solving recurrences
Data Structure and Algorithms Merge Sort
10. funtions and closures IN SWIFT PROGRAMMING
Hashing
Tree - Data Structure
Searching and Sorting Techniques in Data Structure
Ad

Similar to 8.unit-1-fds-2022-23.pptx (20)

PDF
Introduction to data structure and algorithm
DOCX
Data structure and algorithm.
PPTX
Lecture 1 and 2
DOCX
3rd-Sem_CSE_Data-Structures and Applications.docx
PPTX
Chapter 1- IT.pptx
PPT
assignment character education assignment
PPTX
Chapter 1 - Introduction to data structure.pptx
PPT
algo 1.ppt
PDF
Data structure and Alogorithm analysis unit one
PPTX
EE-232-LEC-01 Data_structures.pptx
PPTX
Lecture 1.pptx
PPTX
PPTX
1-Introduction to Data Structures beginner.pptx
PPTX
FALLSEM2024-25_BSTS301P_SS_VL2024250100685_2024-07-26_Reference-Material-I.pptx
PDF
Introduction to Data Structure
PPTX
data structures and its importance
DOCX
Data Structure Notes unit 1.docx
PDF
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
PPTX
UNIT-1.pptx python for engineering first year students
Introduction to data structure and algorithm
Data structure and algorithm.
Lecture 1 and 2
3rd-Sem_CSE_Data-Structures and Applications.docx
Chapter 1- IT.pptx
assignment character education assignment
Chapter 1 - Introduction to data structure.pptx
algo 1.ppt
Data structure and Alogorithm analysis unit one
EE-232-LEC-01 Data_structures.pptx
Lecture 1.pptx
1-Introduction to Data Structures beginner.pptx
FALLSEM2024-25_BSTS301P_SS_VL2024250100685_2024-07-26_Reference-Material-I.pptx
Introduction to Data Structure
data structures and its importance
Data Structure Notes unit 1.docx
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
UNIT-1.pptx python for engineering first year students
Ad

Recently uploaded (20)

PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
OOP with Java - Java Introduction (Basics)
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
anatomy of limbus and anterior chamber .pptx
PPTX
“Next-Gen AI: Trends Reshaping Our World”
PPTX
Practice Questions on recent development part 1.pptx
PDF
composite construction of structures.pdf
PPT
Project quality management in manufacturing
PPTX
Road Safety tips for School Kids by a k maurya.pptx
PPTX
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
AgentX UiPath Community Webinar series - Delhi
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
PPTX
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
Structs to JSON How Go Powers REST APIs.pdf
OOP with Java - Java Introduction (Basics)
Embodied AI: Ushering in the Next Era of Intelligent Systems
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
anatomy of limbus and anterior chamber .pptx
“Next-Gen AI: Trends Reshaping Our World”
Practice Questions on recent development part 1.pptx
composite construction of structures.pdf
Project quality management in manufacturing
Road Safety tips for School Kids by a k maurya.pptx
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
bas. eng. economics group 4 presentation 1.pptx
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
AgentX UiPath Community Webinar series - Delhi
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd

8.unit-1-fds-2022-23.pptx

  • 1. SKNSITS,Lonavala Sub:FDS(210242) S.E(CE)(2019 Course) Unit I “Introduction to Algorithm & Data Structure” Prepared By Prof. Ravishankar C.Bhaganagare (Assistant Professor) Department Of Computer Engg. Academic Year 2022-2023 .
  • 2. Introduction: From Problem to Program (Problem, Solution, Algorithm, Data Structure and Program). Data Structures: Data, Information, Knowledge, and Data structure, Abstract Data Types (ADT), Data Structure Classification (Linear and Static and Dynamic, Persistent and Ephemeral data Non-linear, structures) Algorithms: Problem Solving, Introduction to algorithm, Characteristics of algorithm, Algorithm design tools: Pseudo-code and flowchart. Complexity of algorithm: Space complexity, Time complexity, Asymptotic notation- Big-O, Theta and Omega, finding complexity using step count method, Analysis of programming constructs-Linear, Quadratic, Cubic, Logarithmic. Algorithmic Strategies: Introduction to algorithm design strategies- Divide and Conquer, and Greedy strategy. SYLLABUS
  • 4. Computer : A programmable device that can store, retrieve, and process data.(Combination of H/w & S/w ) Hardware : things which we can touch. Software : things which we cannt touch.(Can only see) Programming: A programming language is a set of commands, instructions, and other syntax use to create a software program. Data : Information in a form a computer can use Information : Any knowledge that can be communicated Introduction
  • 5. Data type : The specification of how information is represented in the computer as data and the set of operations that can be applied to it Computer Computer program : Data type specifications and instructions for carrying out operations that are used by a computer to solve a problem Introduction
  • 6. Machine language : The language, made up of binarycoded instructions, that is used directly by the computer Assembly language : A low-level programming language in which a mnemonic is used to represent each of the machine language instructions for a particular computer Assembler : A program that translates an assembly language program into machine code Introduction
  • 7. Source code : Data type specifications and instructions written in a high-level programming language Object code : A machine language version of source code. Introduction Compiler : A program that translates a program written in a high-level language into machine code
  • 9. DATA STRUCTURE Data Structure is a way to store and organize data so that it can be used efficiently. Data : “Data is nothing but collection of information i.e. facts or figures.” Data Object : of storage that “Data object is a region contains a value or group of value”
  • 10. NEED OF DATA STRUCTURE 1. Stores huge data 2. Stores data in systematic way 3. Retains logical relationship 4. Provides various structure 5. Static and dynamic formats 6. Better algorithms
  • 11. ABSTRACT DATA TYPE ADT : “Abstract data types are mathematical models of a set of data values or information that share similar behavior or qualities and that can be specified and identified independent of specific implementations. Abstract data types, or ADTs, are typically used in algorithms.” Another definition ofADT is ADT is set of D, F andA. D – domain = Data object F – function = set of operation which cannt carried out on data object. A– axioms = Properties and rule of the operation
  • 12. TYPES OF DATA STRUCTURE There are two types : 1. Primitives data structure 2. Non-primitive data structure
  • 13. TYPES OF DATA STRUCTURE 1. Primitives data structure : “Primitive data structures are those which are predefined way of storing data by the system. ” e.g. int, char, float etc 2. Non-primitive data structure : “The data types that are derived from primary data types are known as non-Primitive data types. These datatype are used to store group of values.” e.g. struct, array, linklist, stack, tree , graph etc.
  • 14. Linear and Non-Linear Data Structure 1. Linear Data Strucute : “Linear data structuretraverses the data elements sequentially, in which only one data element can directly be reached” Ex: Arrays, Linked Lists, stack, queue. 2. Non-Linear Data Strucute : “Every data item is attached to several other data items in a way that is specific for reflecting relationships.” Ex: Graph , Tree
  • 15. Linear vs Non-Linear Data Structure
  • 16. Static and Dynamic Data Structure 1. Static data strucure : “A static data structure is an organization or collection of data in memory that is fixed in size.” Ex: Arrays 2. Dynamic Data Strucute : “ In Dynamic data structure the size of the structure in not fixed and can be modified during the operations performed on it” Ex: Linked list
  • 17. Persistent and Ephemeral Data Structure 1. Persistent data strucure : “A persistent data structure is a data structure that always preserves the previous version of itself when it is modified..” Ex: Linked list, tree 2. Ephemeral Data Strucute : “ An ephemeral data structure is one of which only one version is available at a time(it does not preserve previous version).” Ex: RAM , Cache memory
  • 18. Relationship among Data, Data Structure and Algorithms Data is considered as set of facts and figures or data is value of group of value which is in particular format. Data structure is method of gathering as well as organizing data in such manner that several operation can be performed Problem is defined as a situation or condition which need to solve to achieve the goals Algorithm is set of ordered instruction which are written in simple english language.
  • 20. ALGORITHM – PROBLEM SOLVING COMPUTER : “Computer is multi purpose Electronic Machine which is used for storing , organizing and processing data by set of program Problem : “Problem is defined as situation or condition which needs to solve to achive goal” Steps in Problem Solving : 1. Define the problem 2. Data gathering 3. Decide effective solution 4. Implement and evaluate the solution 5. Review the result.
  • 21. PROBLEM SOLVING TECHNIQUES There are two types : 1. Algorithmic 2. Flowchart Algorithms is set of instructions which are writeen in simple english language. Flowchart is graphical representation of the algorithms.
  • 22. Some other Problem Solving Techniques 1. Trial and error techniques 2. Divide and conquer techniques 3. Merging solution 4. The building block approach 5. Brain storming techniques
  • 23. INTRODUCTION OF ALGORITHMS DEFINITION : “An algorithm is defined as a step-by-step procedure or method for solving a problem by a computer in a finite number of steps.” From the data structure point of view, following are some important categories of algorithms − Search − Algorithm to search an item in a data structure. Sort − Algorithm to sort items in a certain order. Insert − Algorithm to insert item in a data structure. Update − Algorithm to update an existing item in a data structure. Delete − Algorithm to delete an existing item from a data structure.
  • 24. CHARACTRISTICS OF ALGORITHM 1.Unambiguous − Algorithm should be clear and unambiguous. Each of its steps (or phases), and their inputs/outputs should be clear and must lead to only one meaning. 2. Input −An algorithm should have 0 or more well-defined inputs. 3.Output −An algorithm should have 1 or more well-defined outputs, and should match the desired output. 4. Finiteness −Algorithms must terminate after a finite number of steps. 5. Feasibility − Should be feasible with the available resources. 6.Independent −An algorithm should have step-by-step directions, which should be independent of any programming code.
  • 25. EXAMPLE OF ALGORITHM Example Let's try to learn algorithm-writing by using an example. Problem − Design an algorithm to add two numbers and display the result. Step 1 − START Step 2 − declare three integers a, b & c Step 3 − define values of a & b Step 4 − add values of a & b Step 5 − store output of step 4 to c Step 6 − print c Step 7 − STOP
  • 26. ALGORITHM DESIGN TOOL • There can be two tools : 1. Flowchart 2. Pseudo Code Flowchart : “ Flowchart is graphical representation of the algorithms” Pseudo Code : “It is simply an implementation of an algorithm in the form of annotations and informative text written in plain English. Prof. Anand Gharu
  • 31. EXAMPLE FOR ALGORITH & FLOWCHART Step1: Start Step2: Initialize the count variable to zero Step3: Initialize the sum variable to zero Step4: Read a number say x Step 5:Add 1 to the number in the count variable Step6:Add the number x to the sum variable. Step7: Is the count variable in the memory greater than If 50? If yes, display the sum: go to step 8. No, Repeat from step 4 Step8: Stop
  • 32. Design an algorithm and flowchart to input fifty numbers and calculate their sum.
  • 33. WRITE A PROGRAM FOR ADDING 10 NUMBERS
  • 34. WRITE A PROGRAM TO FIND FACTORIAL OF NUMBER
  • 35. DIFFERENT APPROCHES TO DESIGN ALGORITHMS Types of approach : 1. Top down approach 2. Bottom up approach TOP DOWN APPROACH BOTTOM UP APPROACH 1. Larger problem divided into smaller Smaller pieces are combined together 2. Execution Start from top to down Execution start from bottom to top 3. C is top down approach language C++ is bottom up approach language 4. Main() is written at beginning Main() is written at end of program
  • 37. ALGORITHM ANALYSIS • A Priori Analysis − This is a theoretical analysis of an algorithm. Efficiency of an algorithm is measured by assuming that all other factors, for example, processor speed, are constant and have no effect on the implementation. • A Posterior Analysis − This is an empirical analysis of an algorithm. The selected algorithm is implemented using programming language. This is then executed on target computer machine. In this analysis, actual statistics like running time and space required, are collected. Prof. Anand Gharu
  • 38. CASES OF ANALYSIS ALGORITHMS . There are 3 types 1. Worst case 2. Best case 3. Average case Best Case − Minimum time required for program execution. Average Case −Average time required for program execution. Worst Case − Maximum time required for program execution
  • 39. Standard measure of efficiency There are two important complexity measures: 1. Time complexity 2. Space complexity Time complexity : “The time which is required for analysis of given problem of particular size is known as time complexity” Space complexity : “The amount of computer memory required tp solve the given problem of particular size is called as space complexity” Time efficiency - a measure of amount of time for an algorithm to execute. Space efficiency - a measure of the amount of memory needed for an algorithm to execute.
  • 41. Asymptotic notations Asymptotic Notations are languages that allow us to analyze an algorithm's running time by identifying its behavior as the input size for the algorithm increases. This is also known as an algorithm's growth rate Asymptotic Notation gives us the ability to answer these questions. Following are the commonly used asymptotic notations to calculate the running time complexity of an algorithm. 1. Ο Notation 2. Ω Notation 3. θ Notation
  • 42. BIG – oh NOTATION Big Oh Notation, Ο The notation Ο(n) is the formal way to express the upper bound of an algorithm's running time. It measures the worst case time complexity or the longest amount of time an algorithm can possibly take to complete.
  • 43. Omega NOTATION Omega Notation, Ω The notation Ω(n) is the formal way to express the lower bound of an algorithm's running time. It measures the best case time complexity or the best amount of time an algorithm can possibly take to comp
  • 44. Theta NOTATION Theta Notation, θ The notation θ(n) is the formal way to express both the lower bound and the upper bound of an algorithm's running time. It is represented as follows −
  • 48. ALGORITHMIC STRATEGIES Algorithm design strategies are the general approaches used to develop efficient solution to problem. Algorithm Strategies are : 1. Divide and conquer 2. Merge sort 3. Recursive algorithm 4. Backtracking algorithms 5. Heuristic algorithms 6. Dynamic Programming algorithm
  • 49. DIVIDE AND CONQUER In divide and conquer approach, the problem in hand, is divided into smaller sub-problems and then each problem is solved independently. When we keep on dividing the subproblems into even smaller sub- problems, we may eventually reach a stage where no more division is possible. Those "atomic" smallest possible sub-problem (fractions) are solved. The solution of all sub-problems is finally merged in order to obtain the solution of an original problem.
  • 50. DIVIDE AND CONQUER Operation for strategy : Divide – Break the problem into subproblem of same type Conquer – Recursively solve these sub problem Combine – Combine the solution of sub problem are based on divide and conquer Following algorithms strategies : 1. Merge sort 2. Binary search 3. Quick sort 4. Closest pair 5. Tower of Hanoi
  • 51. DIVIDE AND CONQUER 1. Merge sort : Merge Sort is a Divide and Conquer algorithm. It divides input array in two halves, calls itself for the two halves and then merges the two sorted halves. The merge() function is used for merging two halves. The merge(arr, l, m, r) is key process that assumes that arr[l..m] and arr[m+1..r] are sorted and merges the two sorted sub-arrays into one.
  • 52. DIVIDE AND CONQUER 2. Tower of Hanoi : Tower of Hanoi is a mathematical puzzle where we have three rods and n disks. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules: 1) Only one disk can be moved at a time. 2)Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack. 3) No disk may be placed on top of a smaller disk.
  • 53. DIVIDE AND CONQUER 2. Tower of Hanoi : Example
  • 54. GREEDY STRATEGIES Greedy algorithm : An algorithm is designed to achieve optimum solution for a given problem. In greedy algorithm approach, decisions are made from the given solution domain. As being greedy, the closest solution that seems to provide an optimum solution is chosen. Example of greedy strategy : 1. Travelling Salesman Problem 2. Prim's Minimal Spanning Tree Algorithm 3. Kruskal's Minimal Spanning Tree Algorithm 4. Dijkstra's Minimal Spanning Tree Algorithm 5. Knapsack Problem 6. Job Scheduling Problem
  • 55. GREEDY STRATEGIES 1. Minimum Spanning tree (Prims or Kruskal’s algorithms) The cost of the spanning tree is the sum of the weights of all the edges in the tree. There can be many spanning trees. Minimum spanning tree is the spanning tree where the cost is minimum among all the spanning trees. There also can be many minimum spanning trees.
  • 56. GREEDY STRATEGIES 1. Kruskal’s algorithms : Kruskal’s Algorithm builds the spanning tree by adding edges one by one into a growing spanning tree. Kruskal's algorithm follows greedy approach as in each iteration it finds an edge which has least weight and add it to the growing spanning tree. Algorithm Steps : Sort the graph edges with respect to their weights. Start adding edges to the MST from the edge with the smallest weight until the edge of the largest weight. Only add edges which doesn't form a cycle , edges which connect only disconnected components.
  • 57. GREEDY STRATEGIES 2. Kruskal’s algorithms : Example .
  • 58. GREEDY STRATEGIES 2. Kruskal’s algorithms : Example .
  • 59. GREEDY STRATEGIES 2. Prims algorithm: Prim’s Algorithm also use Greedy approach to find the minimum spanning tree. In Prim’s Algorithm we grow the spanning tree from a starting position. Unlike an edge in Kruskal's, we add vertex to the growing spanning tree in Prim's. Algorithm Steps: 1. Initialize the minimum spanning tree with a vertex chosen at random. 2.Find all the edges that connect the tree to new vertices, find the minimum and add it to the tree. 3. Keep repeating step 2 until we get a minimum spanning tree.
  • 60. GREEDY STRATEGIES 2. Prims algorithm: Example
  • 61. GREEDY STRATEGIES 2. Prims algorithm: Example