KEMBAR78
Unit 2 - Problem Solving Tools & Technics | PDF | Control Flow | Algorithms
0% found this document useful (0 votes)
12 views25 pages

Unit 2 - Problem Solving Tools & Technics

The document discusses problem-solving tools and techniques, focusing on algorithms, pseudocode, and flowcharts. It provides a historical background on algorithms, outlines steps for designing and analyzing algorithms, and explains key programming concepts such as variables, data types, and mathematical operations. Additionally, it highlights the benefits of pseudocode in algorithm design and provides examples of pseudocode for various problems.

Uploaded by

kundanet21
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)
12 views25 pages

Unit 2 - Problem Solving Tools & Technics

The document discusses problem-solving tools and techniques, focusing on algorithms, pseudocode, and flowcharts. It provides a historical background on algorithms, outlines steps for designing and analyzing algorithms, and explains key programming concepts such as variables, data types, and mathematical operations. Additionally, it highlights the benefits of pseudocode in algorithm design and provides examples of pseudocode for various problems.

Uploaded by

kundanet21
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/ 25

Problem Sovings Tools and

Technics

Pseudocode
Algorithm

Flowchart
Problem Sovings Tools and
Technics
1. Algorithm: Origin

The word "algorithm" traces its roots back to the 9th-
century Persian mathematician, Muhammad ibn Musa al-
Khwarizmi.


Algorithm Has been translated from Persian to Latin to
English
Father of Algorithm & Algebra- Muhammad I Musa Al
Khwarizmi
Steps for designing and analyzing an
1. Understanding the problemAlgorithm
-Read the problem
4. Prove correctness
-Ask the questions
-Verification
-Find and decide the range of inputs
-Validation
2. Make decision
5. Analyze the algorithm
-Capacities of computational
-Time complexity
devices, sequential & Pararel
-Space complexity
-Select problem solving method-
-Simplicity
Exact & approximation
-Generality
-Data structures
6.Code the algorithm
-Algorithmic strategies
-Suitable programming language
3. Design an algorithm
-Writing optimized code
-Natural Language
-Pseudocode
-Flowchart
Introduction and definition of
common terms

Variables

Data types

Mathematical operators

Keywords

Statements
Variables
➢ Variables are fundamental constructs in algorithms and programming that
represent storage locations for holding data.

➢ They serve as containers that can store different types of values, such as
numbers, characters, or more complex data structures, depending on the
programming language and its type system.

➢ Examples: y=10 which means

y takes the value 10

10 is assigned to y
Data Types

A set containing values and operations that can be performed on those
values .

Tell the computer how to treat the values of a variable;

Common data types:
integer, floating-point numbers, character, string, boalean, Arrays

Primitive includes byte , short , int , long , float , double , boolean and char.

Non-primitive data types - such as String, Arrays and Classes


Mathematical Operations
Mathematical operators are fundamental symbols used in algorithms and
programming to perform various arithmetic and mathematical operations on
numerical values.

The most common mathematical operators include


• Addition (+)
• subtraction (-),
• multiplication (*),
• and division (/), which are used to perform basic calculations.
Additionally, the modulus operator (%)
Keywords
Based on the context of algorithms and programming, here is a list of common keywords that are typically
used in algorithm design:
INPUT - Used to denote the acquisition of data from the user or another source.
OUTPUT - Represents the results produced by the algorithm after processing the input.
IF - A conditional statement that executes a block of code if a specified condition is true.
ELSE - Provides an alternative block of code to execute if the condition in the IF statement is false.
ELSE IF - Allows for multiple conditions to be checked in sequence.
WHILE - Initiates a loop that continues to execute as long as a specified condition remains true.
FOR - Used to create a loop that iterates a specific number of times, often with a counter variable.
DO - Similar to WHILE, but guarantees that the code block is executed at least once before checking the
condition.
FUNCTION - Defines a reusable block of code that can be called with specific parameters.
RETURN - Exits a function and optionally returns a value to the caller.
BREAK - Exits a loop or switch statement prematurely.
CONTINUE - Skips the current iteration of a loop and proceeds to the next iteration.
CASE - Used in switch statements to define a block of code that executes for a specific value.
DEFAULT - Specifies a block of code to execute if no case matches in a switch statement.
Statement
 Part of a program or pseudocode
 Indicates a particular action to be performed
in program
 Example:
PRINT (“I am ready for Business”)
 Types
Declarative Statements
Assignment Statements
Conditional Statements
Iterative statements
Conditional Statement
➢ Different actions for different input
➢ Evaluate statements and execute instructions based on whether the evaluated
statement true or false.
➢ Single or multiple
Single Multiple
If you are hungry if you are hungry
then eat then eat
End if else
work
end if
Iterative Statement
➢ commonly referred to as loops, are fundamental constructs in programming
that allow for the repeated execution of a block of code based on specified
conditions.
➢ there are three primary types of iteration statements: for, while, and do-
while.
➢ The for loop is particularly useful when the number of iterations is known in
advance, as it combines initialization, condition checking, and incrementing
in a single line.
➢ In contrast, the while loop continues to execute as long as a specified
condition remains true, making it suitable for situations where the number
of iterations is not predetermined. The do-while loop guarantees that the
code block is executed at least once before the condition is evaluated,
which is beneficial in cases where the loop body must run before any
checks are made
Algorithms Representation
Algorithms can be represented in various forms to
convey their logic and structure clearly and concisely.
Two common ways to represent algorithms are
pseudocode and flowcharts.
Pseudocode

A pseudocode (pronounced Soo-doh-kohd) is another way of representing an
algorithm.

It is considered as a non-formal language that helps programmers to write
algorithm.

It is a detailed description of instructions that a computer must follow in a particular
order. It is intended for human reading and cannot be executed directly by the
computer.

No specific standard for writing a pseudocode exists.

The word “pseudo” means “not real,” so “pseudocode” means “not real code”
Or
pseudo-” means “almost” so Pseudocode means ” almost code’’
Pseudocode

Following are some of the frequently used keywords while writing pseudocode:


INPUT

COMPUTE

PRINT

INCREMENT

DECREMENT

IF/ELSE

WHILE

TRUE/FALSE

SET
Benefits of Pseudocode

Improved Readability

Concise and Clear: Pseudocode allows the designer to focus on the main logic
without being distracted by programming language syntax, making it easier to
understand and modify

Plain English: It is written in plain natural language, making it accessible even to
non-programmers


Language Independence

Universal Understanding: Pseudocode is not specific to any programming
language, allowing it to be understood by programmers regardless of their
background or language expertise

Easy Translation: It can be easily translated into any computer language code,
facilitating the development process
Benefits of Pseudocode

Design and Documentation

Rough Draft: Pseudocode serves as a preliminary sketch, helping to plan out the
app before actual coding begins

Documentation: It acts as rough documentation, making it easier for other
developers to understand the program and its logic


Efficiency and Time Savings

Simplification: Pseudocode helps simplify the design process by focusing on the
core logic, reducing the time spent on syntax and language-specific details

Easier Code Construction: It makes the actual code construction phase easier by
outlining the steps clearly

Modifiability

Easy Changes: Pseudocode is more readable and easier to modify compared to
flowcharts, making it a flexible tool for iterative development
Benefits of Pseudocode

Educational and Communication

Teaching Tool: Pseudocode is often used in educational settings to teach
programming concepts and algorithms, as it provides a clear and accessible way
to explain complex ideas

Communication: It is useful for explaining design decisions and complex
processes to non-technical staff, making it a valuable communication tool

Error Detection

Pre-Implementation: Pseudocode helps detect errors and feasibility issues before
actual coding begins, ensuring that the design is sound and can be implemented
correctly.
Pseudocode

Informal description of a computer program written in a symbolic code

Pseudocode is not a programming language

Doeds not require specifique sysntax

Each step of a pseudocode is written on a separate line

Written in sequence

Keywords are written in uppercase letters, variable s in lowercase letters
and messages (output) in senetence case
Pseudocode Examples

1. Write an algorithm and pseudocode 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.
Pseudocode Examples

1. Write an algorithm and pseudocode 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.
Pseudocode Examples

2. Write an algorithm and pseudocode to Calculate Area and Perimeter of
Rectangle
Algorithm Pseudocode

1. Start
2. Declare variables to store length (L) and width DECLARE length L
DECLARE width W
(W) of the rectangle
3. Prompt the user to enter the length and width of PRINT "Enter the length of the rectangle"
the rectangle READ L
PRINT "Enter the width of the rectangle"
4. Read the length (L) and width (W) values READ W
5. Calculate the area of the rectangle using the
formula: Area = L * W COMPUTE Area = L * W
COMPUTE Perimeter = 2 * (L + W)
6. Calculate the perimeter of the rectangle using
the formula: Perimeter = 2 * (L + W) PRINT "Area of the rectangle is:", Area
7. Display the calculated area and perimeter PRINT "Perimeter of the rectangle is:",
Perimeter
8. Stop
Pseudocode Examples

3. Write for me algorithm and a pseudocode to check if a number is positive or
negative
Algorithm Pseudocode

DECLARE number
1. Start PRINT "Enter a number"
2. Declare a variable to store the number READ number
IF number > 0 THEN
3. Prompt the user to enter a number PRINT "The number is positive"
4. Read the number into the variable ELSE IF number < 0 THEN
PRINT "The number is negative"
5. If the number is greater than 0 ELSE
1. Print "The number is positive" PRINT "The number is zero"
END IF
6. Else if the number is less than 0
1. Print "The number is negative"
7. Else
1. Print "The number is zero"
8. Stop
Pseudocode Examples

3. Write an algorithm and a pseudocode to find the biggest of three numbers:

Algorithm Pseudocode

1. Start DECLARE num1, num2, num3


2. Declare variables to store the three PRINT "Enter three numbers"
numbers (num1, num2, num3) READ num1, num2, num3
3. Prompt the user to enter the three numbers
IF num1 > num2 AND num1 > num3 THEN
4. Read the numbers into the variables num1, PRINT "num1 is the largest"
num2, num3 ELSE IF num2 > num1 AND num2 > num3 THEN
5. If num1 is greater than num2 and num3 PRINT "num2 is the largest"
ELSE
1. Print num1 is the largest PRINT "num3 is the largest"
6. Else if num2 is greater than num1 and END IF
num3
1. Print num2 is the largest
7. Else
1. Print num3 is the largest
Exercises
Problem 1: Write a pseudocode, to accept a user’s name and age and print a
comment based on the user’s input.
Problem 2: Write a pseudocode, to find the greatest among two and three numbers
Problem 3: Write a pseudocode, to find the sum of first 100 integers
Problem 5: Calculate Area and Perimeter of Rectangle
Problem 6: Check a Number is Positive or Negative
Problem 7: Find the sum of all elements of array
Problem 8 : Swap two variables with using a temporary variable (Simple Pseudocode
Example)
Problem 9 : Calculate the Sum and Average of n Number. (Pseudocode)
Problem 10 : Perform the application that calculates the area of the triangle whose
height and base length entered by the keyboard. (Pseudocode)
Problem 11 : What is the algorithm that finds and shows on the screen tha the water is
in the form of solid, liquid or gaseous according to the temperature? (Pseudocode)
Flowchart Diagram

Read the flowchart pdf file

You might also like