L
LLLOS.ai
Learn
L

Chapter 3 — Algorithms and Flowcharts

Class 8 · Computer Studies

Overview

This unit introduces students to algorithms and flowcharts, the foundation of problem solving in computer studies. It explains what an algorithm is, how to write clear step-by-step instructions, and how to represent those instructions visually with flowcharts. The unit covers basic programming constructs — sequence, selection (decision), and iteration (loops) — and shows how to convert everyday problems into algorithms and flowcharts. Students learn common flowchart symbols, rules for drawing correct diagrams, and simple pseudocode notation to plan solutions before coding. Emphasis is on logical thinking, accuracy, and tracing the steps to predict outcomes. Learning these skills helps students break complex tasks into manageable parts, reason systematically, and communicate solutions clearly. These abilities are useful not only for later programming topics but also for mathematics, science, and daily decision-making. By the end of the unit, students will be able to design algorithms for simple tasks such as finding the largest of numbers, computing sums, and checking conditions, draw corresponding flowcharts, follow and debug given flowcharts, and translate between flowcharts, pseudocode, and plain English instructions.

Learning Objectives

  • Describe what an algorithm is and explain why algorithms matter in computing and daily life.
  • Identify and use common flowchart symbols to represent steps of a process.
  • Write simple algorithms in clear step-by-step form and in basic pseudocode.
  • Construct flowcharts for problems using sequence, selection and iteration.
  • Trace (execute manually) an algorithm or flowchart to find outputs for given inputs.
  • Convert a flowchart into pseudocode and a short English description, and vice versa.
  • Detect and correct logical errors in algorithms and flowcharts through dry runs.
  • Apply algorithmic thinking to solve classroom problems such as sums, comparisons and repeated actions.

Topics in this chapter

12 topics · tap a topic title to jump straight to it.

💻1

What is an Algorithm and Its Characteristics

Definition and meaning: An algorithm is a precise, step-by-step method to solve a problem or perform a task. It describes each needed action, the order to do them in, and the expected output for given inputs. An algorithm can be written as a list of steps, expressed as pseudocode, or represented visually as a flowchart.

Why clarity matters: Each step in an algorithm must be clear and unambiguous. If a step can be interpreted in more than one way, different people or machines may produce different results. For example, the instruction "arrange the books" should be replaced by "arrange books in alphabetical order by title" to be definite.

Key properties: A good algorithm must be finite — it must finish after a limited number of steps. It must be effective — each step should be simple enough to be carried out exactly. It should specify inputs and outputs clearly. Correctness is essential: for every valid input the algorithm should produce the intended output. Finally, while not the main focus in Class 8, efficiency is desirable; it means using fewer steps or less time to reach the answer.

Examples to understand properties: A recipe to make toast is an algorithm: inputs (bread, toaster), steps (insert bread, press lever, wait), and output (toasted bread). A vague instruction like "keep stirring until ready" is not good unless "ready" is defined by time or a visible sign. Always check whether an algorithm finishes for all allowed inputs — if it depends on a condition that never becomes false, the algorithm will not be finite.

Testing and improvement: After writing an algorithm, test it by doing a dry run using sample inputs, including typical and boundary cases (such as zero or equal numbers). If the result is incorrect, trace where steps failed and revise. Practising this builds logical reasoning and prepares students for coding in later classes.

📌 Examples
  • Recipe for a sandwich: list ingredients and precise actions to make it.
  • Finding larger of two numbers: compare them and pick the larger.
  • Calculating sum of first n numbers by adding each number from 1 to n.
🧮 Formulas
  1. An algorithm must be definite, finite, and effective.
📊 Visual ideas
Draw a simple list with numbered steps showing a small task like tying shoelaces
💻2

Steps to Write an Algorithm

Understand the problem: Before you write any steps, read the problem carefully. Ask: what inputs are given? What result is expected? Write the problem in your own words to ensure you understand it correctly. Identify special cases that might need attention, such as equal values or zero.

Select inputs and outputs: Decide exactly which values the algorithm must read and which values it should produce. For example, to find the average of marks, inputs are the list of marks and number of students; the output is the calculated average.

Break the task into main steps: Think of how you would do the task yourself. Write the big steps in order. For instance: read values, process them (such as add or compare), and then display the result. Keep each step small and focused so it is easy to test.

Refine steps into detailed actions: Replace vague actions with specific instructions. Instead of "process the list", write "for each element in the list add element to total". If repetition is needed, indicate how many times it will repeat or state the condition that ends the repetition. If decisions are needed, state the condition clearly, e.g., "if score >= 35 then pass else fail".

Choose a representation: Write the algorithm as numbered steps, use pseudocode, or draw a flowchart. Choose the representation that makes the logic clearest for the problem and for your own style. Pseudocode is good for outlining logic; flowcharts help visualise the flow of control.

Dry run and test: Use sample inputs, including edge cases, and follow the steps by hand recording variable values. If the result differs from expectations, find the step where the logic broke and rewrite it. Repeat testing until the algorithm works for all tested inputs. Keep refining to improve clarity and, when appropriate, efficiency.

📌 Examples
  • Plan to find largest among three numbers: compare first two, compare winner with third.
  • Plan to count how many students passed: examine each mark and increment counter when mark >= pass mark.
📊 Visual ideas
A stepwise numbered list illustrating the algorithm writing process from understanding to testing
💻3

Introduction to Flowcharts

What is a flowchart: A flowchart is a visual diagram showing the steps and decisions of an algorithm. It uses standard shapes for specific kinds of actions and arrows to show the order of execution. Flowcharts make the flow of control and choices easy to follow at a glance.

Why use flowcharts: They help to plan and communicate solutions clearly. For learners, drawing a flowchart before coding makes it easier to find missing steps, spot logic errors, and discuss the approach with classmates or teachers. A flowchart also serves as a simple documentation of how a program or process works.

How to begin drawing: Start with the oval Start symbol, then draw shapes for inputs, processes and decisions in the order they occur. Connect shapes with arrows. Place a Stop symbol where the algorithm ends. Keep the diagram flowing from top to bottom or left to right so it is intuitive for a reader.

Use in planning and debugging: A well-made flowchart can be translated into code or pseudocode. While tracing by hand, the flowchart shows the path of execution clearly and helps to test different paths. For example, if a decision splits into two outcomes, follow each path with suitable test inputs to ensure both lead to correct results and eventually to Stop.

Limitations and good practice: Flowcharts are excellent for small to medium problems but can become large for complex systems. Use modular design by splitting a large problem into small sub-flowcharts. Keep labels short, use standard symbols, and redraw messy charts for clarity. With practice, converting algorithms into flowcharts and back becomes fast and reliable, preparing students for programming tasks later on.

📌 Examples
  • Flowchart to add two numbers and display the sum.
  • Flowchart to check whether a number is even or odd.
📊 Visual ideas
A simple flowchart showing Start -> Input numbers -> Add -> Output -> End
💻4

Basic Flowchart Symbols

Symbols you must know: Flowcharts depend on a small set of standard symbols that communicate different kinds of steps. The Start/Stop symbol is an oval and marks where the process begins or ends. The Input/Output symbol is a parallelogram and is used for reading input values or displaying results. The Process symbol is a rectangle and stands for operations such as calculations or assignments. The Decision symbol is a diamond and represents a test that yields two or more branches, commonly yes/no or true/false. The Connector is a small circle used to join parts of a chart or continue the flow on another page.

How to use the symbols: Place the right symbol for each action; do not use a rectangle for a decision or a diamond for input. Inside each shape use short, precise text: in a rectangle write statements like "sum = sum + i"; in a parallelogram write "Read n" or "Write result"; in a diamond write a condition such as "i <= n?". Label the arrows leaving a decision with outcomes such as "Yes" and "No" if the path is not obvious from context.

Combining symbols for structure: A loop is drawn by using a decision diamond to check the loop condition and an arrow that returns to an earlier process. For count-controlled loops, show initialization, decision check, process inside the loop, update step, and the arrow back to the check. Use connectors when the diagram becomes large to avoid crossing lines and to keep the flow tidy.

Practice drawing neatly: Teachers expect correct shapes, readable text, and clear arrows. Practice by drawing each symbol and writing examples inside them. Understanding and using these symbols correctly will make your flowcharts unambiguous and easier to convert into pseudocode or code later.

📌 Examples
  • Use parallelogram for reading a number and rectangle for computing its square.
  • Use diamond to check if score >= pass_mark and branch to Pass/Fail outputs.
📊 Visual ideas
Draw and label the five symbols: Start/Stop oval, Input/Output parallelogram, Process rectangle, Decision diamond, Connector circle
💻5

Rules for Drawing Flowcharts

Follow standard rules: A flowchart must be clear, logical and complete. Use standard symbols and place Start at the top (or left) and Stop at the end. Each shape should contain a short phrase describing the action. Avoid long sentences; use concise statements such as "i = i + 1" or "Display total".

Flow direction and arrows: Make the flow easy to read: top-to-bottom or left-to-right. Arrows show the direction of control. Do not have multiple arrow heads or ambiguous connections. If arrows cross, rearrange shapes to avoid crossing or use connectors that make the connections clear.

Decisions and branches: Every decision diamond should have two exits for a simple yes/no question. Label the exits when necessary. Ensure both exits ultimately lead to a defined next step or to Stop; do not leave a branch without a clear outcome. For multiway decisions, chain diamonds or use clear labels for each path.

Loops and updates: For loops, show initialization before the loop, a decision to test whether to continue, the body of the loop, and an update step that modifies the loop counter or condition. If the update is missing, the loop may never end. For count-controlled loops, show the counter initialization, the check, the body, and the counter increment clearly.

Completeness and testing: Include Start and Stop and make sure every possible path reaches Stop. After drawing a flowchart, perform a dry run with sample inputs to check correctness. Finally, redraw messy charts for clarity. Neatness and correctness are graded more than artistic drawing; clarity of logic is the key goal.

📌 Examples
  • Redraw a flowchart where arrows cross by moving boxes so arrows are straight top-to-bottom.
  • Label decision exits as 'Yes' and 'No' on a diamond checking if x > 0.
📊 Visual ideas
An example diagram showing a messy crossed-arrow flowchart and a corrected clean flowchart side by side
⚖️6

Sequence, Selection and Iteration

Three essential constructs: Any algorithm is built from three basic control structures: sequence, selection and iteration. Sequence is simply doing steps one after another. Selection is choosing different paths depending on a condition. Iteration repeats a group of steps until a condition is satisfied or for a set number of times.

Sequence explained: Most simple tasks are a sequence. For example, to add two numbers you read the first number, read the second number, add them, and display the result. Each step follows the previous one with no branching or repetition.

Selection (decision) explained: Selection is used when a choice must be made. It uses a condition to decide which path to follow. A typical example is determining pass or fail from marks: if marks >= 35 then pass else fail. In a flowchart this appears as a diamond with two arrows. Selection can be nested so that one decision leads to another decision inside a branch.

Iteration (loop) explained: Iteration repeats actions. There are two common kinds: count-controlled loops (repeat a fixed number of times) and condition-controlled loops (repeat until a condition is met). A count-controlled example is: FOR i = 1 TO 5 DO print i. A condition-controlled example is: WHILE input <> 0 DO add input to total; read next input. Each loop must include an update step that moves the loop toward termination.

Combining constructs: Real problems mix these constructs. Example: compute the sum of even numbers in a list — sequence to read the list, iteration to inspect each number, and selection inside the loop to check if a number is even. Practise breaking problems into these constructs and drawing the corresponding flowchart or writing pseudocode; this skill is central to writing correct programs later.

📌 Examples
  • Sequence: Read a, read b, compute a+b, display sum.
  • Selection: If age >= 18 then allow vote else deny.
  • Iteration: For i = 1 to 5 do print i.
📊 Visual ideas
Flowchart showing a loop: initialize counter -> decision counter<=n -> process -> increment -> back to decision
💻7

Pseudocode Basics

What is pseudocode: Pseudocode is a simple, informal way to express an algorithm using human-readable statements. It looks like programming code but uses English words and avoids strict syntax rules. Pseudocode helps to plan logic before converting it to a flowchart or program.

Useful keywords and structure: Common words used in pseudocode include READ, WRITE, IF, THEN, ELSE, ENDIF, FOR, WHILE, REPEAT, UNTIL, SET, and RETURN. Use indentation to show which statements belong to a decision or loop. For example, under an IF write the statements that run when the condition is true indented to make the structure clear.

Writing good pseudocode: Be consistent with variable names and keep statements short and precise. Write assignments as "sum = sum + i" and input as "READ n". When using loops, clearly show initialization, condition and update steps, for example: FOR i = 1 TO n sum = sum + i ENDFOR. For decisions use clear conditions like "IF marks >= 35 THEN" and include an ELSE branch if needed.

Advantages in planning: Pseudocode is quick to write and easy to modify. It helps spot logic errors before drawing a flowchart or writing code. When converting to code later, you map pseudocode statements to actual language constructs. Pseudocode serves as a bridge between plain English explanations and formal programming syntax.

Practice tips: Write pseudocode for daily activities such as making tea or for small math problems. Compare your pseudocode with a flowchart for the same problem to ensure both represent the same logic. This practice improves clarity and prepares you for programming in higher classes.

📌 Examples
  • READ n sum = 0 FOR i = 1 TO n sum = sum + i ENDFOR WRITE sum
  • READ x IF x mod 2 = 0 THEN WRITE "Even" ELSE WRITE "Odd" ENDIF
📊 Visual ideas
A short pseudocode block with indentation for a FOR loop to calculate factorial
💻8

Flowchart to Pseudocode and Vice Versa

Mapping ideas between forms: Each flowchart symbol has a corresponding pseudocode construct. Input/Output parallelogram maps to READ and WRITE statements. Process rectangles map to assignment or calculation lines like "sum = sum + i". Decision diamonds map to IF...THEN...ELSE, WHILE or REPEAT conditions depending on the logic. Connectors map to labels or continuation statements in longer pseudocode.

Converting a flowchart to pseudocode: Read the flowchart from Start to Stop. For each shape write the equivalent pseudocode statement. When you reach a decision diamond, write an IF or WHILE block and indent the statements for each branch. If the decision leads back to a previous step, you will usually use a WHILE or REPEAT loop in pseudocode. Ensure you include initialization steps shown before a loop and the update step inside the loop.

Converting pseudocode to a flowchart: Read each pseudocode statement in order and draw the matching shape. For READ/WRITE use parallelograms, for assignments use rectangles, and for IF or WHILE use diamonds. For FOR loops, show initialization, condition check, loop body, update, and back arrow to the condition. Label decision arrows with Yes/No or True/False if needed to make the flow explicit.

Checking the translation: After conversion, dry run the new representation with sample inputs to confirm the logic is preserved. Look for missing initialization, incorrect loop updates, or missing branches. Practice with examples of increasing complexity — single decision, nested decisions, loops with inner decisions — until conversions feel straightforward.

Why this skill matters: Translating between flowcharts and pseudocode trains clear thinking and prepares students to convert plans into real code. It helps spot mismatches early and document solutions clearly for others to understand and implement.

📌 Examples
  • Convert READ n; IF n>0 THEN WRITE 'Positive' ELSE WRITE 'Non-positive' into a flowchart with a decision diamond.
  • Convert a flowchart that sums numbers until a negative is entered into pseudocode using WHILE/REPEAT constructs.
📊 Visual ideas
Show a simple flowchart and beside it the equivalent pseudocode lines in the same order
🔢9

Example: Largest of Three Numbers

Problem statement and approach: We need an algorithm to find the largest among three numbers a, b and c. The efficient way uses only two comparisons. First compare a and b to find the larger of those two. Store that in a variable max. Then compare max with c. The larger of these two will be the largest of the three.

Why this works: By first reducing the problem from three numbers to two (by selecting the larger of a and b), we make the second comparison sufficient to find the overall maximum. This avoids unnecessary comparisons and is simple to test.

Pseudocode: READ a, b, c IF a >= b THEN max = a ELSE max = b ENDIF IF c >= max THEN max = c ENDIF WRITE max This pseudocode uses >= so equal values are handled correctly. The algorithm is finite and definite; it finishes after the two comparisons and one output.

Flowchart structure: Start -> Input a,b,c (parallelogram) -> Decision a >= b? (diamond) with Yes branch setting max = a (rectangle) and No branch setting max = b -> Next decision c >= max? with Yes branch setting max = c and No branch skipping -> Output max -> Stop. Label arrows clearly and ensure both decision exits eventually lead to the next step.

Testing with examples: Use several test values: (5,9,3) gives max = 9; (7,7,6) gives max = 7; (-2, -5, -1) gives max = -1. Trace each step by writing variable values at each stage to make sure the chart and pseudocode match. This example reinforces selection and shows how to write clear, testable algorithms.

📌 Examples
  • Inputs 5, 9, 3 -> comparisons: 5>=9? No -> max=9; 3>=9? No -> result 9.
  • Inputs 7, 7, 6 -> 7>=7? Yes -> max=7; 6>=7? No -> result 7.
📊 Visual ideas
Flowchart showing Start -> Input a,b,c -> Decision a>=b -> set max -> Decision c>=max -> Output max -> Stop
🔢10

Example: Sum of First n Natural Numbers

Problem and two viewpoints: The task is to compute the sum of the first n natural numbers. There are two common ways to think about this: an iterative method that uses a loop and a direct mathematical formula. For Class 8 we focus on understanding iteration and show the formula for checking answers.

Iterative algorithm (loop): The loop-based method builds the total by adding numbers one by one. Steps: read n, initialize sum = 0 and i = 1. Then while i <= n add i to sum and increase i by 1. After the loop ends display sum. This is a count-controlled loop because it repeats exactly n times when n is a positive integer. The algorithm must initialize both sum and i before entering the loop and must update i inside the loop to ensure termination.

Pseudocode: READ n sum = 0 i = 1 WHILE i <= n DO sum = sum + i i = i + 1 ENDWHILE WRITE sum This pseudocode clearly shows initialization, the loop condition, the body where accumulation happens, and the update of i.

Flowchart structure: Start -> Read n -> sum=0, i=1 (process) -> Decision i <= n? -> If Yes do sum = sum + i (process), i = i + 1 (process), then arrow back to decision. If No, go to Write sum and Stop. When drawing, keep the decision diamond between initialization and the loop body and make sure the update step is inside the loop so that i moves towards termination.

Formula for checking: The well-known formula sum = n*(n+1)/2 gives the same result and is useful to verify loop results for sample n. For example with n = 5 the loop yields 15 and the formula gives 5*6/2 = 15. Use both methods in class to build confidence in correctness and to learn both procedural thinking and numerical shortcuts.

📌 Examples
  • n = 5 -> iterative loop produces sum 15.
  • Use formula for check: n*(n+1)/2 = 5*6/2 = 15.
🧮 Formulas
  1. Sum of first n natural numbers: sum = n*(n+1)/2
📊 Visual ideas
Flowchart with initialization, decision i<=n, process sum=sum+i and i=i+1, loop back, then output
💻11

Debugging and Tracing Flowcharts

What is tracing (dry run): Tracing a flowchart means following each step manually, updating variable values as you move from start to stop. It is the simplest way to test whether the logic works for given inputs. Write down a table of variables and their values at each important step so you can see how the result was produced.

How to perform a dry run: 1) Choose sample inputs, including normal and boundary cases (zero, negative numbers, equal values). 2) Start at the Start symbol and note initial values. 3) Follow arrows, executing each process and recording changes. 4) When reaching a decision, choose the branch based on the current values and continue until Stop. 5) Compare the final output with the expected result to decide if the flowchart is correct.

Finding and fixing errors: If the result is wrong, look back through the trace table to find where an unexpected value first occurred. Common causes include incorrect initialization, missing updates inside loops, wrong comparison operators, or missing branches in decisions. Once the cause is found, edit the flowchart: change initialization, add an update statement, correct the condition, or add the missing branch, then re-run the trace on the corrected chart.

Examples of common trace findings: Off-by-one errors are often visible during tracing when a loop runs one time too many or too few. A missing increment statement will show a variable stuck at the same value through many steps. An unhandled case in a decision will appear as no defined output for some input values. Tracing helps you see such problems clearly and fix them systematically.

Teacher expectations: In exams, present a clear trace table with steps and variable values, explain which branch was taken at each decision, and justify fixes if you change the flowchart. Good tracing demonstrates understanding of the algorithm's behaviour and is a key skill for programming success.

📌 Examples
  • Trace a loop where i starts at 0 but condition is i<=n causing one extra iteration; fix by starting i=1 or using i<n.
  • Trace largest-of-three example with equal numbers to ensure comparisons use >= if needed.
📊 Visual ideas
A sample trace table with columns for step number, variable values and comments while following a flowchart
💻12

Common Mistakes, How to Avoid Them and Advantages of Flowcharts

Common mistakes students make: Many errors recur when beginners write algorithms or draw flowcharts. Vague instructions such as "do process" leave ambiguity. Missing Start or Stop symbols make a diagram incomplete. Forgetting to initialize variables before use leads to incorrect results. In loops, missing the update (for example forgetting i = i + 1) creates an infinite loop. Using wrong comparison operators (like < instead of <=) causes off-by-one mistakes. Decisions with only one branch drawn leave some inputs unhandled.

How to avoid these mistakes: Use specific, short statements inside symbols. Always include Start and Stop. Initialize all variables before using them. For loops, ensure initialization, condition and update are clearly shown. Label decision branches and make sure every path reaches Stop. Perform at least two dry runs with different inputs, including edge cases, to find hidden errors. Ask a classmate to review your flowchart; peer review often spots overlooked issues.

Advantages of flowcharts: Flowcharts make logic visible and easy to follow. They are excellent for planning because they reveal missing steps and branches before coding. Flowcharts are useful for communicating ideas to others who understand diagrams better than text. They also serve as simple documentation and help in debugging because the flow of control is explicit.

Limitations of flowcharts: For very large programs, flowcharts can become unwieldy and hard to maintain. They do not show low-level details such as data types, memory use, or performance aspects explicitly. For complex systems, modular designs or high-level diagrams are preferred and flowcharts are used only for parts of the system. Despite limitations, flowcharts are ideal for learning algorithmic thinking and for designing small to medium problems.

Practical advice: Use flowcharts for classroom problems and small projects. When a task grows large, split it into subproblems and draw a flowchart for each part. Keep diagrams neat and tested; clear, tested flowcharts are a strong foundation for later programming and for performing well in exams.

📌 Examples
  • Loop without update: WHILE i<=n DO sum=sum+i ENDWHILE — missing i=i+1 causes infinite loop.
  • Decision with only one branch drawn, leaving the else path undefined.
📊 Visual ideas
Before-and-after flowchart pair showing an incorrect loop without counter update and corrected version

Key Concepts

Algorithm
A finite, precise sequence of steps to solve a problem or perform a task.
Flowchart
A diagram using standard symbols to represent the steps and decisions of an algorithm.
Pseudocode
An informal, English-like way to write the steps of an algorithm without using a real programming language.
Sequence
A construct where instructions are executed one after another in order.
Selection
A decision-making construct that chooses between two or more paths based on a condition.
Iteration
A construct that repeats a set of instructions until a condition is met or for a fixed number of times.
Start/Stop symbol
The oval flowchart symbol that marks the beginning or end of a flowchart.
Process symbol
A rectangle in a flowchart that represents an instruction or calculation.
Input/Output symbol
A parallelogram used to show reading input or writing output in a flowchart.
Decision symbol
A diamond-shaped symbol that represents a test or condition with branches for outcomes.
Dry run / Tracing
Manually following an algorithm or flowchart step by step to find outputs and reveal errors.
Off-by-one error
A common loop mistake where the loop runs one time too many or too few due to an incorrect boundary.
Connector
A small circle used in flowcharts to join or continue flow between different parts of the diagram.
Initialization
Setting initial values for variables before entering a process or loop.

Practice Questions

  1. Draw a flowchart to read two numbers and display their sum. / दो संख्याएँ पढ़कर उनका योग दिखाने का फ्लोचार्ट बनाइए।
    Show answer

    Start; Read A, B; Sum = A + B; Display Sum; Stop. / Start; A, B पढ़ें; Sum = A + B; Sum प्रदर्शित करें; Stop.

  2. Write pseudocode to find the largest of three numbers. / तीन संख्याओं में से सबसे बड़ी खोजने का स्यूडोकोड लिखिए।
    Show answer

    READ a, b, c IF a >= b THEN max = a ELSE max = b ENDIF IF c >= max THEN max = c ENDIF WRITE max. / READ a, b, c IF a >= b THEN max = a ELSE max = b ENDIF IF c >= max THEN max = c ENDIF WRITE max.

  3. Trace the flowchart that computes sum of first n natural numbers for n = 4 and show the final sum. / n = 4 के लिए पहले n प्राकृतिक संख्याओं का योग निकालने वाले फ्लोचार्ट का ट्रेस करें और अंतिम योग दिखाइए।
    Show answer

    Initialize sum = 0, i = 1. Iteration 1: sum=1, i=2. Iteration 2: sum=3, i=3. Iteration 3: sum=6, i=4. Iteration 4: sum=10, i=5. Loop ends as i>n. Final sum = 10. / प्रारम्भ करें sum = 0, i = 1. चक्र 1: sum=1, i=2. चक्र 2: sum=3, i=3. चक्र 3: sum=6, i=4. चक्र 4: sum=10, i=5. चक्र समाप्त, अंतिम योग = 10.

  4. What are the three basic constructs of algorithms? Give a one-line example of each. / एल्गोरिद्म के तीन मूलभूत संरचनाएँ कौन सी हैं? प्रत्येक का एक-लाइन उदाहरण दें।
    Show answer

    Sequence: Read A, Read B, Display A+B. Selection: IF marks>=40 THEN Pass ELSE Fail. Iteration: FOR i=1 TO 5 DO Print i ENDFOR. / अनुक्रम: A पढ़ें, B पढ़ें, A+B दिखाएँ। चयन: IF marks>=40 THEN Pass ELSE Fail। पुनरावृत्ति: FOR i=1 TO 5 DO Print i ENDFOR.

  5. Give four rules to follow when drawing a flowchart. / फ्लोचार्ट बनाते समय चार नियम दीजिए।
    Show answer

    Use standard symbols; include Start and Stop; decisions must have two exits; keep flow clear top-to-bottom or left-to-right and avoid crossing arrows. / मानक चिह्नों का उपयोग करें; Start और Stop शामिल करें; निर्णय के दो ही रास्ते होने चाहिए; प्रवाह साफ रखें ऊपर-से-नीचे या बाएँ-से-दाएँ और काटती रेखाओं से बचें।

  6. Convert this pseudocode to a flowchart: READ n; IF n MOD 2 = 0 THEN WRITE 'Even' ELSE WRITE 'Odd' ENDIF. / इस स्यूडोकोड को फ्लोचार्ट में बदलिए: READ n; IF n MOD 2 = 0 THEN WRITE 'Even' ELSE WRITE 'Odd' ENDIF।
    Show answer

    Flowchart: Start -> Input n (parallelogram) -> Decision diamond 'n MOD 2 = 0?' with Yes arrow to Process/Output 'Write Even' and No arrow to Process/Output 'Write Odd' -> Stop. / फ्लोचार्ट: Start -> n इनपुट (parallelogram) -> निर्णय 'n MOD 2 = 0?'; हाँ मार्ग पर 'Write Even', नहीं मार्ग पर 'Write Odd' -> Stop.

  7. A flowchart has a loop where counter i starts at 0 and condition is i < = n but i is never increased. What is the problem and how to fix it? / एक फ्लोचार्ट में काउंटर i का आरम्भ 0 है और शर्त i <= n है परन्तु i कभी बढ़ता नहीं है। समस्या क्या है और इसे कैसे ठीक करें?
    Show answer

    Problem: Missing update causes an infinite loop since i never changes so the condition remains true. Fix: Add a process inside the loop to increment i (e.g., i = i + 1) or change the loop logic to ensure termination. / समस्या: अपडेट न होने पर अनन्त लूप बनता है क्योंकि i कभी बदलता नहीं; सुधार: लूप के भीतर i = i + 1 जैसा अपडेट जोड़ें या लूप की शर्त/तर्क बदलकर समाप्ति सुनिश्चित करें।

  8. Why do we perform dry runs on algorithms? Give two reasons. / हम एल्गोरिद्म पर ड्राई रन क्यों करते हैं? दो कारण बताइए।
    Show answer

    To check correctness by simulating steps with sample inputs; to find and fix logic errors like wrong initialisation or off-by-one mistakes. / नमूना इनपुट्स के साथ कदमों का अनुकरण कर सही परिणाम सुनिश्चित करने के लिए; और तर्कगत त्रुटियाँ जैसे गलत प्रारम्भिक मान या ऑफ-बाय-वन की गलतियाँ खोजने व ठीक करने के लिए।

  9. Write an algorithm in steps to count how many numbers in a list are greater than 50. / किसी सूची में 50 से अधिक कितनी संख्याएँ हैं यह गिनने के लिए चरणों में एल्गोरिद्म लिखिए।
    Show answer

    Step 1: Start. Step 2: Read the list and its length n. Step 3: Set count = 0 and index i = 1. Step 4: While i <= n do if list[i] > 50 then count = count + 1. Step 5: i = i + 1. Step 6: Repeat step 4 until i>n. Step 7: Display count and Stop. / चरण 1: Start. चरण 2: सूची और इसकी लंबाई n पढ़ें. चरण 3: count = 0 और i = 1 सेट करें. चरण 4: जब तक i <= n, अगर list[i] > 50 हो तो count = count + 1. चरण 5: i = i + 1. चरण 6: जब तक i>n न हो चरण 4繰 (दोहराएँ). चरण 7: count प्रदर्शित करें और Stop.

  10. Explain one limitation of flowcharts for large programs. / बड़े प्रोग्रामों के लिए फ्लोचार्ट की एक कमी समझाइए।
    Show answer

    Flowcharts for large programs become very big and hard to read or maintain; they can be cluttered and do not show details like data types or memory usage. / बड़े प्रोग्रामों के लिए फ्लोचार्ट बहुत बड़े और पढ़ने/रख-रखाव में मुश्किल हो जाते हैं; वे बाधा पूर्ण और डेटा प्रकार या मेमोरी उपयोग जैसे विवरण नहीं दिखाते।

Related Laws & Principles

Explore all

Foundational laws & principles connected to this chapter — tap to open in the Laws Explorer.

Loading related laws…
Sourced from 0 content files · LLOS Learn · browse all chapters