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

Problem-Solving v2

The document introduces computer science and engineering concepts such as problem solving using computers, algorithms, flowcharting, and programming. It discusses the stages of solving a problem using a computer, including problem analysis, algorithm development, flowcharting, coding, compilation and execution. Examples of algorithms to find the greatest number of three inputs and to calculate the area of a rectangle are provided to illustrate algorithm development.

Uploaded by

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

Problem-Solving v2

The document introduces computer science and engineering concepts such as problem solving using computers, algorithms, flowcharting, and programming. It discusses the stages of solving a problem using a computer, including problem analysis, algorithm development, flowcharting, coding, compilation and execution. Examples of algorithms to find the greatest number of three inputs and to calculate the area of a rectangle are provided to illustrate algorithm development.

Uploaded by

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

20-12-2021

INDIAN INSTITUTE OF TECHNOLOGY ROORKEE


Introduction
Introduction to Computer Science and
• Today, computers are all around us. We use them for doing
Engineering
various tasks in a faster and more accurate manner. For
CSN-101 example, using a computer or smartphone, we can book
train tickets online.
Problem-solving using computers, Flowing charting technique and • Number of problems in our daily life.
writing Algorithm
• Suppose we have to calculate simple interest.
• Suppose we have to prepare a mark sheet .
Prof. Partha Pratim Roy • A computer is DUMB machine.
Associate professor, CSE Department
Indian Institute of Technology Roorkee • A computer cannot do anything alone without software i.e.
Program

Software Stages while solving a problem using computer

• Software, instructions that tell a computer what to do. The • Problem Analysis
software comprises the entire set of programs, procedures, • Algorithm Development
and routines associated with the operation of a computer • Flowcharting
system.
• Coding
• A set of instructions that directs a computer’s hardware to
perform a task is called a program, or software program. • Compilation and Execution
• The two main types of software are system software and • Debugging and Testing
application software. • Documentation
• System software controls a computer’s internal functioning,
chiefly through an operating system, and also controls
such peripherals as monitors, printers, and storage devices.

3 4

Problem Analysis Algorithm Development

• Process of becoming familiar with the problem. • Algorithm development is the act of designing the steps
that solve a particular problem for a computer or any
• We need to analyze and understand it well before solving it. other device to follow not excluding human beings but in
this case computers only and computer-like devices.
• Algorithm development steps. Steps in the development of
• The user’s requirements cannot be fulfilled without a clear Algorithms.
understanding of his / her problem in depth.
• Step by step description of the method to solve the problem.
• Effective procedure for solving the problem with an infinite
• Inadequate identification of problem may cause program less number of steps.
useful and insufficient.
• Developing an algorithm in a step of program design.

• Example Banking Solution, Hospital medical study

5 6

1
20-12-2021

Algorithm to find greatest number


The algorithm to add two numbers.
of three given numbers
• Declare variable ( Two variables to store the number input by • Ask the user to enter three integer values.
the user and one variable is used to store the output).
• Read the three integer values in num1, num2, and num3
• Take the input of two numbers. (integer variables).
• Apply the formula for addition.
• Add two numbers. • Check if num1 is greater than num2.
• Store the result in a variable.
• Print the result. • If true, then check if num1 is greater than num3

• If false, then check if num2 is greater than num3.

7 8

Algorithm to find area of rectangle Features of Algorithm


• Unambiguous − The algorithm should be unambiguous. Each
1. Define the width of the rectangle.
of its steps (or phases), and their inputs/outputs should be clear
2. Define the Height of the rectangle. and must lead to only one meaning.
3. Define Area of the rectangle. • Input − An algorithm should have 0 or more well-defined inputs.
4. Calculate the area of the rectangle by multiplying the width • Output − An algorithm should have 1 or more well-defined
and height of the rectangle. outputs and should match the desired output.
5. Assign the area of the rectangle to the area variable. • Finiteness − Algorithms must terminate after a finite number of
6. print the area of the rectangle. steps.
• Feasibility − Should be feasible with the available resources.
• Independent − An algorithm should have step-by-step
directions, which should be independent of any programming
code.

9 10

Flowcharting Advantages of Flowcharts

• Graphical representation of an algorithm using standard • Communication


symbols.
• Quickly provide logic , ideas and descriptions of algorithms.
• Includes a set of various standard shaped boxes that are
• Effective analysis
interconnected by flow lines.
• Clear overview entire problem.
• Flow lines have arrows directed of flow.
• Proper documentation
• Activities are written within boxes in English.
• Helps us to understand its logic in future.
• Communicates between programmers and business
persons. • Efficient coding
• More ease with comprehension flowchart as a guide
• Easy in debugging and program maintenance
• Debugging and maintenance of operating program

11 12

2
20-12-2021

Flowcharting Difference
Algorithm Flowchart
It is a procedure for solving It is a graphic representation of
problems. a process.

The process is shown in


The process is shown in step-by-
block-by-block information
step instruction.
diagram.
It is complex and difficult to It is intuitive and easy to
understand. understand.
It is convenient to debug errors. It is hard to debug errors.

The solution is showcased in The solution is showcased in


natural language. pictorial format.
13 14

Example 1: Print 1 to 20: Coding


Algorithm: Flowchart • The process of transforming the program logic design into
• Step 1: Initialize X computer language format.
as 0,
X=0 • An act of transforming operations in each box of the flowchart
• Step 2: Increment X in terms of the statement of a program.
by 1,
• The code written using programming language is also known
• Step 3: Print X, as source code.

• Step 4: If X is less • Coding isn’t the only task to be done to solve a problem
than 20 then go back using computer.
to step 2.

15 16

Compilation Execution

• Process of changing high-level language into machine-level • Execution in computer and software engineering is
language. the process by which a computer or virtual machine
It is by special software, COMPILER reads and acts on the instructions of a computer
• The compilation process tests the program whether it program. ...
contains syntax errors or not. • Programs for a computer may be executed in a batch
• If syntax errors are present, the compiler can not compile the process without human interaction or a user may type
code. commands in an interactive session of an interpreter.
• Once the compilation is completed then the program is
linked with other object programs needed for execution,
there by resulting in a binary program
• And then the program is located in the memory for the
purpose of execution and finally it is executed.

17 18

3
20-12-2021

Debugging and Testing Program Documentation

• Testing means verifying correct behavior. Testing can be • Any written text, illustrations, or video that describes
done at all stages of module development: requirements software or program to its users is called a program or
analysis, interface design, algorithm design, implementation, software document. Users can be anyone from a
and integration with other modules programmer, system analyst, and administrator to end-user.
• Debugging is a cyclic activity involving execution testing and • At various stages of development, multiple documents may
code correction. The testing that is done during debugging be created for different users. Software documentation is a
has a different aim than final module testing. Final module critical process in the overall software development process.
testing aims to demonstrate correctness, whereas testing • In modular programming documentation becomes even
during debugging is primarily aimed at locating errors. This more important because different modules of the software
difference has a significant effect on the choice of testing are developed by different teams.
strategies.

19 21

Two types of documentations Pseudocode

• Programmers' Documentation (Technical • Pseudocode is not an actual programming language. So it


documentation) cannot be compiled into an executable program.
– Maintain, redesign and upgrade • It uses short terms or simple English language syntaxes to
write code for programs before it is converted into a specific
– Logic, Data Flow Diagram , E-R, Algorithm and flowchart
programming language.
• This is done to identify top-level flow errors and understand
• User documentation (user manual) the programming data flows that the final program is going to
– Support to the user of the program use.
– Instructions for installation • This helps save time during actual programming as
conceptual errors have been already corrected.

22 23

Computer program Types or levels of programming language

• Computer program, detailed plan or procedure for solving a


problem with a computer; more specifically, an
unambiguous, ordered sequence of computational
instructions necessary to achieve such a solution.
• The distinction between computer programs and equipment
is often made by referring to the former as softwareand the
latter as hardware.
• Programs stored in the memory of a computer enable the
computer to perform a variety of tasks in sequence or even
intermittently.

24 25

4
20-12-2021

Low level language Machine level language

• It is very close to writing actual machine instructions, and it • Machine language is the lowest and most elementary level of
deals with a computer's hardware components and programming language and was the first type of
constraints. It works to control a computer's operational programming language to be developed.
semantics and provides little or no abstraction of • Machine language is basically the only language that a
programming ideas computer can understand and it is usually written in hex.
• In fact, a manufacturer designs a computer to obey just one
• In contrast to high-level language that used for developing language, its machine code, which is represented inside the
software, low-level code is not human-readable, and it is computer by a string of binary digits (bits) 0 and 1.
often cryptic. • The symbol 0 stands for the absence of an electric pulse and
• Assembly language and machine language are two the 1 stands for the presence of an electric pulse. Since a
examples of low-level programming languages. computer is capable of recognizing electric signals, it
understands machine language.

26 27

Machine Level Language Assembly Language


Advantage Disadvantage • An assembly language is a type of low-level programming
• Computer directly understands • Difficult to use language that is intended to communicate directly with a
machine instructions computer’s hardware.
• Unlike machine language, which consists of binary and
• Machine dependent
• Takes less execution time hexadecimal characters, assembly languages are designed
to be readable by humans.
• Difficult to Debug and modify • Low-level programming languages such as assembly
• Directly starts executing • All operation codes have to language are a necessary bridge between the underlying
• Machine language makes fast be remembered hardware of a computer and the higher-level programming
and efficient use of the languages—such as Python or JavaScript—in which modern
computer. software programs are written.

28 29

High Level Language Difference between

• User-friendly, Similar to natural languages High level language Low level language
• Platform independent It is programmer friendly language. It is a machine friendly language.

• Easy to write or remember High level language is less memory Low level language is high memory
efficient. efficient.
• Easy to learn and work
• While execution: translated into assembly language than to It is easy to understand. It is tough to understand.
machine language. It is simple to debug. It is complex to debug comparatively.
• Slow in execution but is efficient for developing programs.
It is complex to maintain
• Ex: C, C++, Python, Java, etc. It is simple to maintain.
comparatively.
It is portable. It is non-portable.

It can run on any platform. It is machine-dependent.

It needs compiler or interpreter for


It needs assembler for translation.
translation.
30 31

5
20-12-2021

Compiler Interpreter

• A high-level source program must be translated into a format • Like a compiler, it is also a translator which translates high-
that machine can understand. This is done by a software level to machine-level language.
called the compiler.
• Source code => Machine language code(Object code) • Translates and executes the program line by line.
• During the process of translation, the compiler reads the
source programs statement-wise and checks for syntax • Each line is checked for syntax error and then converted to
errors. the equivalent machine code.
• In case of any error, the computer generates a message
about the error.
• Ex. QBASIC, PERL, PHP, ASP, PYTHON, RUBY
• C, C++, Java, FORTRAN, Pascal, etc.

32 33

Difference between compiler and interpreter

Compiler Interpreter
Interpreter translates just one statement of Compiler scans the entire program and
the program at a time into machine code. translates the whole of it into machine code
at once.

An interpreter takes very less time to analyze A compiler takes a lot of time to analyze the
the source code. However, the overall time to source code. However, the overall time taken
execute the process is much slower. to execute the process is much faster.
Thanks…
An interpreter does not generate an A compiler always generates an intermediary
intermediary code. Hence, an interpreter is object code. It will need further linking. Hence
highly efficient in terms of its memory. more memory is needed.

Keeps translating the program continuously A compiler generates the error message only
till the first error is confronted. If any error is after it scans the complete program and
spotted, it stops working and hence hence debugging is relatively harder while
debugging becomes easy. working with a compiler.

34 38

You might also like