Module 2 Q and Answers
Module 2 Q and Answers
Module 2 Q and Answers
Features of an Algorithm
1. Finite Steps: An algorithm must have a limited number of steps and end after a finite
number of operations.
2. Well-Defined Instructions: Each step must be clear, unambiguous, and executable.
3. Input and Output: It should accept zero or more inputs and produce at least one output.
4. Deterministic: The algorithm should produce the same output every time for the same
input.
5. Effectiveness: Each step should be basic enough to be performed within a finite time.
1. Step 1: Start.
2. Step 2: Take two numbers as input, say a and b.
3. Step 3: Calculate the sum, sum = a + b.
4. Step 4: Output the result (sum).
5. Step 5: End.
Not Executable:
Language-Independent:
7. Describe the basic structure of pseudocode. What are the common elements used?(3)
IF age >= 18
THEN OUTPUT "Eligible to vote"
ELSE
OUTPUT "Not eligible to vote"
4. Loops (Repetition Statements):
5. End Statement:
Indicates the end of the pseudocode sequence.
Example: END
user(3)
START
INPUT n // number of elements to be summed
SET sum = 0 // initialize sum to zero
FOR i = 1 TO n
INPUT number // get each number from the user
SET sum = sum + number // add the number to sum
END FOR
Start
Input three numbers, A, B, and C.
Check if A is greater than both B and C.
11. Depict the difference between algorithm and pseudocode with suitable examples(3)
1. Start
2. Input two numbers, A and B
3. Set Sum = A + B
4. Output the value of Sum
5. End
Pseudocode
START
END
Control structures in pseudocode, such as if-else statements and loops, are essential for directing
the flow of execution based on conditions and for repeating actions. These structures help in
making decisions and executing blocks of code multiple times, thereby enabling complex logic
to be implemented in an algorithm.
1. If-Else Statements
Role: The if-else control structure allows the algorithm to make decisions based on
certain conditions. If a condition evaluates to true, a specific block of code is executed;
otherwise, an alternative block of code can be executed.
2. Loops
Role: Loops are used to repeat a block of code multiple times until a specific condition is
met. This is useful for tasks like iterating over lists, performing calculations, or accepting
user inputs.
SET sum = 0
FOR i FROM 1 TO 5 DO
INPUT number
SET sum = sum + number
END FOR
OUTPUT "The total sum is:", sum
structured yet simple way to describe the logic in a way that's easy to translate into code.
Flowchart Example:
Pseudocode Example:
Algorithm:
Step 4: Stop.
1. Sequencing
START
INPUT A
INPUT B
Sum = A + B
OUTPUT Sum
END
FOR i FROM 1 TO 5 DO
OUTPUT "Iteration", i
END FOR
This diagrammatic representation illustrates a solution model to a given problem. Flowcharts are
used in analysing, designing, documenting or managing a process or program in various fields.
Like other types of diagrams, they help visualize what is going on and thereby help understand a
process, and perhaps also find flaws, bottlenecks, and other less-obvious features within it.
There are many different types of flowcharts, and each type has its own repertoire of boxes and
notational conventions.
Common alternative names include: flowchart, process flowchart, functional flowchart, process
map, process chart, functional process chart, business process model, process model, process flow
diagram, work flow diagram, business flow diagram.
5. Draw a flowchart to solve the problem of a non functioning light bulb(8)