0% found this document useful (0 votes)
3 views1 page

Unit 1 Question Bank Answers (1) - 1-9 - Compressed

The document provides a comprehensive question bank on algorithms, flowcharts, and programming concepts. It includes definitions, characteristics, and examples of algorithms and flowcharts, as well as explanations of programming concepts like debugging, testing, and modular programming. Additionally, it features algorithms and flowcharts for various mathematical computations and problem-solving strategies.
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)
3 views1 page

Unit 1 Question Bank Answers (1) - 1-9 - Compressed

The document provides a comprehensive question bank on algorithms, flowcharts, and programming concepts. It includes definitions, characteristics, and examples of algorithms and flowcharts, as well as explanations of programming concepts like debugging, testing, and modular programming. Additionally, it features algorithms and flowcharts for various mathematical computations and problem-solving strategies.
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/ 1

UNIT 1 QUESTION BANK ANSWERS

1. What is an Algorithm?
An algorithm is a step-by-step procedure or set of rules to solve a specific problem. It consists of
a finite sequence of well-defined instructions that, when executed, produce an output and
terminate in a finite amount of time.

Example: Algorithm to add two numbers


Start
Input two numbers: a and b
Compute sum: sum = a + b
Display the sum
Stop

2. Define Flowchart
A flowchart is a graphical representation of an algorithm using symbols to depict the flow of
execution. It helps in visualizing the steps involved in solving a problem.

3. What are the characteristics of an Algorithm?


An algorithm should have the following characteristics:

Input – It should have well-defined inputs.


Output – It must produce a required result.
Definiteness – Each step should be clear and unambiguous.
Finiteness – It should terminate after a finite number of steps.
Effectiveness – Each step must be simple enough to be performed in a reasonable amount of
time.

4. What are the symbols of a Flowchart?


Common symbols used in a flowchart are:

Oval – Represents Start/Stop


Rectangle – Represents a Process/Operation
Parallelogram – Represents Input/Output
Diamond – Represents a Decision (Yes/No)
Arrow – Represents Flow of Control

5. What is the use of a Translator?


A translator is a program that converts code written in one programming language into another
language. It helps in converting human-readable source code into machine-readable code.
Types of translators include:

Compiler – Converts the entire source code into machine code at once.
Interpreter – Converts and executes code line by line.
Assembler – Converts assembly language into machine code.

6. Differentiate between Algorithm and Flowchart


Feature Algorithm Flowchart
Definition A step-by-step procedure for solving a problem. A graphical representation of an
algorithm.
Representation Written in text using pseudocode. Uses symbols and diagrams.
Readability Requires understanding of logic. Easier to understand visually.
Debugging Can be checked logically. Helps visualize the process for debugging.

7. What is program debugging and program testing?


Program Debugging – The process of finding and fixing errors (bugs) in a program.
Program Testing – The process of running a program with different test cases to check its
correctness and reliability.

8. What is the difference between Compiler and Interpreter?


Feature Compiler Interpreter
Execution Converts entire program at once. Converts and executes line by line.
Speed Faster execution. Slower execution.
Error Detection Detects all errors after compilation. Stops at the first error.
Example C, C++ compilers Python, JavaScript interpreters

9. Name the two methods to implement modular programming


Functions – Breaking a program into smaller, reusable functions.
Header Files – Using separate files to define reusable code modules.

10. Write an Algorithm to add two numbers


Start
Input two numbers a and b
Compute sum = a + b
Display sum
Stop
Example in C:
#include <stdio.h>

int main() {
int a, b, sum;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum = %d\n", sum);
return 0;
}

DESCRPITIVE TYPE QUESTION AND ANSWERS

1A. Explain programs and algorithm with examples


A program is a set of instructions that a computer follows to perform a task. An algorithm is a
step-by-step procedure for solving a problem.

Example Algorithm: Find the Sum of Two Numbers


Start
Read two numbers, a and b
Compute sum = a + b
Print sum
Stop

C Program:

#include <stdio.h>
int main() {
int a, b, sum;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum: %d\n", sum);
return 0;
}

1B. Draw a flowchart to calculate the average of three numbers


Flowchart Steps:
Start
Input three numbers a, b, c
Compute average = (a + b + c) / 3
Display average
Stop

C Program:

#include <stdio.h>
int main() {
float a, b, c, avg;
printf("Enter three numbers: ");
scanf("%f %f %f", &a, &b, &c);
avg = (a + b + c) / 3;
printf("Average: %.2f\n", avg);
return 0;
}
2A. Describe the steps involved in constructing a flowchart
Identify the problem and its inputs/outputs.
Determine the steps needed to solve the problem.
Use standard symbols:
Oval: Start/End
Parallelogram: Input/Output
Rectangle: Process
Diamond: Decision
Arrange steps logically.
Validate the flowchart.

2B. Draw a flowchart to calculate area and perimeter of a rectangle


Start
Input length and width
Compute area = length × width
Compute perimeter = 2 × (length + width)
Display area and perimeter
Stop
C Program:

#include <stdio.h>
int main() {
float length, width, area, perimeter;
printf("Enter length and width: ");
scanf("%f %f", &length, &width);
area = length * width;
perimeter = 2 * (length + width);
printf("Area: %.2f, Perimeter: %.2f\n", area, perimeter);
return 0;
}

3A. Explain computer solving requirements


To solve a problem using a computer, we need:

Input: Raw data.


Processing: Operations to transform input into output.
Storage: Memory to hold data.
Output: Displaying results.
Control Structures: Decision-making and looping.
3B. Write an algorithm to calculate simple interest
Start
Input P (Principal), R (Rate), T (Time)
Compute SI = (P × R × T) / 100
Display SI
Stop

C Program:

#include <stdio.h>
int main() {
float P, R, T, SI;
printf("Enter Principal, Rate, Time: ");
scanf("%f %f %f", &P, &R, &T);
SI = (P * R * T) / 100;
printf("Simple Interest: %.2f\n", SI);
return 0;
}

4A. Describe phases of problem solving


Understanding the Problem: Define input, process, and output.
Planning the Solution: Develop an algorithm or flowchart.
Implementing the Solution: Write code.
Testing & Debugging: Fix errors.
Maintenance: Improve efficiency.

4B. Draw a flowchart to find the greatest of two numbers


Start
Input a, b
If a > b, print a else print b
Stop

C Prog

#include <stdio.h>
int main() {
int a, b;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
if (a > b)
printf("%d is greater\n", a);
else
printf("%d is greater\n", b);
return 0;
}

5A. Explain problem-solving strategies


Problem-solving strategies include:

Divide and Conquer – Break the problem into smaller subproblems.


Top-Down and Bottom-Up Approach – Design solutions from high-level to low-level (top-down)
or the opposite (bottom-up).
Algorithmic Thinking – Use step-by-step logical procedures.
Trial and Error – Test different solutions.
Heuristics – Use rule-of-thumb methods.
5B. Write an algorithm to find the area of a triangle using Heron’s formula
Start
Input sides a, b, c
Compute s = (a + b + c) / 2
Compute Area = sqrt(s * (s - a) * (s - b) * (s - c))
Display Area
Stop

C Program:
#include <stdio.h>
#include <math.h>
int main() {

float a, b, c, s, area;
printf("Enter three sides of the triangle: ");
scanf("%f %f %f", &a, &b, &c);
s = (a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("Area of Triangle: %.2f\n", area);
return 0;
}

6A. Describe top-down design


Top-down design is a problem-solving approach where:

The problem is divided into smaller tasks.


Each task is solved independently.
Tasks are integrated to form a complete solution.
6B. Write an algorithm to convert Fahrenheit to Celsius
Start
Input Fahrenheit
Compute Celsius = (Fahrenheit - 32) * 5/9
Display Celsius
Stop

C Program:

#include <stdio.h>
int main() {
float F, C;
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &F);
C = (F - 32) * 5 / 9;
printf("Temperature in Celsius: %.2f\n", C);
return 0;
}

7A. Explain program verification


Program verification ensures that a program correctly implements the intended algorithm. It
involves:

Code Reviews – Checking code logic.


Testing – Running test cases.
Formal Proofs – Mathematically verifying correctness.

7B. Draw a flowchart to check whether the given year is a leap year or not
Start
Input year
If (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0), print "Leap Year"
Else print "Not a Leap Year"
Stop

C Program:

#include <stdio.h>
int main() {
int year;
printf("Enter a year: ");
scanf("%d", &year);
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
printf("%d is a Leap Year\n", year);
else
printf("%d is Not a Leap Year\n", year);
return 0;
}

8A. How to improve the efficiency of an algorithm


Use efficient data structures (e.g., Hash Tables for quick lookups).
Reduce time complexity (e.g., using Binary Search instead of Linear Search).
Optimize loops (e.g., avoid unnecessary iterations).
Use caching/memoization (store previous results to avoid recomputation).
Parallel processing (split tasks for multi-core execution).

8B. Draw a flowchart to interchange two numbers


Start
Input a, b
Swap using temp = a; a = b; b = temp;
Display a, b
Stop

C Program:

#include <stdio.h>
int main() {
int a, b, temp;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
temp = a;
a = b;
b = temp;
printf("After swapping: a = %d, b = %d\n", a, b);
return 0;
}

9A. Write an algorithm to find the maximum of three numbers


Start
Input a, b, c
If a > b and a > c, print a
Else if b > c, print b

Else print c
Stop

C Program:

#include <stdio.h>
int main() {
int a, b, c;
printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);
if (a > b && a > c)
printf("%d is the maximum\n", a);
else if (b > c)
printf("%d is the maximum\n", b);
else
printf("%d is the maximum\n", c);
return 0;
}

9B. Write an algorithm to check if a number is even or odd


Start
Input n
If n % 2 == 0, print "Even"
Else print "Odd"
Stop

C Program:

#include <stdio.h>
int main() {
int n;
printf("Enter a number: ");
scanf("%d", &n);
if (n % 2 == 0)
printf("%d is Even\n", n);
else
printf("%d is Odd\n", n);
return 0;
}
10A. Discuss various notations used to measure algorithm efficiency
Big-O (O): Worst-case scenario (e.g., O(n) for linear search).
Big-Theta (Θ): Average-case scenario.
Big-Omega (Ω): Best-case scenario.
Space Complexity: Memory used.
Time Complexity: Execution time.

10B. Draw a flowchart to compute the power of a number


Start

Input base and exponent


Compute result = base^exponent using a loop
Display result
Stop

C Program:

#include <stdio.h>
int main() {
int base, exp, result = 1;
printf("Enter base and exponent: ");
scanf("%d %d", &base, &exp);
for (int i = 0; i < exp; i++)
result *= base;
printf("Result: %d\n", result);
return 0;
}

You might also like