0% found this document useful (0 votes)
5 views27 pages

Chapter 4 Problem Solving Chapter4

The document provides an introduction to problem solving, outlining key steps including analysis, algorithm development, coding, and testing. It explains the importance of algorithms, their characteristics, and various representations such as flowcharts and pseudocode. Additionally, it discusses control flow, verification methods, and the decomposition of complex problems into manageable sub-problems.

Uploaded by

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

Chapter 4 Problem Solving Chapter4

The document provides an introduction to problem solving, outlining key steps including analysis, algorithm development, coding, and testing. It explains the importance of algorithms, their characteristics, and various representations such as flowcharts and pseudocode. Additionally, it discusses control flow, verification methods, and the decomposition of complex problems into manageable sub-problems.

Uploaded by

arokyasundarisp
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Introduction to

Problem Solving
Chapter 4 | Class XI | Algorithm • Flowchart • Pseudocode • Decomposition
01 Steps for Problem Solving
PS
What is Problem Solving?

▸ Problem solving = Identifying a problem → Developing algorithm → Implementing program


▸ Computerisation: Using computers to automate routine human tasks efficiently
▸ Computers CANNOT solve problems on their own — they need precise instructions
▸ Success depends on: Correct problem definition + Proper algorithm design + Accurate
implementation

▸ Real-world example: Railway Reservation System


◦ • Complex task involving train details, schedules, berth types, simultaneous bookings
◦ • Computerisation made booking easy, accessible from anywhere, anytime
4 Key Steps of Problem Solving

ANALYSE Read & understand the problem statement. Identify principal components, inputs, and desired outputs.

ALGORITHM Develop a step-by-step solution in natural language. Refine until all aspects are captured.

CODING Convert algorithm into a programming language. Document the solution for future reference.

TEST & DEBUG Test on various parameters. Fix syntactical & logical errors. Iterate until correct output for all inputs.
02 Algorithm
A
Understanding Algorithms

▸ Algorithm = Finite sequence of steps to get desired output in finite time


▸ Has a definite beginning and definite end
▸ Examples from daily life: Getting ready for school, making breakfast, riding a bicycle

▸ Example: GCD of 45 and 54


◦ Step 1: Find divisors of 45 → 1, 3, 5, 9, 15, 45
◦ Step 2: Find divisors of 54 → 1, 2, 3, 6, 9, 18, 27, 54
◦ Step 3: Find largest common number → GCD = 9

▸ Origin: Named after Persian mathematician Al-Khwarizmi (c. 850 AD)


Why Algorithms? & Characteristics

Why We Need Algorithms Characteristics of Good Algorithm


▸ Roadmap before writing actual code ▸ Precision — steps are clearly stated
▸ Helps visualize instructions clearly ▸ Uniqueness — results depend only on input &
▸ Increases reliability, accuracy & efficiency previous steps
▸ Foundation of all computing: search engines, ▸ Finiteness — always stops after finite steps
messaging, banking, gaming ▸ Input — receives some input
▸ If algorithm is correct → program runs correctly ▸ Output — produces some output
every time ▸ Clearly identify: Input → Processing → Output
03 Representation of Algorithms
Flowchart Symbols

Start / End (Terminator) Process / Action Decision


Oval shape indicating where flow begins Rectangle representing a process, action, Diamond shape for yes/no or true/false
and ends or single step branching points

Input / Output Arrow / Connector Flow Lines


Parallelogram for data input or output Shows order of flow and connections Direct the sequence of operations from
operations between shapes one symbol to another
FC
Flowchart Examples

▸ Example 1: Find square of a number


◦ → Input number → Compute num × num → Store in 'square' → Print square

▸ Example 2: Fix a non-functioning light bulb


◦ → Check if plugged in → Check bulb → Check switch → Replace bulb / Call electrician

▸ Example 3: Sum of two numbers


◦ → Input num1 → Input num2 → Compute sum = num1 + num2 → Print Result
PC
Pseudocode

▸ Non-formal language to write algorithms for human reading (NOT executable)


▸ 'Pseudo' = not real → 'Pseudocode' = not real code
▸ No specific standard — flexible and readable

▸ Common Keywords:
◦ INPUT, COMPUTE, PRINT, INCREMENT, DECREMENT
◦ IF / ELSE, WHILE, TRUE / FALSE

▸ Example: Sum of two numbers


◦ INPUT num1
◦ INPUT num2
◦ COMPUTE Result = num1 + num2
04 Flow of Control
S
1. Sequence

▸ Statements executed one after another in order


▸ Simplest form of control flow — linear execution
▸ Examples 4.3 and 4.4 (sum, rectangle area) follow sequence

▸ Example: Calculate area & perimeter of rectangle


◦ INPUT length
◦ INPUT breadth
◦ COMPUTE Area = length × breadth
◦ PRINT Area
◦ COMPUTE Perim = 2 × (length + breadth)
◦ PRINT Perim
SEL
2. Selection (Decision Making)

▸ Choosing between alternatives based on a condition


▸ Uses IF-ELSE structure for binary (true/false) decisions

▸ Syntax:
◦ IF <condition> THEN
◦ steps when TRUE
◦ ELSE
◦ steps when FALSE

▸ Example: Check if number is Odd or Even


◦ IF number MOD 2 == 0 THEN
◦ PRINT 'Even'
EX
Selection Examples

▸ Example: Age categorization (Child / Teenager / Adult)


◦ IF Age < 13 → 'Child'
◦ ELSE IF Age < 20 → 'Teenager'
◦ ELSE → 'Adult'

▸ Example: Card Game — Dragons vs Wizards


◦ IF (diamond OR club) → Dragons get point
◦ ELSE IF (heart AND number) → Wizards get point
◦ ELSE IF (heart AND not number) → Dragons get point
◦ ELSE → Wizards get point

▸ Key: Conditionals check possibilities using binary (true/false) values


R
3. Repetition (Loops / Iteration)

▸ Executing steps repeatedly until a condition is satisfied


▸ Also known as: Iteration, Looping

▸ Two types:
◦ • Fixed repetition — known number of times (e.g., clap 5 times)
◦ • Conditional repetition — unknown times, until condition met (e.g., walk till crossing)

▸ Example: Average of 5 numbers (counter-controlled)


◦ SET count = 0, sum = 0
◦ WHILE count < 5: INPUT num, sum = sum + num, count = count + 1
◦ COMPUTE average = sum / 5
◦ PRINT average
05 Verifying Algorithms
V
Dry Run — Verifying Algorithms

▸ Critical for banking, medical, space software where errors are catastrophic
▸ Method: Take different input values and manually trace through all steps
▸ Also called 'Dry Run' — simulating execution without a computer

▸ Benefits of Dry Run:


◦ 1. Identify incorrect steps in the algorithm
◦ 2. Figure out missing details or specifics

▸ Example: Adding time (hours + minutes)


◦ T1 = 5h 20m + T2 = 7h 30m → 12h 50m ✓
◦ T1 = 4h 50m + T2 = 2h 20m → 6h 70m ✗ (should be 7h 10m)
◦ → Algorithm needs fix: IF minutes ≥ 60, add 1 to hours, subtract 60 from minutes
06 Comparison of Algorithms
C
Comparing Algorithms

▸ Multiple algorithms can solve the same problem — which is better?


▸ Example: Check if a number is PRIME

▸ Four approaches:
◦ (i) Test all divisors from 2 to n-1 — MOST calculations, SLOWEST
◦ (ii) Test up to n/2 — fewer calculations, faster
◦ (iii) Test up to √n — even fewer, more efficient
◦ (iv) Use pre-stored prime list — least calculations, needs EXTRA memory

▸ Comparison Criteria:
◦ • Time Complexity — processing time required to run
◦ • Space Complexity — memory needed to execute
07 Coding
CD
From Algorithm to Code

▸ Final step: Convert algorithm into high-level programming language


▸ Syntax = rules/grammar governing statements (spelling, order, punctuation)

▸ Levels of Programming Languages:


◦ • Machine Language (0s & 1s) — directly understood by hardware, hard for humans
◦ • High-Level Languages — close to natural language, portable across computers
◦ • Assembly Languages — for embedded systems (watches, traffic signals, medical equipment)

▸ Popular High-Level Languages: FORTRAN, C, C++, Java, Python


▸ Source code → translated by Compiler or Interpreter → Machine language

▸ Choice depends on: Platform (OS), Application type (desktop/mobile/web/embedded)


08 Decomposition
D
Decomposition: Divide and Conquer

▸ Breaking complex problems into smaller, manageable sub-problems


▸ Spirit: 'Divide and Conquer' — Howard Raffa

▸ Example: Railway Reservation System


◦ → Trains information (schedules, classes, berths)
◦ → Reservation info (booking, waiting list, cancellation)
◦ → Staff & infrastructure management
◦ → Billing services
◦ → Food services

▸ Advantages:
◦ • Each sub-problem examined in detail
S
Chapter Summary

▸ Algorithm = Step-by-step procedure with definite beginning, end, and finite steps
▸ Characteristics: Precision, Uniqueness, Finiteness, Input, Output
▸ Representation: Flowcharts (visual) and Pseudocode (textual)
▸ Flow of Control: Sequence → Selection → Repetition
▸ Selection uses IF-ELSE for decision making based on conditions
▸ Repetition (loops) handles repeated tasks: counter-controlled & condition-controlled
▸ Verification via Dry Run — trace algorithm manually with test inputs
▸ Compare algorithms using Time Complexity & Space Complexity
▸ Coding: Convert algorithm to high-level language, compile/interpreter to machine code
▸ Decomposition: Break complex problems into simpler sub-problems solved independently
E
Practice Exercises

▸ 1. Pseudocode: Divide two numbers and display quotient


▸ 2. Algorithm: Coin flip game — first to win 3 out of 5 flips wins cake
▸ 3. Print all multiples of 5 between 10 and 25
▸ 4. Example of a loop executed a fixed number of times
▸ 5. Collect ₹200 from people giving ₹10, ₹20, or ₹50
▸ 6. Print bill with GST (5% tax) based on price × quantity
▸ 7. Calculate aggregate & percentage for 3 subjects (CS, Math, Physics)
▸ 8. Find greatest among two different numbers
▸ 9. Color word based on number range (5-15: GREEN, 15-25: BLUE, etc.)
▸ 10. Find largest & smallest of four input numbers
▸ 11. Water bill: ₹5/unit (first 100), ₹10/unit (next 150), ₹20/unit (>250) + ₹75 meter charge
Thank You!
Questions & Discussion | Introduction to Problem Solving

You might also like