Lec 05 Algorithms-And-Pseudocode
Lec 05 Algorithms-And-Pseudocode
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)