UNIT – 1
Introduction to Programming and Problem Solving
1.Describe about problem solving Phases
PHASES OF PROBLEM SOLVING
The following are the some basic steps to solve the problems by computer.
Step 1: Identify and Define Problem. Explain you problem clearly.
Step 2: Generate Possible Solutions
List out all the solution that you find.
Generate the maximum number of solution.
Step 3: Evaluate Alternatives
After generating the maximum solutions, remove the undesired solutions.
Step 4: Decide a Solution
After filtering all the solution, you have the best solution only. Then choose one of the best solution
and make a decision to make it as a perfect solution.
Step 5: Implement a Solution:
After getting the best solution, implement that solution to solve a problem.
Step 6: Evaluate the result
After implementing a best solution, Evaluate how much you solution solve the problem. If your
solution will not solve the problem then you can again start with Step 2.
2.Explain algorithm analysis and notations
ALGORITHM ANALYSIS AND NOTATIONS
Analysis of algorithms is the determination of the amount of time and space resources required to
execute it.
Big O notation: Describes the worst-case running time of a program.
f(n) = O(g(n)), read as f of n is big oh of g of n, iff (if and only if) positive constants c and n0 exist
such that f(n) <= cg(n) for all n, n >= n0.
Omega notation: Represents the minimum running time of an algorithm, or the best-case complexity
f(n) = omega(g(n)), read as f of n is omega of g of n, iff (if and only if) positive constants c and
n0 exist such that f(n) >= cg(n) for all n, n >= n0.
Theta notation: Represents the upper and lower bound of the running time of an algorithm, or the
average-case complexity.
f(n) = Theta(g(n)), read as f of n is theta of g of n, iff (if and only if) positive constants c1, c2, and
n0 exist such that c1g(n) <=f(n) <= c2g(n) for all n, n >= n0.
3. Explain Top-Down Approach of problem solving
Top-down Approach is a problem-solving method that breaks down a bigger problem into smaller,
less complex sub-problems and solving each sub-problem individually. Then break the sub problem into
tasks until they are directly solvable. Top-Down approach is also termed as breaking a bigger problem
into smaller problems and solving them individually in recursive manner. It is also known as “stepwise
refinement”. Top-Down Model is followed by structural programming languages like C, Fortran, etc.
Working of Top-Down Approach
1. Start with an overview of the problem.
2. Divide the problem into smaller sub-problems.
3. Solve each sub-problem.
4. Combine the subproblems.
Advantages
1. Breaking problems into parts helps identify what needs to be done.
2. At each step of refinement, new sub-problem become less complex and easier to solve.
3. Parts of the solution may be reusable.
4. Breaking problems into parts allows more than one person to solve the problem.
4.What are Problem solving strategies. Explain Briefly.
Ans: There are typically two primary ways to approach problem-solving - "top-down approach"
and "bottom-up approach".
Top-down approach
Top-Down Approach is an approach to design algorithms in which a bigger problem is broken
down into smaller parts. Thus, it uses the decomposition approach. This approach is generally used
by structured programming languages such as C, COBOL, FORTRAN.
The implementation of algorithm using top-down approach depends on the programming language
and platform. Top-down approach is generally used with documentation of module and debugging
code.
Bottom-up approach
Bottom-Up Approach is one in which the smaller problems are solved, and then these solved
problems are integrated to find the solution to a bigger problem. Therefore, it uses composition
approach.
It is generally used with object-oriented programming paradigm such as C++, Java, and Python.
The bottom-up approach is generally used in testing modules
5.Explain the steps involved in developing a program with a neat diagram
Program Development Process
When we want to develop a program using any programming language, we follow a sequence of steps.
These steps are called phases in program development. The program development life cycle is a set of
steps or phases that are used to develop a program in any programming language.
Generally, the program development life cycle contains 6 phases, they are as follows….
1. Problem Definition
In this phase, we define the problem statement and we decide the boundaries of the problem. In this
phase we need to understand the problem statement, what is our requirement, what should be the
output
of the problem solution. These are defined in this first phase of the program development life cycle.
2. Problem Analysis
In phase 2, we determine the requirements like variables, functions, etc. to solve the problem. That
means we gather the required resources to solve the problem defined in the problem definition phase.
We also determine the bounds of the solution.
3. Algorithm Development
During this phase, we develop a step by step procedure to solve the problem using the specification
given in the previous phase. This phase is very important for program development. That means we
write the solution in step by step statements.
4. Coding & Documentation
This phase uses a programming language to write or implement the actual programming instructions for
the steps defined in the previous phase. In this phase, we construct the actual program. That means we
write the program to solve the given problem using programming languages like C, C++, Java, etc.
5. Testing & Debugging
During this phase, we check whether the code written in the previous step is solving the specified
problem or not. That means we test the program whether it is solving the problem for various input data
values or not. We also test whether it is providing the desired output or not.
6. Maintenance
During this phase, the program is actively used by the users. If any enhancements found in this phase,
all the phases are to be repeated to make the enhancements. That means in this phase, the solution
(program) is used by the end-user. If the user encounters any problem or wants any enhancement, then
we need to repeat all the phases from the starting, so that the encountered problem is solved or
enhancement is added
6.Define an algorithm and explain the characteristics of an algorithm?
ALGORITHM
Algorithm is the set of rules that define how particular problem can be solved in finite number of
steps. Any good algorithm must have following characteristics
1. Input: Algorithm must have 0 or more inputs
2. Output: Algorithm must produce atleast one output.
3. Definiteness: each step of the algorithm must be clear and unambiguous.
4. Effectiveness: Every instruction must be very basic.
5. Finiteness: Algorithm must include finite number of steps
Advantages of Algorithms:
1. It is the way to solve a problem step-wise so it is easy to understand.
2. It uses definite procedure.
3. It is not dependent with any programming language.
4. Each step has its own meaning so it is easy to debug
Disadvantage of Algorithms:
1. It is time consuming
2. Difficult to show branching and looping statement
3. Large problems are difficult to implement
7. Discuss briefly on problem solving requirements
REQUIREMENTS FOR PROBLEM SOLVING BY COMPUTER
Algorithms are employed to solve problems. The requirements for problem solving by computer
include:
1. Clear Understanding of the Problem: Precise articulation of the problem is essential. Define the
problem in a way that a computer can understand and process it. This includes identifying inputs,
desired outputs, constraints, and the problem's scope.
2. Input Data: Determine what data is required to solve the problem. Collect, acquire, or generate
the necessary input data. Ensure the data is accurate and reliable.
3. Algorithms and Methods: Formulate a step-by-step procedure or algorithm to solve the problem.
Algorithms provide a clear set of instructions for the computer to follow, breaking down the
solution into smaller, manageable steps. Choose appropriate algorithms, methods, and
techniques that are relevant to the problem.
4. Data Structures: Use suitable data structures to represent and manipulate data efficiently.
Common data structures include arrays, lists, trees, graphs, queues, and stacks.
5. Logical Precision: While developing computer algorithms the solution must be specified with
logical precision in much detail
Definition of program:Program is the set of instructions which is run by the computer to perform
specific task. The task of developing program is called programming. To obtain a computer solution
to a problem, which provides input to the program which is manipulated according to instructions
and produces output
8.What is program verification
Program verification is the process of applying formal methods directly to verification of code.
Program verification is the process of using mathematical proof techniques to establish that the results
obtained by the execution of a program with arbitrary inputs are in accord with formally defined
output specifications.
The main goal of the program verification is to understand what happens when a program is executed
when input is given.
i) Input and Output assertion
ii) Verification of program segments with branches
iii) Verification of program segments with loops:
As an example, consider the following program to compute the factorial of n.
i=1, f=1;
while(i<=n)
f=f*i;
i++;
iv) Proof of termination: To prove that a program terminates, it is necessary to show that the
expected output is attained in a finite number of steps. This implies that every loop in the program
terminates in a finite number of steps.