KEMBAR78
CSC121 Module 3 | PDF | Algorithms | Software Testing
0% found this document useful (0 votes)
24 views7 pages

CSC121 Module 3

The document outlines the steps in program development, including problem definition, algorithm design, coding, testing, debugging, and documentation. It emphasizes the importance of algorithms, their properties, and the use of pseudocode for clarity and communication in software development. Additionally, it provides examples of algorithms for various mathematical operations and problem-solving exercises.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views7 pages

CSC121 Module 3

The document outlines the steps in program development, including problem definition, algorithm design, coding, testing, debugging, and documentation. It emphasizes the importance of algorithms, their properties, and the use of pseudocode for clarity and communication in software development. Additionally, it provides examples of algorithms for various mathematical operations and problem-solving exercises.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

CSC121: INTRODUCTION TO PROBLEM SOLVING

MODULE 3
Steps in Program Development
Program development involves several steps, which can vary slightly depending on
the specific development process and methodology being used. Here are the general
steps in program development:

Problem Definition: The first step is to clearly understand the problem that the
software needs to solve. This involves gathering requirements, defining objectives,
and understanding user needs.

Algorithm Design: Once the problem is defined, programmers create a step-by-step


plan, or algorithm, to solve it. Algorithms provide a structured approach to breaking
down complex problems into manageable steps.

Coding: With the algorithm in place, developers write the actual code in a
programming language. This step involves translating the algorithmic solution into a
machine-readable form.

Testing: Testing involves executing the program with various inputs to verify that it
functions correctly and produces the expected outputs. Testing helps identify defects
and ensures the program meets its requirements.

Debugging: If errors or bugs are found during testing, debugging is the process of
identifying, diagnosing, and fixing these issues in the code. Debuggers and error logs
are commonly used for this purpose.

Documentation: Proper documentation is essential for understanding how the code


works, its purpose, and how to use it. Documentation can include comments in the
code, user manuals, and API documentation for libraries or modules.

Algorithms: Algorithms are precise, step-by-step instructions for solving problems.


They provide a clear and unambiguous path to achieving a specific goal. Algorithms
are independent of programming languages; the same algorithm can be implemented
in different languages. Writing efficient algorithms is essential for optimizing program
performance and resource usage. These algorithms can be designed through the use of
flowcharts or pseudocode.

Flowchart: Flowcharts are graphical representations of algorithms and processes.


They use symbols to represent actions, decisions, inputs, outputs, and the flow of
control in a program. Flowcharts help programmers visualize and plan the logical flow
1
Page

©CSC121: Introduction to Problem Solving


of a program before coding. They are particularly useful for understanding complex
algorithms and for communication between team members.

Key flowchart symbols include rectangles for processes or actions, diamonds for
decisions or conditional statements, arrows for flow direction, and parallelograms for
inputs/outputs.

Steps involved in algorithm development


An algorithm can be defined as a complete, unambiguous, finite number of logical
steps for solving a specific problem:

Step1: Identify the input: For an algorithm, there are quantities to be supplied called
input and these are fed externally. The input is to be identified first for any specified
problem.

Step2: Identify the output: From an algorithm, at least one quantity is produced,
called output for any specified problem.

Step3: Identify the processing operations: All the calculations to be performed in


order to lead to output from the input are to be identified in an orderly manner.

Step4: Processing Definiteness: The instructions composing the algorithm must be


clear and there should not be any ambiguity in them.

Step5: Processing Finiteness: If we go through the algorithm, then for all cases, the
algorithm should terminate after a finite number of steps.

Step6: Possessing Effectiveness: The instructions in the algorithm must be


sufficiently basic and in practice they can be carried out easily.

Properties of Algorithm
Algorithms are fundamental to computer science and problem-solving in general.
They are step-by-step procedures for solving problems and performing tasks. A good
algorithm possesses several important properties:

Correctness: An algorithm must produce the correct output for all possible valid
inputs. It should solve the problem it was designed for without errors or exceptions.

Finiteness: An algorithm must terminate after a finite number of steps. It cannot run
forever. This property ensures that the algorithm will eventually produce a result or
halt.

Definiteness: Each step of the algorithm must be precisely and unambiguously


defined. There should be no room for interpretation or ambiguity in how to execute
2
Page

the steps.

©CSC121: Introduction to Problem Solving


Input: Algorithms take zero or more inputs (parameters) that are used as initial data
for the computation. The algorithm should specify what the inputs are and how they
are used.

Output: An algorithm produces at least one output, which is the result or solution to
the problem. The output should be clearly defined and related to the problem
statement.

Effectiveness: The algorithm should be effective and practical, meaning that it can be
executed by a human or a computer within a reasonable amount of time and with
available resources.

Deterministic: An algorithm should be deterministic, meaning that it will produce the


same output for the same input every time it is executed. There should be no
randomness or unpredictability.

Termination: The algorithm should always terminate, even if it encounters


unexpected inputs or errors. It should not enter an infinite loop or get stuck.

Ease of Understanding: Algorithms should be designed with human readability in


mind. They should be clear, well-structured, and easy to understand by other
programmers.

Efficiency: While correctness is paramount, algorithms should also be designed to be


efficient in terms of time and space complexity. They should use resources
judiciously.

Adaptability: Some algorithms are designed to be general-purpose and adaptable to


various inputs and problem instances. Others may be specialized for specific
scenarios.

Scalability: Algorithms should work well for different input sizes, and their
performance should not degrade significantly as the size of the input increases.

Optimality: In some cases, it's important for an algorithm to produce the best possible
solution. Optimality is a property that depends on the problem being solved.

Robustness: Algorithms should be able to handle unexpected or erroneous inputs


gracefully, providing meaningful error messages or handling exceptional cases
appropriately.

Resource Usage: Algorithms should use resources such as memory efficiently. They
should not waste memory or other resources unnecessarily.
3
Page

©CSC121: Introduction to Problem Solving


Maintainability: Algorithms should be designed with ease of maintenance in mind.
They should be modular and well-documented so that changes and updates can be
made without introducing errors.

An algorithm can be written in English-like sentences or in any standard


representation like Pseudocode or Flowchart.

Pseudocode
Pseudocode is a high-level, human-readable representation of an algorithm or a
program's logic. It serves as an intermediate step between designing an algorithm and
writing the actual code in a programming language. Pseudocode is used to outline the
structure and steps of an algorithm in a way that is easy to understand, without getting
bogged down in the specific syntax of a programming language.

Pseudocode, by nature, exists in various forms; although most borrow syntax from
popular programming languages (like C, Lisp, or FORTRAN). Natural language is
used whenever details are unimportant or distracting.

Advantages of Pseudocode
Pseudocode offers several advantages in the software development process:

 Clarity and Readability: Pseudocode uses plain language and a simplified


structure that makes it easy to understand for both technical and non-technical
stakeholders. This clarity enhances communication among team members,
stakeholders, and collaborators.
 Language Independence: Pseudocode is not tied to a specific programming
language, making it platform-independent. This allows developers to focus on
algorithmic logic without being constrained by language-specific syntax or
semantics.
 Algorithm Exploration: Pseudocode enables developers to explore and plan
algorithms quickly and easily. It encourages thinking through the logical steps
and flow of an algorithm before diving into coding.
 Facilitates Collaboration: Pseudocode serves as a common ground for team
collaboration. It allows team members with different programming language
expertise to contribute to algorithm design and problem-solving discussions.
 Simplified Abstraction: Pseudocode abstracts the low-level details of
programming languages, reducing cognitive load during algorithm design.
Developers can concentrate on the high-level logic and decision-making
processes.
 Documentation: Pseudocode can be used as documentation for algorithms,
4

serving as a reference for future development or maintenance. It provides a


Page

clear, high-level overview of the algorithm's structure and steps.

©CSC121: Introduction to Problem Solving


 Efficiency and Productivity: Writing pseudocode before coding can lead to
more efficient development. Developers can identify potential issues, design
flaws, or algorithmic inefficiencies early in the process, reducing the need for
later revisions.
 Teaching and Learning: Pseudocode is often used in educational settings to
teach programming concepts, problem-solving skills, and algorithmic thinking.
It helps beginners grasp fundamental programming logic without the
distractions of a specific programming language.
 Code Independence: Pseudocode encourages developers to think
algorithmically rather than focusing on specific code constructs. This can lead
to more flexible and adaptable solutions that are not tied to a particular coding
language.
 Debugging Aid: When problems arise during coding, pseudocode can serve as
a reference for understanding the intended logic. It can help pinpoint issues and
inconsistencies in the code.
 Planning and Design: Pseudocode is a crucial tool during the planning and
design phase of software development. It allows developers to map out the
structure and behavior of a program or algorithm before writing actual code.
 Cross-Functional Communication: Pseudocode can facilitate communication
between technical and non-technical stakeholders, such as project managers,
clients, or domain experts, by providing a high-level view of how a solution
will work.

Example: Write a pseudocode to perform the basic


arithmetic operations.

10 Read n1, n2

20 Sum = n1 + n2

30 Diff = n1 – n2

40 Mult = n1 * n2

50 Quot = n1/n2

60 Print sum, diff, mult, quot

70 End

Problem1:
Suppose we want to find the average of three numbers, the algorithm is as follows
5
Page

Solution1:

©CSC121: Introduction to Problem Solving


Step1: Start program

Step2: Read the numbers a, b, c

Step3: Compute the sum of a, b and c

Step4: Divide the sum by 3

Step5: Store the result in variable d

Step6: Print the value of d

Step7: End of the program

Exercise1:
Write an algorithm to calculate the simple interest using
the formula.

Simple interest = P*T* R/100

Where P is Principal Amount, T is the period and R is the


rate of interest.

Problem2:
Write an algorithm to find the area of the triangle with
a given angle. Using Area of Triangle = ½*b*C*sinA

Solution2:

Step1: Start program

Step2: Input the given elements of the triangle namely


sides b, c and angle between the sides A.

Step3: Calculate Area of a Triangle = (1/2)*b*C*sinA

Step4: Print the Area of a Triangle

Step5: Stop

Problem3:
Write an algorithm to find the largest of three numbers X, Y,Z.

Solution3:

Step1: Start Program

Step2: Read X, Y, Z.
6
Page

©CSC121: Introduction to Problem Solving


Step3: If X > Y continue

Step4: If Y>Z then print “Y is the largest “and continue

Step5: Continue step 6. Step 5: If X>Z then print “X is


the largest “and continue step 7.

Step6: Print “Z is largest”.

Step7: End program

Exercise2:
Write an algorithm to find the smallest of three numbers
X, Y,Z.

Problem4:
Write an algorithm to calculate the perimeter and area of
rectangle, given its length and width.

Step1: Start program

Step2: Read length of the rectangle

Step3: Read width of the rectangle

Step4: Calculate perimeter of the rectangle using the


formula perimeter = 2*(length + width)

Step5: Calculate area of the rectangle using the formula


area = length*width

Step6: Print perimeter

Step7: Print area

Step8: End Program


7
Page

©CSC121: Introduction to Problem Solving

You might also like