0% found this document useful (0 votes)
7 views35 pages

Lec 05 Algorithms-And-Pseudocode

The document discusses algorithms and pseudocode, defining algorithms as structured sets of instructions to solve problems and pseudocode as an informal representation of these algorithms. It outlines the properties and advantages of algorithms, emphasizing their clarity, efficiency, and adaptability across programming languages. Additionally, it provides examples of algorithms and pseudocode for common tasks, illustrating their application in problem-solving.

Uploaded by

anaskhabeer04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views35 pages

Lec 05 Algorithms-And-Pseudocode

The document discusses algorithms and pseudocode, defining algorithms as structured sets of instructions to solve problems and pseudocode as an informal representation of these algorithms. It outlines the properties and advantages of algorithms, emphasizing their clarity, efficiency, and adaptability across programming languages. Additionally, it provides examples of algorithms and pseudocode for common tasks, illustrating their application in problem-solving.

Uploaded by

anaskhabeer04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 35

APPLICATION OF INFORMATION AND

COMMUNICATION TECHNOLOGIES
Algorithms and Pseudocodes

1
ALGORITHMS AND
PSEUDOCODES
ALGORITHMS AND FLOWCHARTS
 A typical programming task can be divided into
two phases:
 Problem solving phase
 produce an ordered sequence of steps that describe
solution of problem
 this sequence of steps is called an algorithm

 Implementation phase
 implement the program in some programming
language
Algorithm
 An algorithm is a well-defined set of
instructions or rules designed to solve a
specific problem or perform a task. It is the
abstract concept or the “recipe” for solving
a problem, without necessarily tying it to
any programming language.
Pseudocode
 Pseudocode, on the other hand, is an informal
way to represent an algorithm. It uses plain
English mixed with some programming-like
notation to convey the steps of the algorithm in a
way that’s easier to understand. The purpose of
pseudocode is to help programmers or
developers visualize and plan out the code
structure before implementing it in a specific
programming language.
Pseudocode & Algorithm
 Example 1: Write an algorithm to
determine a student’s final grade and
indicate whether it is passing or failing.
The final grade is calculated as the
average of four marks.
Level of Abstraction
 Algorithm: Algorithms are generally high-
level descriptions of how to solve a
problem. They don’t focus on the specifics
of syntax or detailed step-by-step coding
but provide an outline that can be
implemented in multiple ways.
Level of Abstraction
 Pseudocode: Pseudocode is one step
closer to actual code. While it still isn’t
specific to any programming language, it
may use loops, conditions, and statements
that closely resemble programming syntax
to give a clear picture of the steps.
Structure and Format
 Pseudocode: Pseudocode uses
structured, step-by-step instructions in a
layout resembling actual code but in plain
language.
Structure and Format
 Pseudocode: Pseudocode uses
structured, step-by-step instructions in a
layout resembling actual code but in plain
language.
Execution
 Algorithm: It cannot be executed directly
on a computer. It needs to be
implemented in a programming language.
Execution
 Pseudocode: Pseudocode also cannot be
executed but is closer to executable code,
making it easier to convert to a
programming language.
Properties of Algorithms
 An algorithm must terminate after a finite
number of steps. This means that it should have
a clear end, avoiding infinite loops or indefinite
operations.
 Each step in an algorithm must be clear and
unambiguous. Instructions should be simple,
precise, and meaningful so that there is no
confusion about what each step accomplishes.
Properties of Algorithms
 An algorithm should have well-defined
inputs. These inputs are the data that the
algorithm requires to begin its operation.
There can be zero or more inputs,
depending on the problem.
Properties of Algorithms
 An algorithm should produce at least one
output, which is the result of processing
the inputs. The output should be clearly
defined and meaningful in solving the
given problem.
Properties of Algorithms
 Every step in the algorithm should be
simple enough that it can, in theory, be
carried out by a human using only paper
and pencil within a finite amount of time.
The operations must be feasible and
executable.
Properties of Algorithms
 The steps of an algorithm should be
numbered and ordered sequentially, as
each step relies on the previous ones.
This helps ensure that the algorithm is
followed correctly and yields the desired
results.
Properties of Algorithms
 An algorithm should be written in simple,
language-independent terms. Using plain
English or pseudocode ensures that the
algorithm can be implemented in any
programming language without ambiguity.
Advantages of Algorithms
 Algorithms provide a clear and structured
approach to solving problems. Each step
is outlined logically, making it easier to
follow and understand the solution
process.
Advantages of Algorithms
 Algorithms can be optimized to perform
tasks quickly and with minimal resource
usage. This allows for efficient problem-
solving, which is especially important for
handling large datasets or complex
calculations.
Advantages of Algorithms
 Since algorithms are written in plain
language or pseudocode, they are
independent of any specific programming
language. This makes them versatile and
easily adaptable to various programming
languages.
Advantages of Algorithms
 Once an algorithm is developed and
proven effective, it can be reused to solve
similar problems. This reduces the need to
create new solutions for every similar
problem, saving time and effort.
Advantages of Algorithms
 Algorithms break down complex problems
into manageable steps, helping to simplify
and streamline the solution process. This
structured approach makes problem-
solving easier and less error-prone.
Advantages of Algorithms
 Algorithms provide a standard approach to
solving specific types of problems, which
promotes consistency and reliability.
Standard algorithms, such as sorting or
searching, have been extensively tested
and validated.
Example
 A computer science student often
procrastinates on assignments, leading to
rushed work, errors, or missed deadlines.
The problem is a lack of time management
and structured planning.
Objective: Create a systematic plan to complete
the assignment efficiently and on time .

1. Input:
1. Assignment topic and deadline.
2. List of requirements (coding, documentation, testing, etc.).
3. Estimated time for each task.
2. Steps:
1.Start.
2.Read and understand the assignment requirements.
3.Break down the assignment into smaller tasks:
1. Research the topic.
2. Write code or implement the solution.
3. Test the solution.
4. Write documentation.
5. Review and finalize the submission.
4.Estimate the time required for each task.
5.Create a schedule, allocating time for each task based on the deadline.
6.Start with the first task (research) and work sequentially:
1. If the task is completed, mark it as done.
2. Else, allocate more time or seek help if stuck.
7.Regularly review progress against the schedule.
8.Once all tasks are completed, review the entire assignment for errors.
9.Submit the assignment before the deadline.
10.End.
Input:
1.Assignment: Write a program to implement a sorting algorithm.
2.Deadline: 7 days.
3.Steps

3.1 Tasks:
Research (1 day),
1.

2. Code (3 days),

3. Test (1 day),

4. Document (1 day),

5. Review (1 day)

nProcess: Follow the plan step-by-step, ensuring daily progress.


nOutput: Submit a well-tested, documented program by the 7th day.
Example
Example 1: Adding Two Numbers
Problem: Add two numbers and return the
result.
Algorithm:
•Step 1: Start.
•Step 2: Input the first number, a.
•Step 3: Input the second number, b.
•Step 4: Calculate the sum of a and b and store
it in sum.
•Step 5: Output the value of sum.
•Step 6: End.
Example
 Pseudocode:
1. Start
2. Input a
3. Input b
4. sum = a + b
5. Print sum
6. End
Example
Example 2: Finding the Largest of Two Numbers
Problem: Compare two numbers and return the larger
number.
Algorithm:
•Step 1: Start.
•Step 2: Input the first number, x.
•Step 3: Input the second number, y.
•Step 4: If x is greater than y, then:
•Print x as the largest number.
•Step 5: Otherwise:
•Print y as the largest number.
•Step 6: End.
Example
 Pseudocode:
1. Start
2. Input x
3. Input y
4. If x > y
5. Print x
6. Else
7. Print y
8. End If
9. End
Example
Example 3: Calculating the Average of Three
Numbers
Problem: Find the average of three numbers.
Algorithm:
•Step 1: Start.
•Step 2: Input three numbers: num1, num2, and
num3.
•Step 3: Calculate the sum of the three numbers.
•Step 4: Divide the sum by 3 to find the average.
•Step 5: Output the average.
•Step 6: End.
Example
 Pseudocode:
1. Start
2. Input num1
3. Input num2
4. Input num3
5. sum = num1 + num2 + num3
6. average = sum / 3
7. Print average
8. End
Activity
 Find the Square of a Number
 Determine if a Number is Divisible by 5
 Print All Odd Numbers from 1 to N
 Calculate the Average of Three Numbers
 Convert Celsius to Fahrenheit

You might also like