Define an Algorithm. Explain its characteristics in detail.
Algorithm – Definition
An algorithm is a finite set of well-defined, logical and step-by-step instructions used to solve a
problem and produce the desired output from the given input.
An algorithm provides a clear method to solve a computational problem efficiently and correctly.
Characteristics of an Algorithm
1. Input
An algorithm must accept zero or more inputs. Inputs are the data provided to the
algorithm for processing.
Example: Two numbers given for addition.
2. Output
An algorithm must produce at least one output. The output is the result of processing the
input.
Example: Sum of two numbers.
3. Definiteness
Each step of the algorithm must be clear, precise, and unambiguous. There should be no
confusion about what each step means.
4. Finiteness
The algorithm must terminate after a finite number of steps. An algorithm that never ends
is not valid.
5. Effectiveness
All operations in the algorithm must be simple, basic, and executable in a finite amount
of time.
An algorithm that satisfies all these characteristics is considered correct and reliable.
Q2. Explain the problem solving steps in detail.
Problem solving in computer science follows a systematic approach to ensure correctness and
efficiency.
1. Understanding the Problem
In this step, the problem is read carefully to identify:
Inputs
Outputs
Constraints
Conditions
This step avoids misunderstanding of the problem.
2. Planning the Solution
After understanding the problem, a plan is created. This includes:
Selecting the appropriate logic
Choosing data structures
Writing the algorithm or flowchart
3. Executing the Plan
The planned solution is converted into a program using a programming language such as C.
4. Reviewing and Improving
The solution is tested using different inputs. Errors are corrected and performance is improved if
required.
These steps ensure systematic and error-free problem solving.
Q3. Explain the types of computational problems with
examples.
Computational problems are problems that can be solved using a computer. They are classified
as follows:
1. Decision Problems
These problems have only two possible outputs: Yes/No or True/False.
Example:
Checking whether a number is prime.
2. Search Problems
These problems involve finding the location or presence of an element in a given set.
Example:
Searching a number in an array.
3. Optimization Problems
These problems aim to find the best solution among multiple possible solutions.
Example:
Finding the shortest route between two cities.
4. Counting Problems
These problems require counting the number of valid solutions.
Example:
Counting even numbers in a list.
Q4. Distinguish between generalization and special case in
problem solving.
Generalization
Generalization refers to designing a solution that works for all possible input values.
Example:
Finding the maximum of n numbers.
Advantages:
Flexible
Reusable
Efficient
Special Case
A special case solution works only for limited or specific inputs.
Example:
Finding the maximum of two numbers only.
Disadvantages:
Limited use
Not reusable
Difference Summary
Generalization Special Case
Works for all inputs Works for limited inputs
Flexible Rigid
Preferred in programming Less preferred
Q5. Explain the role of data structures in problem solving.
Data structures are methods of organizing and storing data in memory so that it can be accessed
and modified efficiently.
Role of Data Structures
1. Efficient storage of data
2. Faster processing and retrieval
3. Reduced complexity
4. Better memory management
5. Improved algorithm performance
Examples
Arrays store multiple values
Stacks follow LIFO order
Queues follow FIFO order
Algorithms and data structures together form the foundation of efficient programming.
Q6. Explain problem analysis and efficiency of algorithms.
Problem Analysis
Problem analysis involves understanding the problem before solving it. It includes:
Identifying inputs
Identifying outputs
Understanding constraints
Breaking the problem into sub-problems
Proper analysis ensures correct algorithm design.
Efficiency of Algorithms
Algorithm efficiency measures how well an algorithm performs.
1. Time Efficiency – How fast an algorithm executes
2. Space Efficiency – How much memory an algorithm uses
Efficient algorithms save time and resources.
Q7. Explain input validation, pre-conditions and post-
conditions.
Input Validation
Input validation ensures that the data entered into a program is correct and acceptable.
Example:
Marks should not exceed 100.
Pre-Conditions
Pre-conditions are conditions that must be true before the execution of an algorithm.
Example:
Input numbers must be valid integers.
Post-Conditions
Post-conditions are conditions that must be true after the execution of an algorithm.
Example:
Correct output must be displayed.