KEMBAR78
Ct2 Notes 6ab | PDF | Algorithms | Debugging
0% found this document useful (0 votes)
4 views6 pages

Ct2 Notes 6ab

The document provides an overview of algorithms and data, explaining that algorithms are step-by-step procedures for solving problems, while data consists of raw facts used as input or output. It discusses the importance of predicting algorithm outcomes, flowcharts for visualizing processes, and the use of subroutines for reusable code. Additionally, it highlights the advantages and limitations of flowcharts, along with common errors and their fixes.

Uploaded by

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

Ct2 Notes 6ab

The document provides an overview of algorithms and data, explaining that algorithms are step-by-step procedures for solving problems, while data consists of raw facts used as input or output. It discusses the importance of predicting algorithm outcomes, flowcharts for visualizing processes, and the use of subroutines for reusable code. Additionally, it highlights the advantages and limitations of flowcharts, along with common errors and their fixes.

Uploaded by

nagpalsanjna1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

CT-2 Notes

Name:_________________ Grade: 6
Subject: Computer Science

Algorithm and Data

What is an Algorithm | Introduction to Algorithms


An algorithm is a step-by-step procedure or set of rules designed to solve a specific
problem or perform a specific task.

It takes some input, processes it through a sequence of well-defined instructions, and


produces an output.

Example:

To add two numbers:

1. Start

2. Input number A

3. Input number B

4. Add A and B → Store result in C

5. Output C

6. End

This is a simple algorithm for addition.

What is Data?

Data refers to raw facts or information that algorithms use as input or produce as output.

Example: Numbers like 5, 10, or a list like [3, 8, 1, 7] are data. In real-world terms, it could
be customer names, sales numbers, temperature readings, etc.

Relationship Between Algorithm and Data

Algorithm Data

Tells how to do something Tells what to do it on

The input/output of those


A set of rules/instructions
rules

Is processed by
Operates on data
algorithms

Analogy:
Think of an algorithm as a machine and data as the fuel. The machine (algorithm) processes
the fuel (data) to give you a result.

"An algorithm is like a machine, and data is the fuel."

 Machine = Algorithm (it does the work)

 Fuel = Data (it powers the process)


This analogy helps you understand how algorithms and data work together.

Predicting the Outcome of an Algorithm

Predicting the outcome of an algorithm means figuring out what result or output the
algorithm will produce when given a specific input.

Why It's Important:

 Helps in debugging and understanding code.

 Essential for testing and analyzing algorithms.

 Key in exams and interviews when you're asked, "What will this algorithm return?"

General Steps to Predict the Outcome:

1. Understand the Algorithm


Know what task it's supposed to do (e.g., sort, search, add).

2. Follow the Steps


Apply the algorithm to the given input, step by step.

3. Track Values
Use a table or list to keep track of changing variables or data.

4. Determine the Output


Look at the result after the algorithm finishes processing.

5. Example Algorithm: Find Greater of Two Numbers


Algorithm Greater Number
Input: Two numbers A and B
Output: The greater number

1. If A > B:
Return A
2. Else:
Return B

Example 1:
Input: A = 15, B = 10
Step: 15 > 10 → return 15
Output: 15

 What is a Flowchart?
 A flowchart is a visual representation of a process, algorithm, or system using
symbols and arrows.
It shows the logical flow of steps in a process from start to end.

 It helps in planning, designing, analyzing, and communicating how a program or


system works.

 Why Use Flowcharts?

 Uses:

 Design algorithms
 Document business processes

 Explain program logic

 Debug logical errors

 Teach programming or process design

 Key Flowchart Symbols (Expanded)


 Symbol  Name  Function

Represents the beginning or end of


Oval Start/End
a flow
Parallelogram Input/Output Shows data input or output
Rectangle Process Indicates an action or operation
Diamond Decision A condition that branches (Yes/No)
Arrow Flowline Shows direction of process flow

 Rules for Making Flowcharts

 Start and End with an oval symbol.

 Keep flow top to bottom or left to right.

 Use arrows to show the correct direction.

 Only one entry and exit point per symbol.

 Label decision branches (Yes/No or True/False).

 Keep it clear and simple — avoid too much clutter.

 Use meaningful names for processes or variables.

 Advantages of Flowcharts

 ✔ Makes logic easy to understand

 ✔ Useful for problem-solving

 ✔ Helps in debugging

 ✔ Aids in documentation

 ✔ Useful for team communication

 Limitations of Flowcharts
 ❗ Can become complex for large problems

 ❗ Not suitable for minor changes (redrawing needed)

 ❗ Takes time to draw and update

 How to Find Errors in a Flowchart


 Finding errors in a flowchart means checking if the logic, sequence, symbols, or flow are
incorrect. This is very important before turning the flowchart into a program.

 ✅ Common Errors in Flowcharts (and How to Fix Them)


 ❌ Error Type  🔍 What to Check  Fix Tip

 Missing  Every flowchart must begin with  Add oval symbols at


Start/End Start and end with End symbols. start and end.

 Is a process shown with a


 Wrong symbol
rectangle? Is input/output a  Use correct symbols.
usage
parallelogram?

 A decision (diamond) must have


 No decision path two paths: Yes and No (or  Add both outcomes.
True/False).

 Are arrows missing or pointing


 Use arrows clearly,
 Unclear flow backward? Do lines cross
avoid confusion.
unnecessarily?

 Missing  Is user input or result output clearly  Use parallelograms


input/output shown? to show these.

 Review your
 Incorrect logic or  Steps in the wrong order or wrong
algorithm or logic
sequence calculations
first.

 Real-life Use Cases

 ATM withdrawal process

 Online shopping checkout

 Login validation system

 Traffic light control system

 Calculator logic
o Example 1-

 Example 1 Flowchart for adding two numbers


 Example 2 Flowchart for Greater in two numbers

What is a Subroutine?
A subroutine (also called a function, procedure, or method) is a reusable set of
instructions designed to perform a specific task within a program. Instead of repeating
code, you "call" a subroutine when you need it.

Example: Flowchart Using a Subroutine


Let’s say we want to design a process that:
1. Takes two numbers
2. Adds them
3. Outputs the result
We’ll use a subroutine for the addition.

Flowchart Steps:
1. Start
2. Input number A
3. Input number B
4. Call subroutine Add(A, B)
5. Output result
6. End

Subroutine: Add(A, B)
1. Return A + B

You might also like