0% found this document useful (0 votes)
29 views17 pages

Comptutational Thinking Notes

The document outlines a Year 8 computing unit focused on computational thinking, covering algorithms, flowcharts, pseudocode, and searching algorithms. It includes learning objectives, definitions, advantages and disadvantages of flowcharts and pseudocode, as well as comparisons between linear and binary search methods. Key concepts such as iteration, subroutines, and the importance of efficient coding practices are also discussed.

Uploaded by

zoeadler1910
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)
29 views17 pages

Comptutational Thinking Notes

The document outlines a Year 8 computing unit focused on computational thinking, covering algorithms, flowcharts, pseudocode, and searching algorithms. It includes learning objectives, definitions, advantages and disadvantages of flowcharts and pseudocode, as well as comparisons between linear and binary search methods. Key concepts such as iteration, subroutines, and the importance of efficient coding practices are also discussed.

Uploaded by

zoeadler1910
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/ 17

Computing Year 8

UNIT 1 – Computational thinking

Subtopics: -

1. Algorithms
2. Flowcharts
3. Pseudocodes
4. Characteristics of pseudocode
5. Searching algorithms
6. Binary Search
7. AND, OR and NOT to create logic within algorithms

Learning Objectives :
1. Follow, understand, edit and correct algorithms that are presented as pseudocode.
2. Follow flowchart or pseudocode algorithms that use loops.
3. Know how to create algorithms using flowcharts and pseudocode.
4. Know how to use predefined sub-routines in flowcharts or pseudocode.
5. Describe and use binary searches.
6. Understand and use iteration statements, limited to count-controlled loops, presented as either flowcharts or pseudocode.
7. Predict the outcome of algorithms that use iteration.
8. Compare and contrast algorithms designed for the same tasks to determine which is best suited to the purpose.
9. Combine multiple constructs (sequence, selection, count-controlled iteration) to write algorithms as flowcharts or
pseudocode.
1. Algorithm

An algorithm is simply a set of steps used to complete a specific task. They're the building blocks for programming, and they
allow things like computers, smartphones, and websites to function and make decisions.

What is the need for algorithms?

1. Algorithms are necessary for solving complex problems efficiently and effectively.
2. They help to automate processes and make them more reliable, faster, and easier to perform.
3. Algorithms also enable computers to perform tasks that would be difficult or impossible for humans to do manually.
4. They are used in various fields such as mathematics, computer science, engineering, finance, and many others to
optimize processes, analyze data, make predictions, and provide solutions to problems.

• Clear and Unambiguous: The algorithm should be unambiguous. Each of its steps should be clear in all aspects
and must lead to only one meaning.
• Well-Defined Inputs: If an algorithm says to take inputs, it should be well-defined inputs. It may or may not
take input.
• Well-Defined Outputs: The algorithm must clearly define what output will be yielded and it should be well-
defined as well. It should produce at least 1 output.
• Finite-ness: The algorithm must be finite, i.e. it should terminate after a finite time.
• Feasible: The algorithm must be simple, generic, and practical, such that it can be executed with the available
resources. It must not contain some future technology or anything.
• Language Independent: The Algorithm designed must be language-independent, i.e. it must be just plain
instructions that can be implemented in any language, and yet the output will be the same, as expected.
2. Flowcharts

A flowchart is a pictorial representation of a sequence of instructions that are required to solve a problem.
One way of representing algorithms is to use flow charts, also called flow diagrams. They are a useful way of planning how a
computer program might work and show others your thinking.

Rules For Creating Flowchart :

A flowchart is a graphical representation of an algorithm.it should follow some rules while creating a flowchart
Rule 1: Flowchart opening statement must be ‘start’ keyword.
Rule 2: Flowchart ending statement must be ‘end’ keyword.
Rule 3: All symbols in the flowchart must be connected with an arrow line.
Rule 4: The decision symbol in the flowchart is associated with the arrow line.

Advantages of Flowchart:

• Flowcharts are a better way of communicating the logic of the system.


• Flowcharts act as a guide for blueprint during program designed.
• Flowcharts help in debugging process.
• With the help of flowcharts programs can be easily analyzed.
• It provides better documentation.
• Flowcharts serve as a good proper documentation.
• Easy to trace errors in the software.
• Easy to understand.
• The flowchart can be reused for inconvenience in the future.
• It helps to provide correct logic.

Disadvantages of Flowchart:

• It is difficult to draw flowcharts for large and complex programs.


• There is no standard to determine the amount of detail.
• Difficult to reproduce the flowcharts.
• It is very difficult to modify the Flowchart.
• Making a flowchart is costly.
• Some developer thinks that it is waste of time.
• It makes software processes low.
• If changes are done in software, then the flowchart must be redrawn
Types of Flowcharts
Pseudocodes

Pseudocodes

Pseudocode is used to design the programmings and do dryrun to check whether the programs run properly or not.

Values are assigned to an item/variable using the assignment operator


Example:

FlightCost ← 15 Flight cost value is 15

FlightPrice ← FlightCost * 1.5 FlightPrice value is FlightCost*1.5

Amount← 20 Amount is 20

TotalPrice← Amount*FlightPrice TotalPrice value is Amount*FlightPrice

Pilot← “James” Pilot value is “James”

Message← “Hi I am” + Pilot Message value is “Hi I am” + Pilot

Advantages of Pseudocode

• Improves the readability of any approach. It’s one of the best approaches to start implementation of an algorithm.
• Acts as a bridge between the program and the algorithm or flowchart. Also works as a rough documentation, so the
program of one developer can be understood easily when a pseudo code is written out. In industries, the approach of
documentation is essential. And that’s where a pseudo-code proves vital.
• The main goal of a pseudo code is to explain what exactly each line of a program should do, hence making the code
construction phase easier for the programmer.
• What is pseudocode?
Answer: A form of representing an algorithm without a set syntax.
• When is pseudocode used?
Answer: When planning or designing algorithms.
• Why is pseudocode used?
Answer: It is language independent so anyone should be able to understand it.
• What features does pseudocode contain?
Answer: Command words, assignment symbols, mathematical symbols

Flowcharts and pseudocode algorithms that use conditional statements

What are the key words used in conditional statements in programming?

Answer: IF, THEN, ELSE


What are the different symbols that can be used for comparisons?

Answer: >, <, >=, <=, <> =


Example of flowchart that use conditional statements

Example of pseudocode, to suit Python, for an IF statement:

if condition:

Code to run if true

else:

Code to run if false


Flowchart or pseudocode that use loops.(Refer to pseudocode guide also)

A count-controlled loop, or FOR loop, iterates the number of times specified in the The variable used in the FOR statements has a starting value,
and then counts from that number to the end value.

Format of a FOR loop that is suitable for Python programming language:


for variable in range (start, end):
code

Loops/Repetition/Iteration in a program is a piece, or section, of code that runs more than once

FOR loop the four elements are given in one line, for example:

for count in range(0, 10) gives

• the variables (count)


• the start value (0)
• the end value (10)
• and for indicates the incrementing

When using count-controlled loops in flowcharts a variable needs to be declared with a start value, for example: count = 0

The value will need to be checked against the end value, for example: if count = 10

The value will need to be incremented (increased) each time through the loop, for example: count = count + 1

In a flowchart these need to be separated and placed in the correct position, for example:
Key features of the count-controlled iterations in the flowchart:

• the variable declared before the loop


• the start value given before the loop
• the selection used to check the variable value
• the incrementing the value within the loop

Draw a flowchart to print/output the numbers 1 to 100


What is repetition in an algorithm?

Answer: A piece of code run more than once

What is a count-controlled loop?

Answer: Code that runs a set number of times

When can a count-controlled loop be useful in algorithms?

Answer: When something has to happen a set number of times

What are the key features of a count-controlled loop?

Answer: A counter with a starting value, an end value and an increment.

What is iteration?

Answer: Code that repeats multiple times.

What is special about a count-controlled loop?

Answer: It runs a set number of times.

Subroutines

• Sub-routine is a self-contained program that that can be called from other programs
• Sub-routines can be used multiple times in an algorithm and can be used across different algorithms.

Advantages of Subroutines

• You do not need to write the same code every time it is used
• Each small programme or algorithm only has to be written once but can be used many times within a larger programme or algorithm.

Flowchart subroutine that converts Celsius to Fahrenheit:


Flowchart that makes use of the subroutine, for example:
What is a subroutine?

Answer: A section of code with a name that can be called from another program.

How do you call a subroutine in a flowchart or pseudocode?

Answer: Use its identifier.

Searching Algorithms
A very common task that computers need to perform is searching for an item in a list. Many highly optimised search algorithms have
been created, as companies like Google rely on effective searching algorithms all of the time. There are two basic searching
algorithms that you need to be aware of:

1. Linear Search
2. Binary Search

Linear Search
The most basic search is called a linear search. You can think of a linear search as simply starting at the beginning of a list and checking
each item until you find the thing you are looking for.
Linear Search, also known as Sequential Search, is a straightforward method for finding a particular element within a list. It sequentially
checks each element in the list until a match is found or the whole list has been searched.

Binary Search
A binary search is a way of looking for a piece of data in an ordered list by continually splitting the list in half. You then check the
middle number and work out which half of the list the value to find it.

To find a number from given list of numbers using Binary Search algorithm:

• Compare the number with the middle number, for example:


• if not equal then:
o select the numbers to the left if it is less than the middle number
o select the numbers to the right if it is greater than the middle number
o discard the remaining numbers.
• repeat this process until the correct number has been found or until there are no elements left.

➢ Binary search is a much more efficient way of searching through a list of items compared to a linear search.
➢ However, you can only use a binary search algorithm if the data is ordered i.e. smallest to largest.
➢ If the data that you have is unordered, you must either use a linear search algorithm or sort the data first.

Difference Between Linear and Binary Search: Linear vs Binary Search

Parameters Linear Search Binary Search

Linear Search sequentially checks each element Binary Search continuously divides the sorted list,
Definition in the list until it finds a match or exhausts the comparing the middle element with the target
list. value.

Efficiency Less efficient, especially for large datasets. More efficient, especially for large datasets.

Data In a linear search, the elements don't need to be The pre-condition for the binary search is that the
Requirement arranged in sorted order. elements must be arranged in a sorted order.

Size It is preferrable for the small-sized data sets. It is preferrable for the large-size data sets.

Eliminates half of the search space with each


Search Space Examines each element sequentially.
comparison.

Use Case Suitable for small and unsorted datasets. Ideal for large and sorted datasets.
There are some elements that impact the efficiency of a program, for example:

• number of lines of code (which impacts the file size)


• number of variables used (which impacts the memory usage).

Here are two different codes for each feature, such as two codes that solve the same problem but where one uses many more variables and
lines. For example:

Problem: Take 3 numbers as input, add them together and output the result.

Code 1:
number1 = input("Enter a number")
number2 = input("Enter a number")
number3 = input("Enter a number")
value1 = number1 + number2
total = number3 + value1
print(total)

and

Code 2:
number1 = input("Enter a number")
number2 = input("Enter a number")
number3 = input("Enter a number")
print(number1 + number2 + number2)

• The second program uses fewer lines of code which means the file size will be smaller.
• It also has one less variable therefore, when running, it will use less memory.

You might also like