UNIT - 1
Introduction: The Role of Algorithms in Computing, Algorithms
as a technology, Analyzing algorithms, Designing algorithms,
Growth of Functions, Asymptotic notation, Standard notations
and common functions.
Fundamental Algorithms: Exchanging the values of two
variables, Counting, Summation of a set of numbers, Factorial
Computation, Generating of the Fibonacci sequence, Reversing
the digits of an integer, Character to number conversion.
Problem solving
•It is a systematic approach to find and implement the solution to a
problem.
Program
•It is a set of instructions written in computer languages
Software
•It is a collection of computer program (or) data and instructions.
•It is responsible for controlling, integration and managing hardware
components and perform specific tasks.
Classifications of software
System software
•It is a set of one or more programs that manage and support
a computer system hardware and its data processing
activities.
•Ex: Operating system, Compilers, Assemblers
Application software
•It is a set of one or more programs, designed to solve a
specific problem or a specific task.
•Ex: Ms-Word ,Ms-Excel, Ms-Powerpoint
Steps in Problem Solving
1. Problem Definition
2. Problem Analysis
3. Design
4. Coding
5. Testing
6. Maintenance
1. Problem Definition
•To solve a problem, the first step is to
identify and define the problem.
•The problem must be stated clearly,
accurately and precisely.
•Ex: Find largest of three numbers
2. Problem Analysis
The problem analysis helps in designing and coding for that
particular problem.
1. Input specifications
•The number of inputs and what forms the input are available
2.Output specifications
•The number of outputs and what forms the output should be
displayed.
Ex:
•input – a,b,c
•output – a (or) b (or) c
3. Designing a program
Algorithms
•Algorithm - step by step procedure of solving a problem
Flowcharts
•Flowcharts – It is the graphical representation of the
algorithm.
4. Coding
• Writing instructions in a particular language to solve a
problem.
5. Testing a Program
• After writing a program, programmer needs to test the
program for completeness, correctness, reliability and
maintainability.
• Unit testing
• Program Testing
• Verification Testing
• Validation Testing
6. Maintaining the program
•It means periodic review of the
programs and modifications based on
user requirements.
What is an Algorithm?
•In computer programming terms, an algorithm is a set of
well-defined instructions to solve a particular problem. It
takes a set of input(s) and produces the desired output.
For example,
•An algorithm to add two numbers:
1. Take two number inputs
2. Add numbers using the + operator
3. Store the result
4. Display the result
Hint:
Need of the Algorithm:
Algorithms are used to solve problems or automate tasks in a systematic and efficient manner. They are a set of
instructions or rules that guide the computer or software in performing a particular task or solving a problem.
Qualities of a Good Algorithm
•Input and output should be defined
precisely.
•Each step in the algorithm should be clear
and unambiguous.
•Algorithms should be most effective among
many different ways to solve a problem.
•An algorithm shouldn't include computer
code. Instead, the algorithm should be
written in such a way that it can be used in
different programming languages.
Characteristics of an algorithm
The characteristics of an algorithm are
•(i) Algorithm must have finite number of steps.
•(ii) No instructions should be repeated.
•(iii) An algorithm should be simple.
•(iii) An algorithm must take atleast one or more
input values.
•(iv) An algorithm must provide atleast one or more
output values.
Characteristics of an algorithm
Advantages
•Algorithms are very easy to
understand.
•Algorithm is programming language
independent.
•Algorithm makes the problem simple,
clear, correct.
The Role of Algorithms
• Algorithms play a crucial role in computing by providing
a set of instructions for a computer to perform a specific
task.
• They are used to solve problems and carry out tasks in
computer systems, such as sorting data, searching for
information, image processing, and much more.
• An algorithm defines the steps necessary to produce
the desired outcome, and the computer follows the
instructions to complete the task efficiently and
accurately.
Role of Algorithm in Applications
Role of Algorithm in Computing
Role of Algorithm in Networking
Algorithm to Add two numbers entered by
the user
• Step 1: Start
• Step 2: Declare variables num1, num2 and sum.
• Step 3: Read values num1 and num2.
• Step 4: Add num1 and num2 and assign the result to sum.
• sum←num1+num2
• Step 5: Display sum
• Step 6: Stop
Algorithm for Swapping
two numbers using third
variable:
Step 1: Declare a variable a,b
and c as integer;
Step 2: Read two numbers a and
b;
Step 3: c=a;
Step 4: a=b;
Step 5: b=c;
Step 6: Print a and b
STEP 1: START
STEP 2: ENTER A, B
STEP 3: PRINT A, B
STEP 4: A = A + B
STEP 5: B= A - B
STEP 6: A =A - B
STEP 7: PRINT A, B
STEP 8: END
Algorithm for Swapping two
numbers without using third
variable:
Algorithm to find Summation of a set of
numbers
Step 1: Start
Step 2: Read the number n
Step 3: Calculate the sum of n natural number, sum = n * (n + 1) / 2
Step 4: Display sum
Step 5: End
Algorithm to find count of numbers of digits
in a number
• Step 1: Declare variable a and n; //n variable is used for counting
• Step 2: Read number a;
• Step 3: while(a not equal 0)
• a=a/10;
• n=n+1;
• end
• Step 4: Print n;
• Step 5: End
Algorithm to Find the largest number among
three numbers
Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c.
Step 4: If a > b
If a > c
Display a is the largest number.
Else
Display c is the largest number.
Else
If b > c
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: Stop
Algorithm to Find the factorial of a number
Step 1: Start
Step 2: Declare variables n, fact and i.
Step 3: Initialize variables
fact← 1
i ← 1
Step 4: Read value of n
Step 5: Repeat the steps until i = n
5.1: fact ← fact*i
5.2: i ← i+1
Step 6: Display fact
Step 7: Stop
Algorithm 6: Find the Fibonacci series
• Step 1: Start
• Step 2: Declare variable a, b, c, n, i
• Step 3: Initialize variable a=0, b=1 and i=2
• Step 4: Read n from user
• Step 5: Print a and b
• Step 6: Repeat until i<=n :
Step 6.1: c=a+b
Step 6.2: print c
Step 6.3: a=b, b=c
Step 6.4: i=i+1
• Step 7: Stop
Algorithm to Reversing the digits of an
integer
• Step 1: Declare variable n, rev and rem as integer;
• Step 2: Read the number n;
• Step 3: while n not equal 0
{
rem=n%10;
rev=rev * 10 + rem;
n=n/10;
}
• Step 4: Print rev
GREATEST OF THREE
NUMBERS
FACTORIAL OF GIVEN
NUMBER
FIBONACCI SERIES
REVERSE THE GIVEN
NUMBER
Algorithms as a technology
Analysing Algorithms
Designing algorithms

Problem Solving Techniques notes for Unit 1

  • 1.
    UNIT - 1 Introduction:The Role of Algorithms in Computing, Algorithms as a technology, Analyzing algorithms, Designing algorithms, Growth of Functions, Asymptotic notation, Standard notations and common functions. Fundamental Algorithms: Exchanging the values of two variables, Counting, Summation of a set of numbers, Factorial Computation, Generating of the Fibonacci sequence, Reversing the digits of an integer, Character to number conversion.
  • 2.
    Problem solving •It isa systematic approach to find and implement the solution to a problem. Program •It is a set of instructions written in computer languages Software •It is a collection of computer program (or) data and instructions. •It is responsible for controlling, integration and managing hardware components and perform specific tasks.
  • 3.
    Classifications of software Systemsoftware •It is a set of one or more programs that manage and support a computer system hardware and its data processing activities. •Ex: Operating system, Compilers, Assemblers Application software •It is a set of one or more programs, designed to solve a specific problem or a specific task. •Ex: Ms-Word ,Ms-Excel, Ms-Powerpoint
  • 4.
    Steps in ProblemSolving 1. Problem Definition 2. Problem Analysis 3. Design 4. Coding 5. Testing 6. Maintenance
  • 5.
    1. Problem Definition •Tosolve a problem, the first step is to identify and define the problem. •The problem must be stated clearly, accurately and precisely. •Ex: Find largest of three numbers
  • 6.
    2. Problem Analysis Theproblem analysis helps in designing and coding for that particular problem. 1. Input specifications •The number of inputs and what forms the input are available 2.Output specifications •The number of outputs and what forms the output should be displayed. Ex: •input – a,b,c •output – a (or) b (or) c
  • 7.
    3. Designing aprogram Algorithms •Algorithm - step by step procedure of solving a problem Flowcharts •Flowcharts – It is the graphical representation of the algorithm.
  • 8.
    4. Coding • Writinginstructions in a particular language to solve a problem. 5. Testing a Program • After writing a program, programmer needs to test the program for completeness, correctness, reliability and maintainability. • Unit testing • Program Testing • Verification Testing • Validation Testing
  • 9.
    6. Maintaining theprogram •It means periodic review of the programs and modifications based on user requirements.
  • 10.
    What is anAlgorithm? •In computer programming terms, an algorithm is a set of well-defined instructions to solve a particular problem. It takes a set of input(s) and produces the desired output. For example, •An algorithm to add two numbers: 1. Take two number inputs 2. Add numbers using the + operator 3. Store the result 4. Display the result Hint: Need of the Algorithm: Algorithms are used to solve problems or automate tasks in a systematic and efficient manner. They are a set of instructions or rules that guide the computer or software in performing a particular task or solving a problem.
  • 11.
    Qualities of aGood Algorithm •Input and output should be defined precisely. •Each step in the algorithm should be clear and unambiguous. •Algorithms should be most effective among many different ways to solve a problem. •An algorithm shouldn't include computer code. Instead, the algorithm should be written in such a way that it can be used in different programming languages.
  • 12.
    Characteristics of analgorithm The characteristics of an algorithm are •(i) Algorithm must have finite number of steps. •(ii) No instructions should be repeated. •(iii) An algorithm should be simple. •(iii) An algorithm must take atleast one or more input values. •(iv) An algorithm must provide atleast one or more output values.
  • 13.
  • 14.
    Advantages •Algorithms are veryeasy to understand. •Algorithm is programming language independent. •Algorithm makes the problem simple, clear, correct.
  • 15.
    The Role ofAlgorithms • Algorithms play a crucial role in computing by providing a set of instructions for a computer to perform a specific task. • They are used to solve problems and carry out tasks in computer systems, such as sorting data, searching for information, image processing, and much more. • An algorithm defines the steps necessary to produce the desired outcome, and the computer follows the instructions to complete the task efficiently and accurately.
  • 16.
    Role of Algorithmin Applications
  • 17.
    Role of Algorithmin Computing
  • 18.
    Role of Algorithmin Networking
  • 19.
    Algorithm to Addtwo numbers entered by the user • Step 1: Start • Step 2: Declare variables num1, num2 and sum. • Step 3: Read values num1 and num2. • Step 4: Add num1 and num2 and assign the result to sum. • sum←num1+num2 • Step 5: Display sum • Step 6: Stop
  • 20.
    Algorithm for Swapping twonumbers using third variable: Step 1: Declare a variable a,b and c as integer; Step 2: Read two numbers a and b; Step 3: c=a; Step 4: a=b; Step 5: b=c; Step 6: Print a and b STEP 1: START STEP 2: ENTER A, B STEP 3: PRINT A, B STEP 4: A = A + B STEP 5: B= A - B STEP 6: A =A - B STEP 7: PRINT A, B STEP 8: END Algorithm for Swapping two numbers without using third variable:
  • 21.
    Algorithm to findSummation of a set of numbers Step 1: Start Step 2: Read the number n Step 3: Calculate the sum of n natural number, sum = n * (n + 1) / 2 Step 4: Display sum Step 5: End
  • 22.
    Algorithm to findcount of numbers of digits in a number • Step 1: Declare variable a and n; //n variable is used for counting • Step 2: Read number a; • Step 3: while(a not equal 0) • a=a/10; • n=n+1; • end • Step 4: Print n; • Step 5: End
  • 23.
    Algorithm to Findthe largest number among three numbers Step 1: Start Step 2: Declare variables a,b and c. Step 3: Read variables a,b and c. Step 4: If a > b If a > c Display a is the largest number. Else Display c is the largest number. Else If b > c Display b is the largest number. Else Display c is the greatest number. Step 5: Stop
  • 24.
    Algorithm to Findthe factorial of a number Step 1: Start Step 2: Declare variables n, fact and i. Step 3: Initialize variables fact← 1 i ← 1 Step 4: Read value of n Step 5: Repeat the steps until i = n 5.1: fact ← fact*i 5.2: i ← i+1 Step 6: Display fact Step 7: Stop
  • 25.
    Algorithm 6: Findthe Fibonacci series • Step 1: Start • Step 2: Declare variable a, b, c, n, i • Step 3: Initialize variable a=0, b=1 and i=2 • Step 4: Read n from user • Step 5: Print a and b • Step 6: Repeat until i<=n : Step 6.1: c=a+b Step 6.2: print c Step 6.3: a=b, b=c Step 6.4: i=i+1 • Step 7: Stop
  • 26.
    Algorithm to Reversingthe digits of an integer • Step 1: Declare variable n, rev and rem as integer; • Step 2: Read the number n; • Step 3: while n not equal 0 { rem=n%10; rev=rev * 10 + rem; n=n/10; } • Step 4: Print rev
  • 33.
  • 34.
  • 35.
  • 36.
  • 38.
    Algorithms as atechnology
  • 39.
  • 44.