SlideShare a Scribd company logo
Algorithmics
COLLEGE OF BUSINESS EDUCATION
What is an Algorithm?
 Let us consider the problem of preparing Chapati.
 To prepare Chapati, we follow the steps given below:
1) Get the frying pan.
2) Get the oil.
a. Do we have oil?
What is an Algorithm?
 i. If yes, put it in the pan.
ii. If no, do we want to buy oil?
1. If yes, then go out and buy.
2. If no, we can terminate.
3) Turn on the stove, etc...
 What we are doing is, for a given problem (preparing chapati), we are providing a step-by step
procedure for solving it.
 An algorithm is the step-by-step unambiguous instructions to solve a given problem or is a finite
sequence of well-defined instructions, typically used to solve a class of specific problems or to
perform a certain computation.
What is an Algorithm?
 An algorithm itself is division of a problem into small steps which are ordered in sequence and easily
understandable.
 Algorithms are very important to the way computers process information, because a computer
program is basically an algorithm that tells computer what specific tasks to perform in what specific
order to accomplish a specific task.
 The same problem can be solved with different methods. So, for solving the same problem, different
algorithms can be designed.
What is an Algorithm?
 Algorithmics is the systematic study of the design and analysis of algorithms.
 It is fundamental and one of the oldest fields of computer science.
 Algorithm analysis is the science of studying the properties of a problem, such as quantifying
resources in time and memory space needed by this algorithm to solve this problem.
Characteristics of an Algorithm.
 An algorithm must possess following characteristics :
i. Finiteness: An algorithm should have finite number of steps and it should end after a finite
time.
ii. Input: An algorithm may have many inputs or no inputs at all.
iii. Output: It should result at least one output.
iv. Definiteness: Each step must be clear, well-defined and precise. There should be no any
ambiguity.
v. Effectiveness: Each step must be simple and should take a finite amount of time.
Ways of presenting an algorithm.
 Descriptions.
 Pseudo codes.
 Flowcharts.
Flowcharts
 Flowchart is a graphical representation of an algorithm.
 Programmers often use it as a program-planning tool to solve a problem.
 It makes use of symbols which are connected among them to indicate the flow of information and
processing.
 The process of drawing a flowchart for an algorithm is known as “flowcharting”.
Basic Symbols used in Flowchart
Designs
1. Terminal: The oval symbol indicates Start, Stop and Halt in a program’s logic flow.
 A pause/halt is generally used in a program logic under some error conditions.
 Terminal is the first and last symbols in the flowchart.
2. Input/Output: A parallelogram denotes any function of input/output type.
 Program instructions that take input from input devices and display output on output devices are
indicated with parallelogram in a flowchart.
3. Processing: A box represents arithmetic instructions.
 All arithmetic processes such as adding, subtracting, multiplication and division are indicated by action or
process symbol.
Basic Symbols used in Flowchart
Designs
4. Decision - Diamond symbol represents a decision point. Decision based operations such as yes/no
question or true/false are indicated by diamond in flowchart.
5. Connectors: Whenever flowchart becomes complex or it spreads over more than one page, it is
useful to use connectors to avoid any confusions. It is represented by a small circle.
6.Flow lines: Flow lines indicate the exact sequence in which instructions are executed.
Arrows represent the direction of flow of control and relationship among different symbols of
flowchart.
Algorithmics,  intro to data structures.pptx
Pseudo code
 Pseudo code is a term which is often used in programming and algorithm based fields.
 It is a methodology that allows the programmer to represent the implementation of an algorithm.
Simply, we can say that it’s the cooked up representation of an algorithm.
 Often at times, algorithms are represented with the help of pseudo codes as they can be interpreted
by programmers no matter what their programming background or knowledge is.
 Pseudo code, as the name suggests, is a false code or a representation of code which can be
understood by even a layman with some school level programming knowledge.
Pseudo code
 Pseudo code: It’s simply an implementation of an algorithm in the form of annotations and
informative text written in plain English.
 It has no syntax like any of the programming language and thus can’t be compiled or interpreted by
the computer.
How to write a Pseudo-code?
1.Arrange the sequence of tasks and write the pseudocode accordingly.
2.Start with the statement of a pseudo code which establishes the main goal or the aim.
Example:
3. The way the if-else, for, while loops are indented in a program, indent the statements likewise, as it
helps to comprehend the decision control and execution mechanism. They also improve the readability
to a great extent.
How to write a Pseudo-code?
How to write a Pseudo-code?
4. Use appropriate naming conventions. The human tendency follows the approach to follow what we
see. If a programmer goes through a pseudo code, his approach will be the same as per it, so the
naming must be simple and distinct.
5. Use appropriate sentence casings, such as CamelCase for methods, upper case for constants and
lower case for variables.
6. Elaborate everything which is going to happen in the actual code. Don’t make the pseudo code
abstract.
How to write a Pseudo-code?
7. Use standard programming structures such as ‘if-then’, ‘for’, ‘while’, ‘cases’ the way we use it in
programming.
8. Check whether all the sections of a pseudo code is complete, finite and clear to understand and
comprehend.
9. Don’t write the pseudo code in a complete programmatic manner. It is necessary to be simple to
understand even for a layman or client, hence don’t incorporate too many technical terms.
Guidelines for Developing an
Algorithm.
 Following guidelines must be followed while developing an algorithm :
 An algorithm will be enclosed by START (or BEGIN) and STOP (or END).
 To accept data from user, generally used statements are INPUT, READ, GET or OBTAIN.
 To display result or any message, generally used statements are PRINT, DISPLAY, or WRITE.
 Generally, COMPUTE or CALCULATE is used while describing mathematical expressions and
based on situation relevant operators can be used.
Example of an Algorithm
Advantages of devising Algorithms
 Designing an algorithm has following advantages :
1. Effective Communication: Since algorithm is written in English like language, it is simple to understand
step-by-step solution of the problems.
2. Easy Debugging: Well-designed algorithm makes debugging easy so that we can identify logical error in the
program.
3. Easy an Efficient Coding: An algorithm acts as a blueprint of a program and helps during program
development.
4. Independent of Programming Language: An algorithm is independent of programming languages and can
be easily coded using any high level language.
Challenges with devising Algorithms
 Developing algorithm for complex problems would be time consuming and difficult to understand.
 Understanding complex logic through algorithms can be very difficult.
Analysis of algorithms.
 In the traditional study of algorithms, there are two main criteria for judging the merits of
algorithms:
1. Correctness: (does the algorithm give solution to the problem in a finite number of steps?)
2. Efficiency: (how much resources (in terms of memory and time) does it take to execute the
algorithm)
Why the Analysis of Algorithms?
 To go from city “A” to city “B”, there can be many ways of accomplishing this: by flight, by bus, by
train and also by bicycle.
 Depending on the availability and convenience, we choose the one that suits us.
 Similarly, in computer science, multiple algorithms are available for solving the same problem (for
example, a sorting problem has many algorithms, like insertion sort, selection sort, quick sort and
many more).
 Algorithm analysis helps us to determine which algorithm is most efficient in terms of time and space
consumed.
Goal of the Analysis of Algorithms
 The goal of the analysis of algorithms is to compare algorithms (or solutions) mainly in terms of
running time but also in terms of other factors (e.g., memory, developer effort, etc.)
What is Running Time Analysis?
 It is the process of determining how processing time increases as the size of the problem (input size)
increases.
 Input size is the number of elements in the input, and depending on the problem type, the input may
be of different types.
What is Rate of Growth?
 The rate at which the running time increases as a function of input is called rate of growth.
 Let us assume that you go to a shop to buy a car and a bicycle. If your friend sees you there and asks
what you are buying, then in general you say buying a car. This is because the cost of the car is high
compared to the cost of the bicycle (approximating the cost of the bicycle to the cost of the car).
What is Rate of Growth?
 As an example, in the case below, n4, 2n2, 100n and 500 are the individual costs of some function
and approximate to n4 since n4 is the highest rate of growth.
Commonly Used Rates of Growth.
Types of Analysis.
 There are three types of analysis:
1. Worst case.
a. Defines the input for which the algorithm takes a long time (slowest time to complete).
b. Input: is the one for which the algorithm runs the slowest.
2. Best case.
c. Defines the input for which the algorithm takes the least time (fastest time to complete).
d. Input : is the one for which the algorithm runs the fastest.
Types of Analysis.
 There are three types of analysis:
3. Average case.
 Provides a prediction about the running time of the algorithm.
 Run the algorithm many times, using many different inputs that come from some distribution that
generates these inputs, compute the total running time (by adding the individual times), and divide
by the number of trials.
 Assumes that the input is random.
Asymptotic Notation.
 Having the expressions for the best, average and worst cases, for all three cases we need to identify the
upper and lower bounds.
 To represent these upper and lower bounds, we need some kind of syntax, and that is the subject of the
following discussion. Let us assume that the given algorithm is represented in the form of function f(n).
 Big-O Notation [Upper Bounding Function]
 This notation gives the tight upper bound of the given function. Generally, it is represented as f(n)
= O(g(n)). That means, at larger values of n, the upper bound of f(n) is g(n).
 That means g(n) gives the maximum rate of growth for f(n) at larger values of n.
Big-O Notation [Upper Bounding Function]
Big-O Notation [Upper Bounding Function]
 Let us see the O–notation with a little more detail. O–notation defined as O(g(n)) = {f(n): there exist positive
constants c and n0 such that 0 ≤ f(n) ≤ cg(n) for all n > n0}.
 g(n) is an asymptotic tight upper bound for f(n).
 Generally we discard lower values of n. That means the rate of growth at lower values of n is not
important.
 In the figure, n0 is the point from which we need to consider the rate of growth for a
given algorithm. Below n0, the rate of growth could be different.
 n0 is called threshold for the given function.
Big-O Visualization.
Note: Analyze the algorithms at larger values of n only. What this means is, below n0 we do not care
about the rate of growth.
Big-O Examples.
Example-1: Find upper bound for f(n) = 3n + 8
Solution: 3n + 8 ≤ 4n, for all n ≥ 8
∴ 3n + 8 = O(n) with c = 4 and n0 = 8
Example-2: Find upper bound for f(n) = n^2 + 1
Solution: n^2 + 1 ≤ 2n^2, for all n ≥ 1
∴ n2 + 1 = O(n2) with c = 2 and n0 = 1
Example-3: Find upper bound for f(n) = n^4 + 100n^2 + 50
Solution: n^4 + 100n^2 + 50 ≤ 2n^4, for all n ≥ 11
∴ n^4 + 100n^2 + 50 = O(n^4 ) with c = 2 and n0 = 11
Quiz
Find upper bound for f(n) = 2n^3 – 2n^2
Omega-Q Notation [Lower Bounding Function]
 Similar to the O discussion, this notation gives the tighter lower bound of the given algorithm and we
represent it as f(n) = Ω(g(n)).
 That means, at larger values of n, the tighter lower bound of f(n) is g(n).
Omega-Q Notation [Lower Bounding Function]
 The Ω notation can be defined as Ω(g(n)) = {f(n): there exist positive constants c and n0 such that 0 ≤
cg(n) ≤ f(n) for all n ≥ n0}.
 g(n) is an asymptotic tight lower bound for f(n). Our objective is to give the largest rate of growth
g(n) which is less than or equal to the given algorithm’s rate of growth f(n).
Theta-Θ Notation [Order Function]
Theta-Θ Notation [Order Function]
 This notation decides whether the upper and lower bounds of a given function (algorithm) are the same.
 The average running time of an algorithm is always between the lower bound and the upper bound. If the
upper bound (O) and lower bound (Ω) give the same result, then the Θ notation will also have the same rate of
growth.
 As an example, let us assume that f(n) = 10n + n is the expression. Then, its tight upper bound g(n) is O(n). The
rate of growth in the best case is g(n) = O(n).
 In this case, the rates of growth in the best case and worst case are the same. As a result, the average case will
also be the same. For a given function (algorithm), if the rates of growth (bounds) for O and Ω are not the
same, then the rate of growth for the Θ case may not be the same.
 In this case, we need to consider all possible time complexities and take the average of those cases.
Theta-Θ Notation [Order Function]
 The Ω notation can be defined as Ω(g(n)) = {f(n): there exist positive constants c and n0 such that 0 ≤
cg(n) ≤ f(n) for all n ≥ n0}.
 g(n) is an asymptotic tight lower bound for f(n). Our objective is to give the largest rate of growth
g(n) which is less than or equal to the given algorithm’s rate of growth f(n).
 NOTE: we generally focus on the upper bound (O) because knowing the lower bound (Ω) of an
algorithm is of no practical importance, and we use the Θ notation if the upper bound (O) and lower
bound (Ω) are the same.
Guidelines for Asymptotic Analysis.
 There are some general rules to help us determine the running time of an algorithm.
Loops: The running time of a loop is, at most, the running time of the statements inside the loop
(including tests) multiplied by the number of iterations.
 Total time = a constant c × n = cn = O(n).
Guidelines for Asymptotic Analysis.
 Nested loops: Analyze from the inside out. Total running time is the product of the sizes of all the
loops.
 Total time = c × n × n = cn^2 = O(n^2).
Guidelines for Asymptotic Analysis.
 Consecutive statements: Add the time complexities of each statement.
 Total time = c0 + c1n + c2n^2 = O(n^2).
Guidelines for Asymptotic Analysis.
 If-then-else statements: Worst-case running time: the test, plus either the then
part or the else part (whichever is the larger).
 Total time = c0 + c1 + (c2 + c3) * n = O(n)
Guidelines for Asymptotic Analysis.
 Logarithmic complexity: An algorithm is O(log n) if it takes a constant time to cut the problem size by a
fraction (usually by ½).
 As an example let us consider the following program:
 If we observe carefully, the value of i is doubling every time. Initially i = 1, in next step i = 2, and in
subsequent steps i = 4,8 and so on.
 Let us assume that the loop is executing some k times. At kth step 2 power k = n, and at (k + 1)th step,
we come out of the loop. Taking logarithm on both sides, gives;
Guidelines for Asymptotic Analysis.
Note: Similarly, for the case below, the worst case rate of growth is O(logn). The same
discussion holds good for the decreasing sequence as well.
Commonly used Logarithms and Summations
Commonly used Logarithms and Summations
Practice questions.
 What is the running time of the following function?
We can define the ‘s’ terms according
to the relation si = si–1 + i. The value
oft’ increases by 1
for each iteration.
The value contained in ‘s’ at the ith
iteration is the sum of the first
‘(‘positive integers. If k is the total
number of iterations taken by the
program, then the while loop
terminates if:
Practice questions.
 Find the complexity of the function given below.
In the above-mentioned function the loop will end, if i power 2 > n T(n) = O( ).
⇒
Practice questions.
 What is the complexity of the program given below:
The complexity of the above function is O(n2logn)
Practice questions.
 What is the complexity of the program given below:
The complexity of the above function is O(nlog2n).
Practice questions.
 What is the complexity of the program given below:
 The complexity of the above function is O(n). Even though the inner loop is bounded by n, due to the
break statement it is executing only once.
Practice questions.
 What is the complexity of the program given below:
Practice questions.
Rank the following functions by order of growth: (n + 1)!, n!, 4n, n × 3n, 3n + n2
+ 20n, , n2 + 200, 20n + 500, 2lgn, n2/3, 1.
Practice questions.
 What is the complexity of the program given below:
Practice questions.
 What is the complexity of the program given below:

More Related Content

Similar to Algorithmics, intro to data structures.pptx (20)

PPTX
Programming C ppt for learning foundations
ssuser65733f
 
PDF
Algorithm Analysis.pdf
NayanChandak1
 
PPTX
Design and Analysis of Algorithm ppt for unit one
ssuserb7c8b8
 
DOCX
Chapter 2(1)
TejaswiB4
 
PPT
Unit 1 python (2021 r)
praveena p
 
PPTX
Unit 1 c programming language Tut and notes
achiver792
 
PPTX
Chp-1 DAA (2).pptx design analysis and algoritham presentation
vaishnavbhavna17
 
PPTX
Cp 111 lecture 2
HafidhyMasoud
 
PPTX
Computer programing 111 lecture 2
ITNet
 
PDF
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
dinesh620610
 
PPT
AOA Week 01.ppt
INAM352782
 
PDF
C Programming Slides for 1st Year Engg students
MysoreYogesh
 
PDF
Introduction to Computer Programming
Prof. Erwin Globio
 
PPTX
Algorithms and flow charts
Chinnu Edwin
 
PPTX
Improving Code Quality Through Effective Review Process
Dr. Syed Hassan Amin
 
PPTX
Module 1 python.pptx
AnuragJoshi813963
 
PPT
UNIT-1-PPTS-DAA_INTRODUCTION_TO_DAA_GH.ppt
sravansonga007
 
PPTX
1.0 Introduction to C programming for all first year courses.pptx
javed Pendhari
 
PPTX
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
RathnaM16
 
PPTX
classVI_Coding_Teacher_Presentation.pptx
ssusere336f4
 
Programming C ppt for learning foundations
ssuser65733f
 
Algorithm Analysis.pdf
NayanChandak1
 
Design and Analysis of Algorithm ppt for unit one
ssuserb7c8b8
 
Chapter 2(1)
TejaswiB4
 
Unit 1 python (2021 r)
praveena p
 
Unit 1 c programming language Tut and notes
achiver792
 
Chp-1 DAA (2).pptx design analysis and algoritham presentation
vaishnavbhavna17
 
Cp 111 lecture 2
HafidhyMasoud
 
Computer programing 111 lecture 2
ITNet
 
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
dinesh620610
 
AOA Week 01.ppt
INAM352782
 
C Programming Slides for 1st Year Engg students
MysoreYogesh
 
Introduction to Computer Programming
Prof. Erwin Globio
 
Algorithms and flow charts
Chinnu Edwin
 
Improving Code Quality Through Effective Review Process
Dr. Syed Hassan Amin
 
Module 1 python.pptx
AnuragJoshi813963
 
UNIT-1-PPTS-DAA_INTRODUCTION_TO_DAA_GH.ppt
sravansonga007
 
1.0 Introduction to C programming for all first year courses.pptx
javed Pendhari
 
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
RathnaM16
 
classVI_Coding_Teacher_Presentation.pptx
ssusere336f4
 

Recently uploaded (20)

PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
July Patch Tuesday
Ivanti
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
July Patch Tuesday
Ivanti
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Ad

Algorithmics, intro to data structures.pptx

  • 2. What is an Algorithm?  Let us consider the problem of preparing Chapati.  To prepare Chapati, we follow the steps given below: 1) Get the frying pan. 2) Get the oil. a. Do we have oil?
  • 3. What is an Algorithm?  i. If yes, put it in the pan. ii. If no, do we want to buy oil? 1. If yes, then go out and buy. 2. If no, we can terminate. 3) Turn on the stove, etc...  What we are doing is, for a given problem (preparing chapati), we are providing a step-by step procedure for solving it.  An algorithm is the step-by-step unambiguous instructions to solve a given problem or is a finite sequence of well-defined instructions, typically used to solve a class of specific problems or to perform a certain computation.
  • 4. What is an Algorithm?  An algorithm itself is division of a problem into small steps which are ordered in sequence and easily understandable.  Algorithms are very important to the way computers process information, because a computer program is basically an algorithm that tells computer what specific tasks to perform in what specific order to accomplish a specific task.  The same problem can be solved with different methods. So, for solving the same problem, different algorithms can be designed.
  • 5. What is an Algorithm?  Algorithmics is the systematic study of the design and analysis of algorithms.  It is fundamental and one of the oldest fields of computer science.  Algorithm analysis is the science of studying the properties of a problem, such as quantifying resources in time and memory space needed by this algorithm to solve this problem.
  • 6. Characteristics of an Algorithm.  An algorithm must possess following characteristics : i. Finiteness: An algorithm should have finite number of steps and it should end after a finite time. ii. Input: An algorithm may have many inputs or no inputs at all. iii. Output: It should result at least one output. iv. Definiteness: Each step must be clear, well-defined and precise. There should be no any ambiguity. v. Effectiveness: Each step must be simple and should take a finite amount of time.
  • 7. Ways of presenting an algorithm.  Descriptions.  Pseudo codes.  Flowcharts.
  • 8. Flowcharts  Flowchart is a graphical representation of an algorithm.  Programmers often use it as a program-planning tool to solve a problem.  It makes use of symbols which are connected among them to indicate the flow of information and processing.  The process of drawing a flowchart for an algorithm is known as “flowcharting”.
  • 9. Basic Symbols used in Flowchart Designs 1. Terminal: The oval symbol indicates Start, Stop and Halt in a program’s logic flow.  A pause/halt is generally used in a program logic under some error conditions.  Terminal is the first and last symbols in the flowchart. 2. Input/Output: A parallelogram denotes any function of input/output type.  Program instructions that take input from input devices and display output on output devices are indicated with parallelogram in a flowchart. 3. Processing: A box represents arithmetic instructions.  All arithmetic processes such as adding, subtracting, multiplication and division are indicated by action or process symbol.
  • 10. Basic Symbols used in Flowchart Designs 4. Decision - Diamond symbol represents a decision point. Decision based operations such as yes/no question or true/false are indicated by diamond in flowchart. 5. Connectors: Whenever flowchart becomes complex or it spreads over more than one page, it is useful to use connectors to avoid any confusions. It is represented by a small circle. 6.Flow lines: Flow lines indicate the exact sequence in which instructions are executed. Arrows represent the direction of flow of control and relationship among different symbols of flowchart.
  • 12. Pseudo code  Pseudo code is a term which is often used in programming and algorithm based fields.  It is a methodology that allows the programmer to represent the implementation of an algorithm. Simply, we can say that it’s the cooked up representation of an algorithm.  Often at times, algorithms are represented with the help of pseudo codes as they can be interpreted by programmers no matter what their programming background or knowledge is.  Pseudo code, as the name suggests, is a false code or a representation of code which can be understood by even a layman with some school level programming knowledge.
  • 13. Pseudo code  Pseudo code: It’s simply an implementation of an algorithm in the form of annotations and informative text written in plain English.  It has no syntax like any of the programming language and thus can’t be compiled or interpreted by the computer.
  • 14. How to write a Pseudo-code? 1.Arrange the sequence of tasks and write the pseudocode accordingly. 2.Start with the statement of a pseudo code which establishes the main goal or the aim. Example: 3. The way the if-else, for, while loops are indented in a program, indent the statements likewise, as it helps to comprehend the decision control and execution mechanism. They also improve the readability to a great extent.
  • 15. How to write a Pseudo-code?
  • 16. How to write a Pseudo-code? 4. Use appropriate naming conventions. The human tendency follows the approach to follow what we see. If a programmer goes through a pseudo code, his approach will be the same as per it, so the naming must be simple and distinct. 5. Use appropriate sentence casings, such as CamelCase for methods, upper case for constants and lower case for variables. 6. Elaborate everything which is going to happen in the actual code. Don’t make the pseudo code abstract.
  • 17. How to write a Pseudo-code? 7. Use standard programming structures such as ‘if-then’, ‘for’, ‘while’, ‘cases’ the way we use it in programming. 8. Check whether all the sections of a pseudo code is complete, finite and clear to understand and comprehend. 9. Don’t write the pseudo code in a complete programmatic manner. It is necessary to be simple to understand even for a layman or client, hence don’t incorporate too many technical terms.
  • 18. Guidelines for Developing an Algorithm.  Following guidelines must be followed while developing an algorithm :  An algorithm will be enclosed by START (or BEGIN) and STOP (or END).  To accept data from user, generally used statements are INPUT, READ, GET or OBTAIN.  To display result or any message, generally used statements are PRINT, DISPLAY, or WRITE.  Generally, COMPUTE or CALCULATE is used while describing mathematical expressions and based on situation relevant operators can be used.
  • 19. Example of an Algorithm
  • 20. Advantages of devising Algorithms  Designing an algorithm has following advantages : 1. Effective Communication: Since algorithm is written in English like language, it is simple to understand step-by-step solution of the problems. 2. Easy Debugging: Well-designed algorithm makes debugging easy so that we can identify logical error in the program. 3. Easy an Efficient Coding: An algorithm acts as a blueprint of a program and helps during program development. 4. Independent of Programming Language: An algorithm is independent of programming languages and can be easily coded using any high level language.
  • 21. Challenges with devising Algorithms  Developing algorithm for complex problems would be time consuming and difficult to understand.  Understanding complex logic through algorithms can be very difficult.
  • 22. Analysis of algorithms.  In the traditional study of algorithms, there are two main criteria for judging the merits of algorithms: 1. Correctness: (does the algorithm give solution to the problem in a finite number of steps?) 2. Efficiency: (how much resources (in terms of memory and time) does it take to execute the algorithm)
  • 23. Why the Analysis of Algorithms?  To go from city “A” to city “B”, there can be many ways of accomplishing this: by flight, by bus, by train and also by bicycle.  Depending on the availability and convenience, we choose the one that suits us.  Similarly, in computer science, multiple algorithms are available for solving the same problem (for example, a sorting problem has many algorithms, like insertion sort, selection sort, quick sort and many more).  Algorithm analysis helps us to determine which algorithm is most efficient in terms of time and space consumed.
  • 24. Goal of the Analysis of Algorithms  The goal of the analysis of algorithms is to compare algorithms (or solutions) mainly in terms of running time but also in terms of other factors (e.g., memory, developer effort, etc.)
  • 25. What is Running Time Analysis?  It is the process of determining how processing time increases as the size of the problem (input size) increases.  Input size is the number of elements in the input, and depending on the problem type, the input may be of different types.
  • 26. What is Rate of Growth?  The rate at which the running time increases as a function of input is called rate of growth.  Let us assume that you go to a shop to buy a car and a bicycle. If your friend sees you there and asks what you are buying, then in general you say buying a car. This is because the cost of the car is high compared to the cost of the bicycle (approximating the cost of the bicycle to the cost of the car).
  • 27. What is Rate of Growth?  As an example, in the case below, n4, 2n2, 100n and 500 are the individual costs of some function and approximate to n4 since n4 is the highest rate of growth.
  • 28. Commonly Used Rates of Growth.
  • 29. Types of Analysis.  There are three types of analysis: 1. Worst case. a. Defines the input for which the algorithm takes a long time (slowest time to complete). b. Input: is the one for which the algorithm runs the slowest. 2. Best case. c. Defines the input for which the algorithm takes the least time (fastest time to complete). d. Input : is the one for which the algorithm runs the fastest.
  • 30. Types of Analysis.  There are three types of analysis: 3. Average case.  Provides a prediction about the running time of the algorithm.  Run the algorithm many times, using many different inputs that come from some distribution that generates these inputs, compute the total running time (by adding the individual times), and divide by the number of trials.  Assumes that the input is random.
  • 31. Asymptotic Notation.  Having the expressions for the best, average and worst cases, for all three cases we need to identify the upper and lower bounds.  To represent these upper and lower bounds, we need some kind of syntax, and that is the subject of the following discussion. Let us assume that the given algorithm is represented in the form of function f(n).  Big-O Notation [Upper Bounding Function]  This notation gives the tight upper bound of the given function. Generally, it is represented as f(n) = O(g(n)). That means, at larger values of n, the upper bound of f(n) is g(n).  That means g(n) gives the maximum rate of growth for f(n) at larger values of n.
  • 32. Big-O Notation [Upper Bounding Function]
  • 33. Big-O Notation [Upper Bounding Function]  Let us see the O–notation with a little more detail. O–notation defined as O(g(n)) = {f(n): there exist positive constants c and n0 such that 0 ≤ f(n) ≤ cg(n) for all n > n0}.  g(n) is an asymptotic tight upper bound for f(n).  Generally we discard lower values of n. That means the rate of growth at lower values of n is not important.  In the figure, n0 is the point from which we need to consider the rate of growth for a given algorithm. Below n0, the rate of growth could be different.  n0 is called threshold for the given function.
  • 34. Big-O Visualization. Note: Analyze the algorithms at larger values of n only. What this means is, below n0 we do not care about the rate of growth.
  • 35. Big-O Examples. Example-1: Find upper bound for f(n) = 3n + 8 Solution: 3n + 8 ≤ 4n, for all n ≥ 8 ∴ 3n + 8 = O(n) with c = 4 and n0 = 8 Example-2: Find upper bound for f(n) = n^2 + 1 Solution: n^2 + 1 ≤ 2n^2, for all n ≥ 1 ∴ n2 + 1 = O(n2) with c = 2 and n0 = 1 Example-3: Find upper bound for f(n) = n^4 + 100n^2 + 50 Solution: n^4 + 100n^2 + 50 ≤ 2n^4, for all n ≥ 11 ∴ n^4 + 100n^2 + 50 = O(n^4 ) with c = 2 and n0 = 11
  • 36. Quiz Find upper bound for f(n) = 2n^3 – 2n^2
  • 37. Omega-Q Notation [Lower Bounding Function]  Similar to the O discussion, this notation gives the tighter lower bound of the given algorithm and we represent it as f(n) = Ω(g(n)).  That means, at larger values of n, the tighter lower bound of f(n) is g(n).
  • 38. Omega-Q Notation [Lower Bounding Function]  The Ω notation can be defined as Ω(g(n)) = {f(n): there exist positive constants c and n0 such that 0 ≤ cg(n) ≤ f(n) for all n ≥ n0}.  g(n) is an asymptotic tight lower bound for f(n). Our objective is to give the largest rate of growth g(n) which is less than or equal to the given algorithm’s rate of growth f(n).
  • 40. Theta-Θ Notation [Order Function]  This notation decides whether the upper and lower bounds of a given function (algorithm) are the same.  The average running time of an algorithm is always between the lower bound and the upper bound. If the upper bound (O) and lower bound (Ω) give the same result, then the Θ notation will also have the same rate of growth.  As an example, let us assume that f(n) = 10n + n is the expression. Then, its tight upper bound g(n) is O(n). The rate of growth in the best case is g(n) = O(n).  In this case, the rates of growth in the best case and worst case are the same. As a result, the average case will also be the same. For a given function (algorithm), if the rates of growth (bounds) for O and Ω are not the same, then the rate of growth for the Θ case may not be the same.  In this case, we need to consider all possible time complexities and take the average of those cases.
  • 41. Theta-Θ Notation [Order Function]  The Ω notation can be defined as Ω(g(n)) = {f(n): there exist positive constants c and n0 such that 0 ≤ cg(n) ≤ f(n) for all n ≥ n0}.  g(n) is an asymptotic tight lower bound for f(n). Our objective is to give the largest rate of growth g(n) which is less than or equal to the given algorithm’s rate of growth f(n).  NOTE: we generally focus on the upper bound (O) because knowing the lower bound (Ω) of an algorithm is of no practical importance, and we use the Θ notation if the upper bound (O) and lower bound (Ω) are the same.
  • 42. Guidelines for Asymptotic Analysis.  There are some general rules to help us determine the running time of an algorithm. Loops: The running time of a loop is, at most, the running time of the statements inside the loop (including tests) multiplied by the number of iterations.  Total time = a constant c × n = cn = O(n).
  • 43. Guidelines for Asymptotic Analysis.  Nested loops: Analyze from the inside out. Total running time is the product of the sizes of all the loops.  Total time = c × n × n = cn^2 = O(n^2).
  • 44. Guidelines for Asymptotic Analysis.  Consecutive statements: Add the time complexities of each statement.  Total time = c0 + c1n + c2n^2 = O(n^2).
  • 45. Guidelines for Asymptotic Analysis.  If-then-else statements: Worst-case running time: the test, plus either the then part or the else part (whichever is the larger).  Total time = c0 + c1 + (c2 + c3) * n = O(n)
  • 46. Guidelines for Asymptotic Analysis.  Logarithmic complexity: An algorithm is O(log n) if it takes a constant time to cut the problem size by a fraction (usually by ½).  As an example let us consider the following program:  If we observe carefully, the value of i is doubling every time. Initially i = 1, in next step i = 2, and in subsequent steps i = 4,8 and so on.  Let us assume that the loop is executing some k times. At kth step 2 power k = n, and at (k + 1)th step, we come out of the loop. Taking logarithm on both sides, gives;
  • 47. Guidelines for Asymptotic Analysis. Note: Similarly, for the case below, the worst case rate of growth is O(logn). The same discussion holds good for the decreasing sequence as well.
  • 48. Commonly used Logarithms and Summations
  • 49. Commonly used Logarithms and Summations
  • 50. Practice questions.  What is the running time of the following function? We can define the ‘s’ terms according to the relation si = si–1 + i. The value oft’ increases by 1 for each iteration. The value contained in ‘s’ at the ith iteration is the sum of the first ‘(‘positive integers. If k is the total number of iterations taken by the program, then the while loop terminates if:
  • 51. Practice questions.  Find the complexity of the function given below. In the above-mentioned function the loop will end, if i power 2 > n T(n) = O( ). ⇒
  • 52. Practice questions.  What is the complexity of the program given below: The complexity of the above function is O(n2logn)
  • 53. Practice questions.  What is the complexity of the program given below: The complexity of the above function is O(nlog2n).
  • 54. Practice questions.  What is the complexity of the program given below:  The complexity of the above function is O(n). Even though the inner loop is bounded by n, due to the break statement it is executing only once.
  • 55. Practice questions.  What is the complexity of the program given below:
  • 56. Practice questions. Rank the following functions by order of growth: (n + 1)!, n!, 4n, n × 3n, 3n + n2 + 20n, , n2 + 200, 20n + 500, 2lgn, n2/3, 1.
  • 57. Practice questions.  What is the complexity of the program given below:
  • 58. Practice questions.  What is the complexity of the program given below: