Algorithm Design and Problem Solving
I know Terms:
1. The stages in the program development cycle
2. Computer Systems and Subsystems
3. Problem decomposition into component parts
4. Methods used to design and construct solutions to problems
5. The purpose of an algorithm and the processes involved in it
6. Standard methods of solutions like (linear search, bubble sort, totalling, counting. Etc.)
7. Validation and Verification checks when data is input
8. Use of di erent types of test data (Use of trace table)
9. Writing, Amending, Identifying, and Correcting Errors (Flowchart, Pseudocode, Programs)
Program Development Life Cycle
Definition: The Program Development Life Cycle (PDLC) is a systematic approach used
in software engineering to develop quality software. It provides an organized plan for
breaking down the task of program development into manageable chunks, ensuring that
each phase is successfully completed before moving on to the next.
Here are the key phases of PDLC:
1. Analysis:
o Connection: This step involves identifying and understanding the
problem that the software aims to solve. It defines the purpose of the
program.
o Importance: Clear problem definition ensures that the development
team understands project goals and objectives, guiding subsequent
steps.
2. Program Design:
o Connection: Building upon the problem definition, program design
focuses on creating a conceptual plan for the software. It breaks down
the main goal into smaller modules.
o Importance: E ective design ensures that software components work
together seamlessly. Design tools like algorithms, structure charts, and
flowcharts aid in visualizing the solution.
Notes created by Avik Ghosh
3. Coding and Implementation:
o Connection: In this step, developers translate the design into actual code
using programming languages.
o Importance: Proper coding ensures that the software behaves as
intended and meets specified requirements.
4. Testing and Debugging:
o Connection: Rigorous testing verifies the functionality, performance, and
reliability of the software. Debugging addresses any issues found during
testing.
o Importance: Thorough testing leads to robust and reliable software,
minimizing errors in the final product.
Remember that the PDLC is not strictly linear; it involves interactions and iterations.
Continual refinement and adaptation are essential throughout the development
process. By following these steps, software development teams can create high-quality
applications.
Computer System, Sub-system
1. Computer Systems:
o A computer system is an integrated entity that comprises interconnected
components working together to perform specific functions or tasks.
o It includes both hardware and software components.
o Key components of a computer system:
Central Processing Unit (CPU): Controls most activities, performs
arithmetic and logical operations, and contains fast memory.
Memory: Stores instructions for the CPU and data.
Input/Output (I/O): Communicates with external devices (e.g.,
keyboard, mouse, screen) and mass storage (e.g., disks, USB).
Bus: Provides communication pathways with specific protocols.
o The von Neumann architecture describes this model, where program
instructions and data are stored separately in memory, allowing programs to be
self-modifying.
Notes created by Avik Ghosh
2. Subsystems:
o Subsystems are self-contained units within larger systems.
o They contribute to the overall functionality and performance of the system.
o Examples of subsystems:
Disk Subsystem: Part of a computer system responsible for managing
storage devices.
I/O Subsystem: Handles communication with external devices.
Network Subsystem: Manages network connections and data transfer.
o Subsystems collaborate to achieve system-level objectives.
Remember, understanding these concepts helps us appreciate how computer systems are
organized and interconnected!
Decomposing a problem
1. Decomposing a Problem:
o Decomposition involves breaking down a complex problem into smaller, more
manageable parts or components.
o By doing so, we can analyse, understand, and address each part independently.
o In the context of computer systems, decomposition helps us design and build
e ective solutions.
2. Why Decompose?
o Any problem that involves a computer system—whether it’s writing software,
designing a database, or building a network—benefits from decomposition.
o Decomposition allows us to:
Understand the problem thoroughly.
Focus on specific aspects without getting overwhelmed.
Design and implement solutions incrementally.
3. Components of a Computer System:
o When decomposing a problem related to a computer system, consider these
essential components:
Input: Information or data provided to the system (e.g., user input,
sensor readings).
Output: The result produced by the system (e.g., displayed information,
generated reports).
Notes created by Avik Ghosh
Process: The computation, manipulation, or transformation of data (e.g.,
algorithms, calculations).
Storage: Where data is stored (e.g., memory, databases, files).
o Importance of Each Component:
Input: Accurate input ensures meaningful processing.
Output: Relevant output communicates results to users.
Process: E icient processing achieves the desired outcome.
Storage: Proper storage maintains data integrity and accessibility.
Example:
The alarm app can be decomposed into:
» Inputs – time to set the alarm, remove a previously set alarm time, switch an alarm o , press
snooze button
» Processes – continuously check if the current time matches an alarm time that has been set,
storage and removal of alarm times, management of snooze
» Outputs – continuous sound/tune (at alarm time or after snooze time expired)
» Storage – time(s) for alarms set
Methods used to design and construct a solution to a problem
Designing and constructing a solution to a problem in computer science typically involves
breaking down the problem into smaller, more manageable components. Three common
methods used for this purpose are Structure Diagrams, Pseudocode, and Flowcharts. Each of
these methods provides a di erent way of representing the logic and structure of the solution,
helping to ensure that the final implementation is well-organized and e icient.
Structure Diagrams
Overview:
Structure diagrams, also known as hierarchy charts or module diagrams, are used to represent
the breakdown of a system or a problem into smaller sub-problems or modules. They visually
depict the relationship between the di erent components of a system, showing how they are
connected and how they interact with each other.
Key Features:
Modularity: Structure diagrams emphasize the modular nature of a system, where each
module represents a distinct function or process.
Notes created by Avik Ghosh
Hierarchy: The diagrams are typically hierarchical, with the main problem or system at
the top, and sub-modules branching out below it.
Interrelationships: The diagram shows how the modules are related, indicating the flow
of control and data between them.
Module: It represents the process or task of the system.
Example:
Pseudocode
Overview:
Pseudocode is a method of designing algorithms in a way that is easy to understand. It is written
in plain language or a simplified programming-like syntax that resembles real code but is not
bound by any specific programming language syntax.
Key Features:
Simplicity: Pseudocode is easy to read and write, making it accessible to both
programmers and non-programmers.
Abstraction: It abstracts away the details of the programming language, focusing
instead on the logic and flow of the algorithm.
Flexibility: It can be easily translated into actual code in any programming language.
Let’s learn the basic Syntax for Pseudocode
OUTPUT
// OUTPUT {value}
Notes created by Avik Ghosh
// OUTPUT {value1}, {value2}, ...
OUTPUT "Hello world"
Hello World
INPUT from User
//Getting information from the user with INPUT
OUTPUT "Please enter your name: "
// INPUT {identifier}
INPUT Name
OUTPUT "Name is ", Name
Comments for Pseudocode
// This is a comment in my code it does nothing
// OUTPUT "Hello world"
// No output will be displayed!
Notes created by Avik Ghosh
Declare a variable
// DECLARE {identifier}: {data type}
DECLARE Counter: INTEGER
DECLARE TotalToPay: REAL
DECLARE GameOver: BOOLEAN
Using variable to store data
DECLARE Counter: INTEGER
// Storing Number
Counter <- 12
// Storing STRING
DECLARE Name: STRING
Name <- “Geet”
Handling Conditions
Notes created by Avik Ghosh
Conditional Statements:
Price <- 0.9
IF Price >= 1.00
THEN
Tax <- 0.07
OUTPUT Tax
ELSE
Tax <- 0.0
OUTPUT Tax
ENDIF
Loops:
Using For loop
Looping several times:
FOR Index ← 1 TO 10
OUTPUT Index
NEXT Index
Assigning a group of array elements:
DECLARE StudentNames : ARRAY[1:3] OF STRING
FOR Index ← 1 TO 10
StudentNames[1] ← ""
NEXT Index
Notes created by Avik Ghosh
OUTPUT "First StudentName: ", StudentNames[1]
Looping with a condition
DECLARE Index : INTEGER
DECLARE StudentNames : ARRAY[1:3] OF STRING
StudentNames[1] ← "Jim"
StudentNames[2] ← "Tony"
StudentNames[3] ← "Bob"
Index ← 1
WHILE Index <= 3 DO
OUTPUT StudentNames[Index]
// Change the condition!!
Index ← Index + 1
ENDWHILE
Function on Pseudocode
PROCEDURE PrintIt
OUTPUT "task completed"
OUTPUT ""
ENDPROCEDURE
FirstName ← "Larry"
Notes created by Avik Ghosh
CALL PrintIt
FOR Index ← 0 TO 9
OUTPUT Index
NEXT Index
CALL PrintIt
Create function which returns something
FUNCTION GetInitial(Name : STRING) RETURNS STRING
DECLARE Initial : STRING
Initial ← Name[0]
RETURN Initial
ENDFUNCTION
OUTPUT "Enter your first name: "
INPUT FirstName
FirstNameInitial ← GetInitial(FirstName)
OUTPUT "Enter your last name: "
INPUT LastName
LastNameInitial ← GetInitial(LastName)
OUTPUT "Your initials are: ", FirstNameInitial, LastNameInitial
Notes created by Avik Ghosh
Function with parameter
FUNCTION GetInitial(Name : STRING, ForceUppercase : BOOLEAN) RETURNS
STRING
DECLARE Initial : STRING
IF ForceUppercase
THEN
Initial ← UCASE(Name[0])
ELSE
Initial ← Name[0]
ENDIF
RETURN Initial
ENDFUNCTION
OUTPUT "Enter your first name: "
INPUT FirstName
FirstNameInitial ← GetInitial(FirstName, FALSE)
OUTPUT "Your initial is: ", FirstNameInitial
Flow Chart
Definition:
A flowchart is a diagram that shows the sequence of actions or information needed for
tasks such as training, documenting, planning, and decision-making.
It represents a workflow or process using boxes (representing steps) and arrows
(indicating the flow between steps).
Notes created by Avik Ghosh
Purpose:
Flowcharts are used to:
o Document processes.
o Study and analyse complex systems.
o Plan and improve workflows.
o Communicate processes clearly.
Symbols:
Let’s take an example to make things clear:
Notes created by Avik Ghosh
Standard Methods of solution
Totalling
Purpose: Calculate the sum of a list of numbers.
Notes created by Avik Ghosh