Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
31 views

C lang UNIT - 1 Notes

Uploaded by

subham285sahoo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

C lang UNIT - 1 Notes

Uploaded by

subham285sahoo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

UNIT – I

Problem Solving is a scientific technique to discover and implement the


answer to a problem. The computer is the symbol manipulating device
that follows the set of commands known as program.

1.Programs and Algorithms:

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.

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.

( or )

Algorithm is a set of instructions for solving a problem or accomplishing a


task.

( or )

Finite set of instructions carried out in a specific order to perform a


particular task.

1. Input: Specify and require input


2. Output: Solution of any problem
3. Definite: Solution must be clearly defined \\UNCOUNTABLE
4. Effective
5. Finite: Steps must be finite \\COUNTABLE
6. Correct: Correct output must be generated
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

Flowchart:

The solution of any problem in picture form is called flowchart. It is


the one of the most important techniques to depict an algorithm.

Advantage of Flowchart:

1. Easier to understand
2. Helps to understand logic of problem
3. Easy to draw flowchart in any software like MS-Word
4. Complex problem can be represent using less symbols
5. It is the way to documenting any problem
6. Helps in debugging process

Disadvantage of Flowchart:

1. For any change, Flowchart must redraw


2. Showing many looping and branching become complex
3. Modification of flowchart is time consuming.
Symbol Name Description

Terminal Terminal represent start and end

Input / Used for input (reading) and output


Output (printing) operation.

Used for data manipulation and data


Processing
operations.

Arrow Used to represent flow of operations.

Connector Used to connect different flow of lines

Decision Used to make decision

Example: Algorithm and Flowchart to check odd or even


Solution:
Algorithm:
Step 1: Start
Step 2: Declare a variable x
Step 3: Take a input from user and store in x
Step 4: IF x % 2 == 0 THEN
PRINT Even
ELSE
PRINT Odd
Step 5: End
Flowchart:

2. Problem Solving Requirements:

Sometimes it is not sufficient just to cope with problems. We have to solve those
problems. Most people are involving to solve the problem. These problems are
occurred while performing small task or making small decision. So, here are some
basic steps to solve the problems

Step 1: Identify and Define Problem

Explain your problem clearly as possible as you can.

Step 2: Generate Possible Solutions

• List out all the solution that you find. Do not focus on the quality of the solution

• Generate the maximum number of solutions as you can without considering the
quality of the solution
Step 3: Evaluate Alternatives

After generating the maximum solution, 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 Step2.

3.PHASES OF PROBLEM SOLVING:

Problem Solving Phase

• Analysis and Specification


Understand (define) the problem and what the solution must do
• Algorithm Development
Develop a comprehensive unambiguous logical sequence of steps to solve
the problem
• Verification of Algorithm
Follow steps closely (manually) to see if solution works.

Implementation Phase

• Program Development
Translate algorithm into a program written in a programming language
• Program Testing
Test program for syntactical and logical errors. Fix the errors.

Maintenance Phase

• Use
Use the program to solve real world problems
• Maintain
Modify the program to meet changing requirements
4. PROBLEM SOLVING STRATEGIES:
1. Identify the problem
The first step is to know which problem you need to solve. Then, you need to
find the root cause of the problem.
The best course of action is to gather as much data as possible, speak to the
people involved, and separate facts from opinions.
Once this is done, formulate a statement that describes the problem. Use
rational persuasion to make sure your team agrees.
2. Break the problem down
Identifying the problem allows you to see which steps need to be taken to
solve it.
First, break the problem down into achievable blocks. Then, use strategic
planning to set a time frame in which to solve the problem and establish a
timeline for the completion of each stage.
3. Generate potential solutions
At this stage, the aim isn’t to evaluate possible solutions but to generate as
many ideas as possible.
Encourage your team to use creative thinking and be patient — the best
solution may not be the first or most obvious one.
Use one or more of the different strategies in the following section to help
come up with solutions — the more creative, the better.
4. Evaluate the possible solutions
Once you’ve generated potential solutions, narrow them down to a shortlist.
Then, evaluate the options on your shortlist.
5. Implement and monitor the solutions
Once you have identified your solution and got buy-in from your team, it is
time to implement it.
But the work doesn’t stop there. You need to monitor your solution to see
whether it actually solves your problem.
Request regular feedback from the team members involved and have a
monitoring and evaluation plan in place to measure progress.
If the solution doesn’t achieve your desired results, start this step-by-step
process again

5. 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.
In this approach we look at the overall requirement and start coding. We
build the main function first, then add calls to various functions like add,
subtract etc... and then display the output. After doing all these we code the
individual functions for addition, subtraction etc.

6. ALGORITHM DESIGINING:
Algorithm design affects how well your solution works, how fast it runs,
how much memory it uses and how easy it is to understand and modify.
Choosing best right algorithm can make a big difference in the quality and
efficiency of your solution.
Designing algorithms requires a set of principles and techniques.
To begin, you must define the problem clearly and precisely including the
inputs and outputs, assumptions and goals of the solution breaking down the
problem into smaller and simpler subprograms can help, use recursion, divide,
and conquer.

7. PROGRAM VERIFICATION
Verification is the process of checking that software achieves its goal
without any bugs.it is the process to ensure whether the product that is
developed is right or not. It verifies whether the developed product fulfils
the requirements that we have.
The commonly used validation activities in software testing are usability
testing, performance testing, system testing, security testing, and
functionality testing. A few verification methods are inspection, code
review, disk checking and walkthroughs.
8. IMPROVING EFFICIENCY
One of the best ways to improve your algorithm efficiency and correctness
is to use pseudocode and diagrams to plan and visualize your algorithm
before you write any code.
Pseudocode is a simplified and informal way of describing the steps and
logic of your algorithm, using natural language and basic symbols.
The most efficient algorithm is one that takes the least amount of execution
time and memory usage possible while still yielding a correct answer.
9. ALGORITHM ANALYSIS AND NOTATIONS
Algorithm analysis is an important part of computational complexity
theory, which provides theoretical estimation for the required resources of
an algorithm to solve a specific computational problem.
Analysis of algorithm is the determination of the amount of time and space
resources required to execute it
Notations:

Asymptotic Notations is used to describe the running time of an algorithm-


how much time an algorithm takes with a given input n.
There are three different notations: big O, big Theta, and big Omega.

You might also like