Chap_1_prob_solving
Chap_1_prob_solving
Problem solving with a computer involves leveraging computational tools, software, and algorithms to
identify, analyze, and address challenges. This fundamental process is crucial in various fields, from
software development to data analysis and artificial intelligence.
Problem Identification
The first step is to clearly define and understand the problem you want to solve. This involves
identifying the objectives, constraints, and requirements of the problem.
Data gathering
In many cases, data is crucial for problem solving. You may need to collect, retrieve, or generate data
that is relevant to the problem at hand.
Analysis
Using computational tools, you can analyze data and gain insights into the problem. This might involve
data visualization, statistical analysis, or more advanced techniques like machine learning.
Algorithm Design
Once you have a good understanding of the problem, you design algorithms or procedures that outline
how the computer should process the data to find a solution. This step is critical for creating an efficient
and effective solution.
1|Page
Programming
You implement the designed algorithms by writing code in a programming language. This code
instructs the computer on how to perform the necessary computations and operations.
Optimization
Depending on the problem's complexity, you may need to optimize the code to make it more efficient,
using techniques like algorithmic improvements, parallelization, or hardware acceleration.
Validation
Ensure that the solution meets the requirements and objectives of the problem. This may involve
comparing the results with expected outcomes and validating the accuracy of the solution.
Deployment
If the solution is intended for practical use, you deploy it in a real-world environment where it can
be accessed and used by others.
Maintenance
Continuously monitor and maintain the solution to ensure it remains functional and up-to-date. This
includes fixing any issues that arise and making improvements as needed.
Problem Analysis
Problem analysis is the initial phase of the problem-solving process. It involves a systematic
examination and understanding of a problem or challenge to gather information, identify its underlying
causes, and define its boundaries. The primary goal of problem analysis is to gain insight into the
problem's nature and characteristics, setting the stage for developing effective solutions.
Problem Definition:
Clearly articulate and define the problem. This includes specifying its scope, objectives, and any
constraints or limitation.
Information Gathering:
Collect relevant data and information related to the problem. This may involve conducting research,
interviews, surveys, or data analysis to understand the issue thoroughly.
2|Page
Root Cause Analysis:
Identify the root causes or contributing factors that lead to the problem. This step helps in addressing
the underlying issues rather than just the symptoms.
Boundary Definition:
Determine the boundaries of the problem. Understand what is included and excluded from the scope of
the problem to avoid scope creep.
Stakeholder Analysis:
Identify and involve relevant stakeholders or individuals affected by the problem. Understanding their
perspectives and needs is crucial for finding a solution that is acceptable to all parties.
Problem Decomposition:
Break down the problem into smaller, more manageable components or sub-problems. This simplifies
the analysis and solution-finding process.
Data Validation:
Ensure the accuracy and reliability of the data used in the analysis. Validate data sources and check for
any inconsistencies or errors.
Documentation
Keep thorough records of the problem analysis process. Document findings, insights, and any
assumptions made during this phase.
Quantitative Analysis:
If applicable, use quantitative methods such as statistics or modeling to analyze data and quantify the
problem's impact.
Qualitative Analysis:
Consider qualitative factors, such as human behavior, organizational culture, or subjective experiences,
that may be relevant to the problem.
Problem Prioritization :
Assess the urgency and importance of the problem. Determine whether it requires immediate attention
or can be addressed over time.
Risk Assessment:
Identify potential risks and consequences associated with the problem and its solutions. Evaluate the
potential impact of different courses of action.
3|Page
Alternative Perspectives:
Encourage diverse viewpoints and alternative perspectives on the problem. This can lead to more
innovative and comprehensive solutions.
Visualization :
Use visualization tools or techniques like diagrams, flowcharts, or mind maps to represent the problem
and its relationships visually.
Algorithm
Output: It produces a result or output based on the input and the steps performed
Algorithm:
Step1: Start
Step5: End
Problem2: Write an algorithm to read two numbers and find their sum
Algorithm:
4|Page
Step1: Start
Step6: End
Step1: Start
Step 3: C= 5/9*(F-32)
Step5: End
Type of Algorithms
The algorithm and flowchart, classification to the three types of control structures. They are:
1. Sequence
2. Branching (Selection)
3. Loop (Repetition)
Problem4: write algorithm to find the greater number between two numbers [Branching
(Selection)]
Step1: Start
Step5: Print C
Step6: End
5|Page
Problem5: A algorithm to find the largest value of any three numbers.
Step1: Start
Step7: End
1. Start
2. I ← 0
4. I ← I+2
6. End
Problem7: Design an algorithm which gets a natural value, n,as its input and calculates odd
numbers equal or less than n. Then write them in the standard output:
1.Start
2. Read n
3. I ← 1
4. Write I
5. I ← I + 2
7. End
6|Page
Problem8: Design an algorithm which generates even numbers between 1000 and 2000 and then
prints them in the standard output. It should also print total sum:
1. Start
2. I ← 1000 and S ← 0
3. Write I
4. S ← S + I
5. I ← I + 2
else go to line 7
7. Write S
8. End
Problem9: Design an algorithm with a natural number, n, as its input which calculates the
following formula and writes the result in the standard output:
S = ½ + ¼ + … +1/n
1. Start
2. Read n
3. I ← 2 and S ← 0
4. S= S + 1/I
5. I ← I + 2
7. End
Flowchart
7|Page
tool for visually conveying the logic and structure of an algorithm or a process. Here are some common
symbols used in flowcharts
Advantages of flowcharts:
Simplified Communication
Serve as a universal language, transcending language barriers and aiding communication across diverse
backgrounds
Identification of Bottlenecks:
Visualizing process flow helps identify slowdowns or bottlenecks, facilitating optimization for
improved efficiency.
8|Page
Documentation
Function as clear documentation for processes, offering a concise representation for analysis,
understanding, and improvement.
Problem solving
Aid in systematic analysis of steps, making it easier to pinpoint errors and devise solutions during
troubleshooting.
Decision Making
Valuable tools for decision-making, allowing visualization of consequences and aiding in strategic
planning within a process.
Standardization
Serve as standards for processes, ensuring consistency and guiding individuals to follow the same set of
steps
Process Improvement
Facilitate continuous improvement by highlighting areas for enhancement, particularly in quality
management and Six Sigma methodologies.
Label clearly
Clearly label symbols, arrows, and additional information.
Keep it simple:
Aim for simplicity to ensure easy understanding at a glance.
11 | P a g e
Problem5: An algorithm to calculate even numbers between 0 and 100
Problem6: Design an algorithm which gets a natural value, n,as its input and calculates odd
numbers equal or less than n. Then write them in the standard output:
12 | P a g e
Example of a flowchart for the same "FindMax" algorithm mentioned earlier:
Here is a brief history of C language that also showcases the hierarchy of programming languages
before C came into existence:
The development of the C programming language can be traced back to its parent node,
ALGOL 60 (algorithmic language), which was introduced in 1960 as the first computer
programming language to use a block structure.
From ALGOL, Martin Richards developed a type less language called BCPL (Basic Combined
Programming Language). This was also a high-level computer language
In 1970, Ken Thompson created a language using BCPL called B, which was also type less.
Then, Dennis Ritchie at AT&T Bell Labs took the development of C into his hands. Using the
foundations laid down by previous languages BCPL and B, he developed the C programming
language in 1972.
C was initially used to re-implement the Unix operating system, which was rewritten in C from
assembly language, and it quickly gained popularity for its portability and efficiency. So,
the development of the Unix operating system started in 1969. And in the year 1972, its code
was rewritten in the C programming language.
In 1985, windows 1.0 was released, and while its source code is not publicly available, it has
been stated that its kernel is mostly written in K programming language.
13 | P a g e
Linux, a popular operating system, started its development in 1991 using C programming
language and Lisp. After almost a year of development, it was released under the GNU license
and was used as part of the GNU operating system.
Oracle, the most widely used relational database management system (RDBMS), began its
development in 1977. In 1983, its code was rewritten from assembly language to C
programming language.
The C language was designed as a general-purpose programming language that helps in system
programming as well as application programming.
14 | P a g e
Basic Structure of C Program
1. Document section
2. Preprocessor/link Section
3. Definition section
6. Main function
15 | P a g e
How Does C Programming Works?
C language is a compiled programming language that is widely used for system programming,
embedded systems, and other low-level applications. The process of creating and executing a C
program involves several steps, including preprocessing, compiling, linking, and executing.
16 | P a g e
Creating
the Program:
The first step in using C is to create the program. This involves writing the source code in a text editor
or integrated development environment (IDE). The source code is a raw set of instructions that define
the behavior of the program.
Preprocessing:
Once the program has been created, it needs to be preprocessed. This step includes running the source
code through a preprocessor, which is a program that performs certain operations on the code before it
is compiled. These operations may include inserting header files, expanding macros, performing
conditional compilation, etc.
17 | P a g e
After preprocessing, the program must be compiled. The compilation process consists of translating
the source code into machine code that can be executed by the computer's processor. The compiler
reads the source code and generates an object file, which contains the compiled code for the program.
In conclusion, the process of creating and executing a C program involves several steps, including
preprocessing, compiling, linking, and executing. Understanding these steps is crucial for developing
efficient and effective C programs.
Testing
o Testing is a crucial phase in software development to ensure the correctness and reliability of a
C program
o Types of testing include unit testing (testing individual functions), integration testing (testing the
interaction between functions/modules), and system testing (testing the entire program
o Testing involves creating test cases, running the program with various inputs, and verifying that
it produces the expected outputs
o Tools like debugging, assertions, and testing frameworks can aid in testing C programs
Documentation
o The preprocessor is a tool that processes the code before actual compilation
o Preprocessor directives start with # and include #include, #define, # ifdef and others
o # include is used to include header files, providing declarations of functions and data types
o # define is used to create macros, which are essentially symbolic constants or code fragments
o The preprocessor simplifies code maintenance and helps manage code modifications
Macros
o Macros are defined using #define and are replaced with their values during preprocessing
o They can be used for defining constants (e.g., #define PI 3.1415) or for creating code shortcuts
o Macros are commonly used in conditional compilation (e.g., # ifdef and #ifndef ), where code is
included or excluded based on certain conditions
19 | P a g e
An algorithm is a step-by-step set of instructions for solving a particular problem or performing a
specific task
7.Why are algorithms considering independent of programming language?
Algorithms provide a language-agnostic, high-level description of a solution, making them adaptable to
various programming languages.
8.What is the significance of effectiveness in algorithm?
Effectiveness in algorithms implies that each step can be executed in a finite amount of time, ensuring
the practical feasibility and efficiency of the solution.
9.What is the primary purpose of a flow chart?
The primary purpose of a flowchart is to visually represent the steps and logic of a process or
algorithm, providing a clear and structured way to understand and communicate the flow of activities
10.Name one advantage of using flow chart for communication?
Flowcharts serve as a universal language, transcending language barriers and aiding communication
across diverse backgrounds, ensuring a common understanding of processes.
11.Why is it recommended to start and end a flow chart with terminal?
Starting and ending a flowchart with terminals, represented by oval shapes, establishes clear entry and
exit points for the process, making it easy to identify where the flow begins and concludes
B short questions
1.Explain the step involved in algorithm design.
Algorithm design encompasses several key steps:
20 | P a g e
I. Deployment: Implement the solution in a real-world setting.
2.What are the key activities in the testing and debugging phase of problem solving?
Problem decomposition involves breaking down complex problems into smaller, more manageable
components. This:
Exercise
22 | P a g e
21. Draw flowchart for the problem of determining prime number?
22. Draw a flowchart which generates first 50 items of the Fibonacci series: 1, 1, 2, 3, 5, 8,…?
23. Design an algorithm to convert a decimal number, n, to binary format?
23 | P a g e
24 | P a g e