Lesson 5: Basics of Algorithm and Flowchart

Lesson Description

In this lesson, you will learn what an algorithm is and how to use a flowchart to represent a set of steps to solve a given problem. They will also learn about the different symbols used in a flowchart.

Knowledge Box

While reading a book in a school library, Mukesh comes across a word that says “draft” whose meaning he does not know. So how does he find out the meaning of this word?

The simple answer to this is that Mukesh searches for the meaning of the word ‘draft’ in a dictionary. However, there are many words in a dictionary. So how does he find the word ‘draft’ in the dictionary?

To achieve this, he first needs to find the dictionary section with the first letter of the word, which in this case is ‘D.’ Then, within the list of words starting with the first letter ‘D’, he needs to find the section having the second letter of the word ‘R’. He needs to do this operation again with the third, fourth & fifth letters until he finally reaches the word ‘draft’ in the dictionary & then finds its meaning.

In other words, Mukesh needs to follow a set of steps to complete the task of finding the meaning of a word.

Similarly, before writing a program code for a given problem in computer science, it is essential to devise a set of steps to be followed to solve the problem successfully. This set of steps is called an algorithm.

An algorithm is defined as the CODING STEPS plan to solve the problem for a given problem statement.

Flowchart

A flowchart is a diagrammatic representation of the CODING STEPS plan to be followed for solving a task/problem statement.

This diagrammatic representation is made up of shapes like boxes, diamonds, parallelograms, circles, and ellipses connected by arrows. Each shape acts as a step in the solution, and the arrows represent the direction of flow among the steps.

Benefits of using a flowchart:

  1. It helps to explain your approach to solving a problem.
  2. The flowchart helps in bringing visual clarity to a problem, so it helps in practical problem-solving.
  3. Once you build a flowchart, this remains as documentation of the code you are about to build. If you need to come back and understand the code, you can refer to the flowchart.

Symbols Used in a Flowchart

S No Symbol Name Definition Image
1 Terminal Indicates start/stop / halt
2 Input / Output Indicates instructions that either take inputs or display output.
3 Processing Indicates instructions that represent computation.
4 Decision Indicates decision-based operations such as Yes/No, or True/False.
5 Connectors Complex flowcharts which span over more than a page are connected via a connector.
6 Flow lines Indicates the direction of flow of sequence in a flowchart.

Activity 1: Profit & Loss

Let’s create a flowchart that takes two inputs, namely cost price, and selling price. It then calculates profit or loss depending on the values and prints the same.

Steps

Follow the steps below:

  1. Taking inputs – cost price and selling price from the user at the start.
  1. Create branches with identification of the profit and loss with the decision.
  2. Calculate the profit and loss values. Your flowchart is complete.

Activity 2: Eligible for Vote

Let’s create a flowchart that takes one input as age. It then checks if the person is eligible for voting or not.

Activity 3: Beating Hearts

In this activity, we’re going to see how we can display a custom pattern on the matrix by making a script to display a beating heart.

Coding Steps

Follow the steps below:

  1. Open PictoBlox App, go to My Space, and click on + button to create a new file.
  2. Connect Quarky to PictoBlox.
  3. Drag and drop a when flag clicked block into the scripting area from the Events palette.
  4. Add a forever block from the Control palette below the when flag clicked block.
  5. Inside the forever block, add a display matrix as () block from the Display palette.
  6. Open the drop-down by clicking on the tiny white arrow as shown in the image. Draw a small heart in the middle of the matrix.
  7. Add a wait () seconds block under the display matrix as () block and set the waiting time as 2 seconds.
  8. Now, add another display matrix as () block and draw a bigger heart in the matrix as shown in the image.
  9. Add another wait () seconds block under the display matrix as () block and set the waiting time as 0.2 seconds.
  10. And there you go! Quarky’s heart beats only for you! Save the file as Beating Heart.

Make sure you finish and submit the assignment, as well as take the quizbefore moving on to the next lesson.

 

Table of Contents