Grade 7ict Algorithm and Data
Grade 7ict Algorithm and Data
●
An algorithm gives a solution to a particular
problem as a well defined set of steps
Algorithm
●
A computer program is a collection of
instructions that performs a specific task when
executed by a computer.
●
A computer programmer (coder) is a person
who writes computer programs (softwares)
Pseudo code
●
Pseudo code: is a high level description of a
program or algorithm that uses simple English
like statement to outline the basic logic of a
program.
Pseudo code
●
In order to write pseudo code follow those steps
1)Understand the problem
2)Break down the problem into smaller steps
3)Write out the pseudo code
4)Test the pseudo code
5)Translate the pseudo code into actual code using
your programming language of your choice.
Flowchart
●
A flowchart is a pictorial representation of an
algorithm in which the steps are drawn in the form
of different shapes of boxes and the logical flow is
indicated by interconnecting arrows.
Flowchart symbols
.
Symbol Name Function
. Terminal
Indicates the starting or ending of the
program, process, or interrupt program
● https://excalidraw.com/
Solution activity 2(algorithm)
1)Start
2)Read the number and store it in variable N.
3)Check if N % 2 == 0.
4)If the remainder is 0, then N is even.
5)Otherwise, N is odd.
6)Display "Even" if the number is even; otherwise,
display "Odd."
7)End
Solution activity 2(Flowchart)
Activity 3
● Write an algorithm and draw a flowchart to find the
area of a rectangle?
● https://excalidraw.com/
Activity 4
● Write an algorithm and draw a flowchart to find the
product of any two number?
Activity 5
● Write an algorithm and draw a flowchart that will
check weather a number is positive, negative or
zero?
Construct(7c2)
1)construct is a fundamental element or building
block used in programming, algorithms, or logical
reasoning to define the structure, behavior, and
flow of a program or process.
2)Constructs represent basic concepts, patterns, or
mechanisms that allow us to organize and control
the execution of instructions.
Construct
1) Programming Construct:-
programming construct is a structure used to control the
flow of a program.
This can include:
Control flow constructs:
Statements that determine how a program executes (e.g.,
loops, conditionals like if-else, and switch).
Data constructs:
Ways to organize and store data (e.g., arrays, lists,
dictionaries).
Construct
Example
1)Conditional construct:-
for i in range(5):
print(i)
Conditional Statements
●
Conditional statements:- allow a program to
execute certain actions based on whether a
specific condition is true or false.
●
They enable decision-making in code, controlling
the flow of execution.
Conditional Statements
1)if Statement: Executes a block of code if the
condition is true.
2)else Statement: Executes a block of code if
the if condition is false.
3)elif (else if) Statement: Checks additional
conditions if the previous if condition is false.
4)nested if: An if statement within another if
statement.
Example
1)number = 10
2)if number > 0:
3) print("Positive")
4)elif number == 0:
5) print("Zero")
6)else:
7) print("Negative")
Searching
1)Searching in an algorithm:- refers to the
process of finding a particular element or value
within a given data set or structure, such as an
array, list, or database.
2)The primary goal is to locate the position of the
target element or determine if it exists within the
data. Searching is a fundamental operation in
computer science, used in many applications
ranging from database queries to finding
records in data structures.
Linear Searching
●
Linear search:- is one of the simplest searching
algorithms, which checks each element of a list or an
array sequentially until it finds the target value or
reaches the end of the list. It is a basic search method
used when the list is unsorted or small.
Linear Searching
How Linear Search Works
1)Start from the first element in the list.
2)Compare the target element (the element you are
searching for) with the current element.
3)If they match, return the index of the element.
4)If they don't match, move to the next element.
5)Repeat this process until you find the target
element or reach the end of the list.
6)If the element is not found in the entire list, return
a value indicating that the element doesn't exist
(usually -1 or None).
Cont ...
1)Steps of Linear Search (in pseudocode):
2)Start from the first element of the array.
3)Compare the current element with the target
element.
4)If the current element matches the target, return the
index.
5)If it does not match, move to the next element.
6)Repeat steps 2-4 until the end of the array is
reached.
7)If the end is reached without finding the target,
return a signal (like -1) indicating the target is not
found.