SlideShare a Scribd company logo
1 of 62
Download to read offline
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
1
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMING
UNIT I
INTRODUCTION
Introduction: Fundamentals of digital computers. Problem Solving Techniques: Algorithm, Flow
Chart, Pseudo code, Program Control Structures, Programming Paradigms: Programming
languages: Generations of Programming Languages, Language Translators, and Features of a
Good Programming Languages.
1.1 INTRODUCTION: FUNDAMENTALS OF DIGITAL COMPUTERS.
Today’s world is an information-rich world and it has become a necessity for everyone to
know about computers. A computer is an electronic data processing device, which accepts and
stores data input, processes the data input, and generates the output in a required format. The
purpose of this tutorial is to introduce you to Computers and its fundamentals.
FUNCTIONALITIES OF A COMPUTER
Any digital computer carries out the following five functions:
Step 1 - Takes data as input.
Step 2 - Stores the data/instructions in its memory and uses them as required.
Step 3 - Processes the data and converts it into useful information.
Step 4 - Generates the output.
Step 5 - Controls all the above four steps.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
2
ADVANTAGES OF COMPUTERS
Following are certain advantages of computers.
High Speed
Computer is a very fast device.
 It is capable of performing calculation of very large amount of data.
 The computer has units of speed in microsecond, nanosecond, and even the picoseconds.
 It can perform millions of calculations in a few seconds as compared to man who will
spend many months to perform the same task.
Accuracy
 In addition to being very fast, computers are very accurate.
 The calculations are 100% error free.
 Computers perform all jobs with 100% accuracy provided that the input is correct.
Storage Capability
Memory is a very important characteristic of computers.
 A computer has much more storage capacity than human beings.
 It can store large amount of data.
 It can store any type of data such as images, videos, text, audio, etc.
Diligence
 Unlike human beings, a computer is free from monotony, tiredness, and
lack of concentration.
 It can work continuously without any error and boredom.
 It can perform repeated tasks with the same speed and accuracy.
Versatility
 A computer is a very versatile machine.
 A computer is very flexible in performing the jobs to be done.
 This machine can be used to solve the problems related to various fields.
 At one instance, it may be solving a complex scientific problem and the
very next moment it may be playing a card game.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
3
Reliability
 A computer is a reliable machine.
 Modern electronic components have long lives.
 Computers are designed to make maintenance easy.
Automation
 Computer is an automatic machine.
 Automation is the ability to perform a given task automatically. Once the computer
receives a program i.e., the program is stored in the computer memory, then the program
and instruction can control the program execution without human interaction.
Reduction in Paper Work and Cost
 The use of computers for data processing in an organization leads to reduction in paper work
and results in speeding up the process.
 As data in electronic files can be retrieved as and when required, the
problem of maintenance of large number of paper files gets reduced.
 Though the initial investment for installing a computer is high, it
substantially reduces the cost of each of its transaction.
DISADVANTAGES OF COMPUTERS
Following are certain disadvantages of computers.
No I.Q.
 A computer is a machine that has no intelligence to perform any task.
 Each instruction has to be given to the computer.
 A computer cannot take any decision on its own.
Dependency
 It functions as per the user’s instruction, thus it is fully dependent on humans.
Environment
 The operating environment of the computer should be dust free and suitable.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
4
No Feeling
 Computers have no feelings or emotions.
 It cannot make judgment based on feeling, taste, experience, and
knowledge unlike humans.
THE APPLICATIONS OF COMPUTER
Business
A computer has high speed of
calculation, diligence, accuracy,
reliability, or versatility which has
made it an integrated part in all
business organizations.
Computer is used in business organizations for:
 Payroll calculations
 Budgeting
 Sales analysis
 Financial forecasting
 Managing employee database
 Maintenance of stocks, etc.
Banking
Today, banking is almost totally
dependent on computers.
Banks provide the following facilities:
 Online accounting facility,
which includes checking
current balance, making
deposits and overdrafts,
checking interest charges,
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
5
shares, and trustee records.
 ATM machines which are
completely automated are
making it even easier for
customers to deal with banks.
Insurance
Insurance companies are keeping all records up- to-date with the help of computers.
Insurance companies, finance houses, and stock broking firms are widely using computers
for their concerns.
Insurance companies are maintaining a database of all clients with information showing:
 Procedure to continue with policies
 Starting date of the policies
 Next due installment of a policy
 Maturity date
 Interests due
 Survival benefits
 Bonus
Education
The computer helps in providing a lot of facilities in the education system.
 The computer provides a tool in the education system known as CBE
(Computer Based Education). CBE involves control, delivery, and
evaluation of learning.
 Computer education is rapidly
increasing the graph of number
of computer students.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
6
 There are a number of methods in which educational institutions can use a computer to
educate the students.
 It is used to prepare a database about performance of a student and analysis is carried out
on this basis.
Marketing
In marketing, uses of the computer are following:
Advertising - With computers,
advertising professionals create art
and graphics, write and revise copy,
and print anddisseminate ads with the
goal of selling more products.
Home Shopping - Home shopping has been made possible through the use of computerized
catalogues that provide access to product information and permit direct entry of orders to be filled
by the customers.
Healthcare
Computers have become an important part in hospitals, labs, and dispensaries.
They are being used in hospitals to keep the record of patients and medicines. It is
alsoused in scanning and diagnosing different diseases. ECG, EEG, ultrasounds and
CT scans, etc. are also done by computerized machines.
Following are some major fields of health care in which computers are used.
 Diagnostic System - Computers are used to collect data and identify the
cause of illness.
 Lab-diagnostic System - All tests can be done and the reports are prepared by computer.
 Patient Monitoring System - These are used to check the patient's signs for abnormality
such as in Cardiac Arrest, ECG, etc.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
7
Pharma Information System
Computer is used to check drug labels,
expiry dates, harmful side effects, etc.
Surgery - Nowadays, computers are also
used in performing surgery.
Engineering Design
Computers are widely used for Engineering purpose. One of the major areas is CAD (Computer
Aided Design) that provides creation and modification of images. Some of the fields are:
Structural Engineering - Requires
stress and strain analysis for design of
ships, buildings, budgets, airplanes,
etc.
Industrial Engineering -
Computers deal with design,
implementation, and
improvement of integrated
systems of people, materials, and
equipment.
Architectural Engineering - Computers help in planning towns, designing buildings,
determining a range of buildings on a site using both 2D and 3D drawings.
Military
Computers are largely used in defence. Modern tanks, missiles, weapons, etc. Military also
employs computerized control systems. Some military areas where a computer has been used are:
 Missile Control
 Military Communication
 Military Operation and Planning
 Smart Weapons
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
8
Communication
Communication is a way to convey a message, an idea, a picture, or speech that is
received and understood clearly and correctly by the person for whom it is meant.
Some main areas in this category are:
 E-mail
 Chatting
 Usenet
 FTP
 Telnet
 Video-conferencing
Government
Computers play an important role in government services. Some major fields in this
category are:
 Budgets
 Sales tax department
 Income tax department
 Computation of male/female ratio
 Computerization of voters lists
 Computerization of PAN card
 Weather forecasting
CLASSIFICATION OR TYPES OF COMPUTERS
Computers can be broadly classified by their speed and computing power.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
9
Sl.No. Type Specifications
1 Micro Computer It is a single user computer system, is minimal in size and
storage capacity.
2 Mini Computer It is a multi-user computer system, capable of supporting
hundreds of users simultaneously.
3 Main Frame It is a multi-user computer system, capable of supporting
hundreds of users simultaneously. Software technology is
different from minicomputer.
4 Super Computer It is an extremely fast computer, which can execute hundreds of
millions of instructions per second.
Micro computer
Micro computer, an electronic device with a microprocessor as its central processing
unit (CPU). High-performance microcomputer systems began to be used widely in business, in
engineering, in “smart” or intelligent machines employed in the factory and office, and in military
electronics systems.
A microcomputer is now primarily called a personal computer (PC), or a device based on
a single-chip microprocessor. Common microcomputers include laptops and desktops. Beyond
standard PCs, microcomputers also include some calculators, mobile phones, notebooks,
workstations and embedded systems.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
10
Applications of Micro computers:
PC is being widely used in many fields like home, office, data collection, business, education,
entertainment, publishing, etc.
Mini computer
It is a midsize multi-processing system capable of supporting up to 250 users
simultaneously. A minicomputer is a type of computer that possesses most of the features and
capabilities of a large computer but is smaller in physical size.
A minicomputer fills the space between the mainframe and microcomputer, and is smaller
than the former but larger than the latter. Minicomputers are mainly used as small or mid-range
servers operating business and scientific applications.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
11
Applications of Mini computers:
The minicomputers are used as real-time applications in Industries, bookings, and
Research Centres. Banks also use minicomputers for preparing payroll for employees’ salaries,
records, tracking of financial accounts, etc. As well as in the field of Higher Education and
Engineering.
Mainframe
Mainframe is very large in size and is an expensive computer capable of supporting
hundreds or even thousands of users simultaneously. Mainframe executes many
programs concurrently and supports many simultaneous execution of programs.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
12
Applications of Mainframe Computers:
Mainframe computers are mainly used by departmental and commercial organizations like Banks,
Companies, Scientific research centers, and governmental departments like railways. These
computers can work for 24 hours. Hundreds of users can work on these computations
simultaneously.
Using the mainframe completes the tasks, Such as keeping details of payments, research centres,
advertising, sending bills and notices, paying employees, ticket booking, maintaining details of
purchases by users, keeping detailed tax details, etc.
Supercomputer
Supercomputers are one of the fastest computers currently available.
Supercomputers are very expensive and are employed for specialized applications
that require immense amount of mathematical calculations (number crunching).
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
13
Applications of Super computers:
 In research and study of energy and nuclear weapons and designing the aircraft, airplanes,
and flight simulators.
 Climate research and Weather Forecasting and Prediction of Natural Disasters.
 Spaceship and Satellite Launching.
 Used in scientific research laboratories.
 Used in Chemical and Biological research and for highly calculation complex tasks.
COMPUTER COMPONENTS
All types of computers follow the same basic logical structure and perform the
following five basic operations for converting raw input data into information
useful to their users.
Sr. No. Operation Description
1 Take Input
The process of entering data and instructions into the computer
system.
2 Store Data
Saving data and instructions so that they are available for
processing as and when required.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
14
3 Processing Data
Performing arithmetic, and logical operations on data in order
to convert them into useful information.
4
Output
Information
The process of producing useful information or results for the
user, such as a printed report or visual display.
5
Control the
workflow
Directs the manner and sequence in which all of the above
operations are performed.
Input Unit
This unit contains devices with the help of which we enter data into the computer.
This unit creates a link between the user and the computer. The input devices
translate the information into a form understandable by the computer.
CPU (Central Processing Unit)
CPU is considered as the brain of the computer. CPU performs all types of data
processing operations. It stores data, intermediate results, and instructions
(program). It controls the operation of all parts of the computer.
CPU itself has the following three components:
 ALU (Arithmetic Logic Unit)
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
15
 Memory Unit
 Control Unit
Output Unit
The output unit consists of devices with the help of which we get the information
from the computer. This unit is a link between the computer and the users. Output
devices translate the computer's output into a form understandable by the users.
COMPUTER MEMORY
A memory is just like a human brain. It is used to store data and
instructions. Computer memory is the storage space in computer where data is to be processed
and instructions required for processing are stored. The memory is divided into large number of
small parts called cells. Each location or cell has a unique address which varies from zero to
memory size minus one. For example if computer has 64k words, then this memory unit has 64 *
1024=65536 memory locations. The address of these locations varies from 0 to 65535.
Memory is primarily of three types
 Cache Memory
 Primary Memory/Main Memory
 Secondary Memory
Cache Memory
Cache memory is a very high speed semiconductor memory which can
speed up CPU. It acts as a buffer between the CPU and main memory. It is used to hold those
parts of data and program which are most frequently used by CPU. The parts of data and
programs are transferred from disk to cache memory by operating system, from where CPU can
access them.
Advantages
The advantages of cache memory are as follows:
 Cache memory is faster than main memory.
 It consumes less access time as compared to main memory.
 It stores the program that can be executed within a short period of time.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
16
 It stores data for temporary use.
Disadvantages
The disadvantages of cache memory are as follows:
 Cache memory has limited capacity.
 It is very expensive.
Primary Memory /MainMemory
Primary memory holds only those data and instructions on which computer
is currently working. It has limited capacity and data is lost when power is switched off. It is
generally made up of semiconductor device. These memories are not as fast as registers. The data
and instruction required to be processed reside in main memory. It is divided into two
subcategories RAM and ROM.
Characteristics of Main Memory
 These are semiconductor memories It is known as main memory.
 Usually volatile memory.
 Data is lost in case power is switched off.
 It is working memory of the computer.
 Faster than secondary memories.
 A computer cannot run without primary memory.
Secondary Memory
This type of memory is also known as external memory or non-volatile. It
is slower than main memory. These are used for storing data/Information permanently. CPU
directly does not access these memories instead they are accessed via input-output routines.
Contents of secondary memories are first transferred to main memory, and then CPU can access
it. For example : disk, CD-ROM, DVD etc.
Characteristic of Secondary Memory
 These are magnetic and optical memories It is known as backup memory.
 It is non-volatile memory.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
17
 Data is permanently stored even if power is switched off.
 It is used for storage of data in a computer.
 Computer may run without secondary memory.
 Slower than primary memories
Generations of Computers
Generation in computer terminology is a change in technology a computer
is/was being used. Initially, the generation term was used to distinguish between
varying hardware technologies. Nowadays, generation includes both hardware and
software, which together make up an entire computer system.
There are five computer generations known till date. Each generation has
been discussed in detail along with their time period and characteristics. In the
following table, approximate dates against each generation has been mentioned,
which are normally accepted.
Following are the main five generations of computers.
First Generation Computers
The period of first generation was from 1946-1959. The computers of first
generation used vacuum tubes as the basic components for memory and circuitry
for CPU (Central Processing Unit). These tubes, like electric bulbs, produced a lot
of heat and the installations used to fuse frequently. Therefore, they were very
expensive and only large organizations were able to afford it.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
18
In this generation, mainly batch processing operating system was used.
Punch cards, paper tape, and magnetic tape was used as input and output devices.
The computers in this generation used machine code as the programming language.
The main features of the first generation are:
 Vacuum tube technology
 Unreliable
 Supported machine language only
 Very costly
 Generated a lot of heat
 Slow input and output devices
 Huge size
 Need of AC
 Non-portable
 Consumed a lot of electricity
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
19
Some computers of this generation were:
 ENIAC
 EDVAC
 UNIVAC
 IBM-701
 IBM-650
Second Generation Computers
The period of second generation was from 1959-1965. In this generation, transistors were used
that were cheaper, consumed less power, more compact in size, more reliable and faster than the
first generation machines made of vacuum tubes. In this generation, magnetic cores were used as
the primary memory and magnetic tape and magnetic disks as secondary storage devices.
In this generation, assembly language and high-level programming languages like
FORTRAN, COBOL were used. The computers used batch processing and
multiprogramming operating system.
The main features of second generation are:
 Use of transistors
 Reliable in comparison to first generation computers
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
20
 Smaller size as compared to first generation computers
 Generated less heat as compared to first generation computers
 Consumed less electricity as compared to first generation computers
 Faster than first generation computers
 Still very costly
 AC required
 Supported machine and assembly languages
Some computers of this generation were:
 IBM 1620
 IBM 7094
 CDC 1604
 CDC 3600
 UNIVAC 1108
Third Generation Computers
The period of third generation was from 1965-1971. The computers of third
generation used Integrated Circuits (ICs) in place of transistors. A single IC has
many transistors, resistors, and capacitors along with the associated circuitry.
The IC was invented by Jack Kilby. This development made computers smaller in
size, reliable, and efficient. In this generation remote processing, time-sharing,
multi-programming operating system were used. High-level languages
(FORTRAN-II TO IV, COBOL, PASCAL PL/1, BASIC, ALGOL-68 etc.) were
used during this generation.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
21
The main features of third generation are:
 IC used
 More reliable in comparison to previous two generations
 Smaller size
 Generated less heat
 Faster
 Lesser maintenance
 Costly
 AC required
 Consumed lesser electricity
 Supported high-level language
Some computers of this generation were:
 IBM-360 series
 Honeywell-6000 series
 PDP (Personal Data Processor)
 IBM-370/168
 TDC-316
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
22
Fourth Generation Computers
The period of fourth generation was from 1971-1980. Computers of fourth generation used Very
Large Scale Integrated (VLSI) circuits. VLSI circuits having about 5000 transistors and other
circuit elements with their associated circuits on a single chip made it possible to have
microcomputers of fourth generation.
Fourth generation computers became more powerful, compact, reliable, and affordable. As a
result, it gave rise to Personal Computer (PC) revolution. In this generation, time sharing, real
time networks, distributed operating system were used. All the high-level languageslike C, C++,
DBASE etc., were used in this generation.
The main features of fourth generation are:
 VLSI technology used
 Very cheap
 Portable and reliable
 Use of PCs
 Very small size
 Pipeline processing
 No AC required
 Concept of internet was introduced
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
23
 Great developments in the fields of networks
 Computers became easily available
Some computers of this generation were:
 DEC 10
 STAR 1000
 PDP 11
 CRAY-1(Super Computer)
 CRAY-X-MP(Super Computer)
Fifth generation computers
The period of fifth generation is 1980-till date. In the fifth generation, VLSI
technology became ULSI (Ultra Large Scale Integration) technology, resulting in
the production of microprocessor chips having ten million electronic components.
This generation is based on parallel processing hardware and AI (Artificial
Intelligence) software. AI is an emerging branch in computer science, which
interprets the means and method of making computers think like human beings. All
the high-level languages like C and C++, Java, .Net etc., are used in this generation.
AI includes:
 Robotics
 Neural Networks
 Game Playing
 Development of expert systems to make decisions in real-life situations
 Natural language understanding and generation
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
24
The main features of fifth generation are:
 ULSI technology
 Development of true artificial intelligence
 Development of Natural language processing
 Advancement in Parallel Processing
 Advancement in Superconductor technology
 More user-friendly interfaces with multimedia features
 Availability of very powerful and compact computers at cheaper rates
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
25
Some computer types of this generation are:
 Desktop
 Laptop
 NoteBook
 UltraBook
 ChromeBook
PROBLEM
Sometimes referred to as an issue, a problem is any situation that occurs that is unexpected or
prevents something from occurring. When dealing with computer problems, you must first
understand the source of the problem and then find a solution to fix the problem.
PROBLEM SOLVING
Problem solving is the systematic approach to define the problem and creating number of
solutions. The problem solving process starts with the problem specifications and ends with a
Correct program.
STEPS INVOLVED IN PROBLEM SOLVING
A computer cannot solve a problem on its own. One has to provide step by step solutions of the
problem to the computer. In fact, the task of problem solving is not that of the computer. It is the
programmer who has to write down the solution to the problem in terms of simple operations
which the computer can understand and execute.
In order to solve a problem by the computer, one has to pass though certain
stages or steps. They are
1. Understanding the problem
2. Analyzing the problem
3. Developing the solution
4. Coding and implementation.
1. Understanding the problem: Here we try to understand the problem to be solved in totally.
Before with the next stage or step, we should be absolutely sure about the objectives of the given
problem.
2. Analyzing the problem: After understanding thoroughly the problem to be solved, we look
different ways of solving the problem and evaluate each of these methods. The idea here is to
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
26
search an appropriate solution to the problem under consideration. The end result of this stage is a
broad overview of the sequence of operations that are to be carried out to solve the given problem.
3. Developing the solution: Here the overview of the sequence of operations that was the result
of analysis stage is expanded to form a detailed step by step solution to the problem under
consideration.
4. Coding and implementation: The last stage of the problem solving is the conversion of the
detailed sequence of operations in to a language that the computer can understand. Here each step
is converted to its equivalent instruction or instructions in the computer language that has been
chosen for the implantation.
1.2 PROBLEM SOLVING TECHNIQUES
 Problem solving technique is a set of techniques that helps in providing logic for solving a
problem. Problem solving can be expressed in the form of
1. Algorithms.
2. Flowcharts.
3. Pseudo codes.
4. Programs
1.2.1. ALGORITHM
 An algorithm is defined as a step by step procedure for solving any problem.
 It is also asequence of finite instructions used to refer the logic of a program.
 It should be precise rules and clearly specify how to solve a problem.
Characteristic of Algorithm
 The algorithm should be written in sequence using simple English.
 Algorithm has a finite number of inputs.
 Every instruction should be precise and unambiguous.
 Ensure that the algorithm has proper termination.
 The desired output must be obtained only after the algorithm terminates.
Qualities of an Algorithm
The following are the primary factors that are often used to judge the quality of the algorithms.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
27
 Time: To execute a program, the computer system takes some amount of time. The lesser
is the time required, the better is the algorithm.
 Memory: To execute a program, computer system takes some amount of memory space.
The lesser is the memory required, the better is the algorithm.
 Accuracy: Multiple algorithms may provide suitable or correct solutions to a given
problem, some of these may provide more accurate results than others, and such
algorithms may be suitable.
 Sequence: The procedure of an algorithm must be in a sequential form.
Example 1: Write an algorithm to print “Good Morning”.
Step 1: Start
Step 2: Print “Good Morning”
Step 3: Stop
Example 2: Write an algorithm to print sum of two numbers.
Step 1: Start
Step 2: Input a,b
Step 3: Calculate c=a+b
Step 4: Display c
Step 5: Stop
BUILDING BLOCKS OF ALGORITHM (Statements, State, Control flow & Functions):
Algorithms can be constructed from basic building blocks namely, sequence, selection and
iteration.
Statements
 Statement is a single action in a computer.
 It is an instruction written in a high-level language that commands the computer to
perform a specified action.
 A program written in such a language is formed by a sequence of one or more statements.
A statement may have internal components (e.g., expressions).
There are two major generic kinds of statements,
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
28
1. Simple statements
 assignment: A:= A + 5
 goto: goto next;
 return: return 5;
 call: function()
2. Compound statements
 block: begin ------- end
 for-loop: for (…) ________
 if-statement: if ----else----
 switch-statement: switch (c) { case ‘a’: alert(); break; case ‘q’: quit(); break; }
 while-loop: while (…) DO -----
State:
 Transition from one process to another process under specified condition with in atime is
called state.
Example: Initial state and End state
Control flow:
 The process of executing the individual statements in a given order is called control flow.
It is also called as flow of control. The control can be executed in three ways
 sequence
 selection
 iteration
Sequence:
 All the instructions are executed one after another is called sequence execution.
Example: Algorithm for Baking Bread
Step1: Add flour.
Step 2: Add salt.
Step 3: Add yeast.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
29
Step 4: Mix.
Step 5: Add water.
Step 6: Knead.
Step 7: Let rise.
Step 8: Bake.
Selection
 Selection control structures (or) Decision structures allows the program to make a choice
between two alternate paths whether it is true or false.
 IF...THEN or IF..THEN..ELSE or a case structures are the selection structures. This logic
is used for making decisions.
1) IF..THEN Structures
This makes a choice between two processes. If the condition is true it performs the process.
If the condition in false it skips over the process.
Pseudocode
IF condition THEN
process 1
…
…
ENDIF
b) IF..THEN...ELSE structure
In this structure if the condition is true it executes
process 1 else if the condition is false it executes process 2.
In this either the process 1 or process 2 gets executed depending on the condition.
Pseudocode Flowchart
IF condition then
process 1
…
ELSE
process 2
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
30
…
ENDIF
Example: Write an algorithm to check whether he is eligible to vote?
Step 1: Start
Step 2: Get age
Step 3: if age >= 18 print “Eligible to vote”
Step 4: else print “Not eligible to vote”
Step 6: Stop
1.2.3.3 Iteration:
 In some programs, certain set of statements are executed again and again based upon
conditional test. i.e. executed more than one time.
 This type of execution is called looping or iteration.
Example: Find the factorial of a given number.
Algorithm
Step 1 : Start
Step 2 : Initialize the value of fact and i to 1
Step 3 : READ the value of n.
Step 4 : If i<= n do the following else Goto step6.
Step 4.1 : fact = fact*i
Step 4.2 :i=i+1
Step 5 :Goto step4
Step 6 : Print fact
Step 7 : Stop
Functions:
 Function is a sub program which consists of block of code (set of instructions) that
performs a particular task.
 For complex problems, the problem is been divided into smaller and simpler tasks during
algorithm design.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
31
 Once a function is written, it can be used over and over and over again. Functions can be
“called” from the inside of other functions.
Steps to Writing a Function
 Understand the purpose of the function.
 Define the data that comes into the function from the caller (in the form of parameters)!
 Define what data variables are needed inside the function to accomplish its goal.
 Decide on the set of steps that the program will use to accomplish this goal.
Benefits of Using Functions
 Reduction in line of code
 code reuse
 Better readability
 Information hiding
 Easy to debug and test
 Improved maintainability
Example: Algorithm for addition of two numbers using function
Main function()
Step 1: Start
Step 2: Call the function add()
Step 3: Stop
sub function add()
Step 1: Function start
Step 2: Get a, b Values
Step 3: add c=a+b
Step 4: Print c
Step 5: Return
NOTATIONS
FLOW CHART
 A flow chart is a diagrammatic representation that illustrates the sequence of operations to
be performed to arrive at the solution.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
32
 Each step in the process is represented by a different symbol and contains a short
description of the process step. The flow chart symbols are linked together with arrows
showing the flow direction of the process.
 The purpose of flowchart is making the logic of the program clear in a visual
representation.
Rules for drawing a flowchart
1. The flowchart should be clear, neat and easy to follow.
2. The flowchart must have a logical start and finish.
3. Only one flow line should come out from a process symbol.
4. Only one flow line should enter a decision symbol. However, two or three flow lines may leave
the decision symbol.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
33
5. Only one flow line is used with a terminal symbol.
6. Within standard symbols, write briefly and precisely.
7. Intersection of flow lines should be avoided.
Advantages of flowchart:
 Communication: - Flowcharts are better way of communicating the logic of a system to
all concerned.
 Effective analysis: - With the help of flowchart, problem can be analyzed in more
effective way.
 Proper documentation: - Program flowcharts serve as a good program documentation,
which is needed for various purposes.
 Efficient Coding: - The flowcharts act as a guide or blueprint during the systems analysis
and program development phase.
 Proper Debugging: - The flowchart helps in debugging process.
 Efficient Program Maintenance: - The maintenance of operating program becomes easy
with the help of flowchart. It helps the programmer to put efforts more efficiently on that
part.
Disadvantages of flow chart:
 Complex logic: - Sometimes, the program logic is quite complicated. In that case,
flowchart becomes complex and clumsy.
 Alterations and Modifications: - If alterations are required the flowchart may require re-
drawing completely.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
34
 Reproduction: - As the flowchart symbols cannot be typed, reproduction of flowchart
becomes a problem.
 Cost: For large application the time and cost of flowchart drawing becomes costly.
PSEUDO CODE
Pseudocode is a kind of structure english for designing algorithm. Pseudocodes came from
two words. Pseudo and code pseudo means imitation and code refer to instructions, written in a
programming language.
 Pseudocode cannot be compiled nor executed, and there are no real formatting or syntax
rules.
 The benefit of pseudo code is that it enables the programmer to concentrate on the
algorithms without worrying about all the syntactic details of a particular programming
language.
 In fact, you can write pseudo code without even knowing what programming language
you will use for the final implementation.
 It gives us the sketch of the program before actual coding.
 It is not a machine readable
 Pseudo code can’t be compiled and executed.
 There is no standard syntax for pseudo code.
Guidelines for writing pseudo code:
 Write one statement per line
 Capitalize initial keyword
 Indent to show hierarchy, improve readability, and show nested constructs.
 End multiline structure
 Keep statements language independent
Common keywords used in pseudocode
The following gives common keywords used in pseudocodes.
1. // : This keyword used to represent a comment.
2. BEGIN,END : Begin is the first statement and end is the last statement.
3. INPUT, GET, READ : The keyword is used to inputting data.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
35
4. COMPUTE, CALCULATE : used for calculation of the result of the given expression.
5. ADD, SUBTRACT, INITIALIZE:used for addition, subtraction and initialization.
6. OUTPUT, PRINT, DISPLAY : It is used to display the output of the program.
7. IF, ELSE, ENDIF : used to make decision.
8. WHILE, ENDWHILE : used for iterative statements.
9. FOR, ENDFOR :Another iterative increment/decrement tested automatically.
Example
Advantages:
 Pseudo is independent of any language; it can be used by most programmers.
 It is easy to translate pseudo code into a programming language.
 It can be easily modified as compared to flowchart.
 Converting a pseudo code to programming language is very easy as compared with
converting a flowchart to programming language.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
36
Disadvantages:
 It does not provide visual representation of the program’s logic.
 There are no accepted standards for writing pseudo codes.
 It cannot be compiled nor executed.
 For a beginner, It is more difficult to follow the logic or write pseudo code ascompared to
flowchart.
Comparison of algorithm, flowchart and pseudocode
1.3 Programming Paradigms
Paradigm can also be termed as a method to solve some problems or do some tasks. A
programming paradigm is an approach to solve the problem using some programming language or
also we can say it is a method to solve a problem using tools and techniques that are available to us
following some approach. There are lots of programming languages that are known but all of them
need to follow some strategy when they are implemented and this methodology/strategy is
paradigms.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
37
Imperative programming paradigm:
It is one of the oldest programming paradigm. It features close relation relation to machine
architecture. It is based on Von Neumann architecture. It works by changing the program state
through assignment statements. It performs step by step task by changing state. The main focus is
on how to achieve the goal. The paradigm consists of several statements and after execution of all
the result is stored.
Declarative programming paradigm:
It is divided as Logic, Functional, Database. In computer science the declarative programming is a
style of building programs that expresses logic of computation without talking about its control
flow. It often considers programs as theories of some logic.It may simplify writing parallel
programs. The focus is on what needs to be done rather how it should be done basically emphasize
on what code code is actually doing. It just declare the result we want rather how it has be produced.
This is the only difference between imperative (how to do) and declarative (what to do)
programming paradigms. Getting into deeper we would see logic, functional and database.
Python supports three types of Programming paradigms
 Object Oriented programming paradigms
 Procedure Oriented programming paradigms
 Functional programming paradigms
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
38
Object Oriented programming paradigms
In the object-oriented programming paradigm, objects are the key element of paradigms. Objects
can simply be defined as the instance of a class that contains both data members and the method
functions. Moreover, the object-oriented style relates data members and methods functions that
support encapsulation and with the help of the concept of an inheritance, the code can be easily
reusable but the major disadvantage of object-oriented programming paradigm is that if the code is
not written properly then the program becomes a monster.
Advantages
 Relation with Real world entities
 Code reusability
 Abstraction or data hiding
Disadvantages
 Data protection
 Not suitable for all types of problems
 Slow Speed
Procedural programming paradigms
In Procedure Oriented programming paradigms, series of computational steps are divided modules
which means that the code is grouped in functions and the code is serially executed step by step so
basically, it combines the serial code to instruct a computer with each step to perform a certain task.
This paradigm helps in the modularity of code and modularization is usually done by the functional
implementation. This programming paradigm helps in an easy organization related items without
difficulty and so each file acts as a container.
Advantages
 General-purpose programming
 Code reusability
 Portable source code
Disadvantages
 Data protection
 Not suitable for real-world objects
 Harder to write
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
39
Functional programming paradigms
A functional programming paradigm is a paradigm in which everything is bind in pure
mathematical functions style. It is known as declarative paradigms because it uses declarations
overstatements. It uses the mathematical function and treats every statement as functional
expression as an expression is executed to produce a value. Lambda functions or Recursion are
basic approaches used for its implementation. The paradigms mainly focus on “what to solve”
rather than “how to solve”. The ability to treat functions as values and pass them as an argument
make the code more readable and understandable.
Advantages
 Simple to understand
 Making debugging and testing easier
 Enhances the comprehension and readability of the code
Disadvantages
 Low performance
 Writing programs is a daunting task
 Low readability of the code
1.4 PROGRAMMING LANGUAGE
 A programming language is a set of symbols and rules for instructing a computer to
perform specific tasks. The programmers have to follow all the specified rules before
writing program using programming language.
 The user has to communicate with the computer using language which it can understand.
Types of programming language
1. Machine language
2. Assembly language
3. High level language
Machine language:
The computer can understand only machine language which uses 0’s and 1’s. In machine
language the different instructions are formed by taking different combinations of 0’s and 1’s.
Advantages:
 Translation free:Machine language is the only language which the computer understands.
For executing any program written in any programming language, the conversion to
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
40
machine language is necessary. The program written in machine language can be executed
directly on computer. In this case any conversion process is not required.
 High speed: The machine language program is translation free. Since the conversion time
is saved, the execution of machine language program is extremely fast.
Disadvantages:
 It is hard to find errors in a program written in the machine language.
 Writing program in machine language is a time consuming process.
 Machine dependent: According to architecture used, the computer differs from each
other. So machine language differs from computer to computer. So a program developed
for a particular type of computer may not run on other type of computer.
Assembly language:
 To overcome the issues in programming language and make the programming process
easier, an assembly language is developed which is logically equivalent to machine
language but it is easier for people to read, write and understand.
 Assembly language is symbolic representation of machine language. Assembly languages
are symbolic programming language that uses symbolic notation to represent machine
language instructions. They are called low level language because they are so closely
related to the machines.
Ex: ADD a, b
Assembler:
Assembler is the program which translates assembly language instruction in to a machine
language.
Advantages
 Easy to understand and use.
 It is easy to locate and correct errors.
Disadvantages
 Machine dependent: The assembly language program which can be executed on the
machine depends on the architecture of that computer.
 Hard to learn: It is machine dependent, so the programmer should have the hardware
knowledge to create applications using assembly language.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
41
 Less efficient: Execution time of assembly language program is more than machine
language program.Because assembler is needed to convert from assembly language to
machine language.
High level language
High level language contains English words and symbols. The specified rules are to be
followed while writing program in high level language. The interpreter or compilers are used for
converting these programs in to machine readable form.
Translating high level language to machine language
The programs that translate high level language in to machine language are called
interpreter or compiler.
Compiler:
A compiler is a program which translates the source code written in a high level language
in to object code which is in machine language program. Compiler reads the whole program
written in high level language and translates it to machine language. If any error is found it
display error message on the screen.
Interpreter
Interpreter translates the high level language program in line by line manner. The
interpreter translates a high level language statement in a source program to a machine code and
executes it immediately before translating the next statement. When an error is found the
execution of the program is halted and error message is displayed on the screen.
Advantages
 Readability: High level language is closer to natural language so they are easier to learn
and understand
 Machine independent: High level language program have the advantage of being
portable between machines.
 Easy debugging: Easy to find and correct error in high level language
Disadvantage
 Less efficient: The translation process increases the execution time of the program.
Programs in high level language require more memory and take more execution time to
execute.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
42
They are divided into following categories:
1. Interpreted programming languages
2. Functional programming languages
3. Compiled programming languages
4. Procedural programming languages
5. Scripting programming language
6. Markup programming language
7. Concurrent programming language
8. Object oriented programming language
1. Interpreted programming languages:
 An interpreted language is a programming language for which most of its implementation
executes instructions directly, without previously compiling a program into machine
language instructions.
 The interpreter executes the program directly translating each statement into a sequence of
one or more subroutines already compiled into machine code.
Examples:Pascal, Python
2. Functional programming language:
 Functional programming language defines every computation as a mathematical
evaluation. They focus on the programming languages are bound to mathematical
calculations
Examples: Clean, Haskell
3. Compiled Programming language:
 A compiled programming is a programming language whose implementation are typically
compilers and not interpreters.
 It will produce a machine code from source code.
Examples: C, C++, C#, JAVA
4. Procedural programming language:
 Procedural (imperative) programming implies specifying the steps that the programs
should take to reach to an intended state.
 A procedure is a group of statements that can be referred through a procedure call.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
43
 Procedures help in the reuse of code. Procedural programming makes the programs
structured and easily traceable for program flow.
Examples: Hyper talk, MATLAB
5. Scripting language:
 Scripting language are programming languages that control an application.
 Scripts can execute independent of any other application. They are mostly embedded in
the application that they control and are used to automate frequently executed tasks like
communicating with external program.
Examples: Apple script, VB script
6. Markup languages:
 A markup language is an artificial language that uses annotations to text that define hoe
the text is to be displayed.
Examples:HTML, XML
7. Concurrent programming language:
 Concurrent programming is a computer programming technique that provides for the
execution of operation concurrently, either with in a single computer or across a number
of systems.
Examples:Joule, Limbo
8. Object oriented programming language:
 Object oriented programming is a programming paradigm based on the concept of objects
which may contain data in the form of procedures often known as methods.
Examples: Lava, Moto
Iterations:
A sequence of statements is executed until a specified condition is true is called iterations.
1. for loop
2. While loop
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
44
Flow chart
Recursions
 A function that calls itself is known as recursion.
 Recursion is a process by which a function calls itself repeatedly until some specified
condition has been satisfied.
Algorithm for factorial of n numbers using recursion:
Main function:
Step1: Start
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
45
Step2: Get n
Step3: call factorial (n)
Step4: print fact
Step5: Stop
Sub function factorial(n):
Step1: if(n==1) then fact=1 return fact
Step2: else fact=n*factorial(n-1) and return fact
Flowchart
Pseudo code for factorial using recursion:
Main function:
BEGIN
GET n
CALL factorial(n)
PRINT fact
BIN
Sub function factorial(n):
IF(n==1) THEN
fact=1
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
46
RETURN fact
ELSE
RETURN fact=n*factorial(n-1)
EXAMPLE 1: Write an algorithm to find area of a rectangle
ALGORITHM PSEUDOCODE FLOW CHART
Step 1: Start
Step 2: get l,b values
Step 3: Calculate
A=l*b
Step 4: Display A
Step 5: Stop
BEGIN
READ l,b
CALCULATE A=l*b
DISPLAY A
END
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
47
EXAMPLE 2: Write an algorithm for Calculating area and circumference of circle
ALGORITHM PSEUDOCODE FLOW CHART
Step 1: Start
Step 2: get r value
Step 3: Calculate
A=3.14*r*r
Step 4: Calculate
C=2.3.14*r
Step 5: Display A,C
Step 6: Stop
BEGIN
READ r
CALCULATE A and C
A=3.14*r*r
C=2*3.14*r
DISPLAY A
END
EXAMPLE 3: Write an algorithm for calculating simple interest
ALGORITHM PSEUDOCODE FLOW CHART
Step 1: Start
Step 2: get P, n, r value
Step3:Calculate
SI=(p*n*r)/100
Step 4: Display S
Step 5: Stop
BEGIN
READ P, n, r
CALCULATE S
SI=(p*n*r)/100
DISPLAY SI
END
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
48
EXAMPLE 4: Write an algorithm for calculating engineering cutoff
ALGORITHM PSEUDOCODE FLOW CHART
Step 1: Start
Step2: get P,C,M value
Step3:calculate
Cutoff= (P/4+C/4+M/2)
Step 4: Display Cutoff
Step 5: Stop
BEGIN
READ P,C,M
CALCULATE
Cutoff=
(P/4+C/4+M/2)
DISPLAY Cutoff
END
EXAMPLE 5: To check greatest of two numbers
ALGORITHM PSEUDOCODE FLOW CHART
Step 1: Start
Step 2: get a,b value
Step 3: check if(a>b) print a
is greater
Step 4: else b is greater
Step 5: Stop
BEGIN
READ a,b
IF (a>b) THEN
DISPLAY a is greater
ELSE
DISPLAY b is greater
END IF
END
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
49
EXAMPLE 6: To check leap year or not
ALGORITHM PSEUDOCODE FLOW CHART
Step 1: Start
Step 2: get y
Step 3: if(y%4==0) print
leap year
Step 4: else print not leap
year
Step 5: Stop
BEGIN
READ y
IF (y%4==0) THEN
DISPLAY leap year
ELSE
DISPLAY not leap year
END IF
END
EXAMPLE 7:To check positive or negative number
ALGORITHM PSEUDOCODE FLOW CHART
Step 1: Start
Step 2: get num
Step 3: check if(num>0)
print a is positive
Step 4: else num is
negative
Step 5: Stop
BEGIN
READ num
IF (num>0) THEN
DISPLAY num is
positive
ELSE
DISPLAY num is
negative
END IF
END
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
50
EXAMPLE 8: To check odd or even number
ALGORITHM PSEUDOCODE FLOW CHART
Step 1: Start
Step 2: get num
Step 3: check
if(num%2==0) print
num is even
Step 4: else num is odd
Step 5: Stop
BEGIN
READ num
IF (num%2==0) THEN
DISPLAY num is even
ELSE
DISPLAY num is odd
END IF
END
EXAMPLE 9: To check greatest of three numbers
ALGORITHM PSEUDOCODE
Step 1 : Start
Step 2 : Read the value of a, b, c
Step 3 : Compare the values of a, b and c.
Step 4 : If a is greater than b, compare a with c. If a
is greater than c then print a is big.
Step 5 : If a is not greater than b & c then compare
b and c.
Step 6 : If b is greater than c print b is big else
print c is big.
Step 7 : Stop
BEGIN
READ a, b, c
IF (a>b) THEN
IF(a>c) THEN
DISPLAY a is greater
ELSE
DISPLAY c is greater
END IF
ELSE
IF(b>c) THEN
DISPLAY b is greater
ELSE
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
51
DISPLAY c is greater
END IF
END IF
END
FLOW CHART
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
52
EXAMPLE 10: Write an algorithm to check whether given number is +ve, -ve or zero.
ALGORITHM PSEUDOCODE
Step 1: Start
Step 2: Get n value.
Step 3: if (n ==0) print “Given number is Zero”
Else goto step4
Step 4: if (n > 0) then Print “Given number is +ve”
Step 5: else Print “Given number is -ve”
Step 6: Stop
BEGIN
GET n
IF(n==0) THEN
DISPLAY “ n is zero”
ELSE
IF(n>0) THEN
DISPLAY “n is positive”
ELSE
DISPLAY “n is positive”
END IF
END IF
END
FLOW CHART
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
53
EXAMPLE 11: Write an algorithm to print all natural numbers up to n
ALGORITHM PSEUDOCODE
Step 1: Start
Step 2: get n value.
Step 3: initialize i=1
Step 4: if (i<=n) go to step 5 else go to step 8
Step 5: Print i value
step 6 : increment i value by 1
Step 7: go to step 4
Step 8: Stop
BEGIN
GET n
INITIALIZE i=1
WHILE(i<=n) DO
PRINT i
i=i+1
ENDWHILE
END
FLOW CHART
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
54
EXAMPLE 12: Write an algorithm to print n odd numbers
ALGORITHM PSEUDOCODE
Step 1: start
step 2: get n value
step 3: set initial value i=1
step 4: check if(i<=n) goto step 5 else goto step 8
step 5: print i value
step 6: increment i value by 2
step 7: goto step 4
step 8: stop
BEGIN
GET n
INITIALIZE i=1
WHILE(i<=n) DO
PRINT i
i=i+2
ENDWHILE
END
FLOW CHART
i=i+2
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
55
EXAMPLE 14: Write an algorithm to find sum of a given number
ALGORITHM PSEUDOCODE
Step 1: start
step 2: get n value
step 3: set initial value i=1, sum=0
Step 4: check i value if(i<=n) goto step 5 else goto
step8
step 5: calculate sum=sum+i
step 6: increment i value by 1
step 7: goto step 4
step 8: print sum value
step 9: stop
BEGIN
GET n
INITIALIZE i=1,sum=0
WHILE(i<=n) DO
sum=sum+i
i=i+1
ENDWHILE
PRINT sum
END
FLOW CHART
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
56
EXAMPLE 15: Write an algorithm to find factorial of a given number
ALGORITHM PSEUDOCODE
Step 1: start
step 2: get n value
step 3: set initial value i=1, fact=1
Step 4: check i value if(i<=n) goto step 5 else goto
step8
step 5: calculate fact=fact*i
step 6: increment i value by 1
step 7: goto step 4
step 8: print fact value
step 9: stop
BEGIN
GET n
INITIALIZE i=1,fact=1
WHILE(i<=n) DO
fact=fact*i
i=i+1
ENDWHILE
PRINT fact
END
FLOW CHART
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
57
EXAMPLE 16: To print the reverse of a number.
ALGORITHM PSEUDOCODE
Step 1 : Start
Step 2 : Initialize r=0, sum=0
Step 3 : READ the value of n
Step 4 : If n>0 do the following else goto step 6
Step 4.1 r=n mod 10
Step 4.2 sum=sum*10+r
Step 4.3 n=n div 10
Step 5 : Goto step 4
Step 6 : Print sum
Step 7 : Stop
Set initial sum=0, r=0
READ the value of n
WHILE (n>0)
r=n%10
sum=sum*10+r
n=n//10
ENDWHILE
Repeat while until the
condition fail
WRITE the sum
Stop
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
58
EXAMPLE 17: Find Fibonacci Series for the first ‘n’ terms
ALGORITHM PSEUDOCODE
Step 1 : Start
Step 2 : Assign F1=0, F2=1, F=0
Step 3 : Read the value of n
Step 4 : print the values of F1, F2
Step 5 : Calculate
F = F1+F2
Step 6 : If (F<n) do the following
else goto step 8
Step 6.1 : F = F1+F2
Step 6.2 : F1 = F2
Step 6.3 : F2 = F1
Step 6.4 : Print F
Step 7 : Goto step 6
Step 8 : Stop
Set initial zero to F, F1 and 1 to F2
READ the value of n
WRITE F1, F2
Calculate
F=F1+F2
WHILE (F<n)
F=F1+F2
F1=F2
F2=F
i=i+1
WRITE F
ENDWHILE
Repeat while until the condition fail
Stop
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
59
EXAMPLE 18:Write an algorithm for swapping two no’s using a third variable
ALGORITHM FLOW CHART
Step 1 : Start
Start 2 : READ num1, num2
Start 3 : temp = num1
Start 4 : num1 = num2
Start 5 : num2 = temp
Start 6 : PRINT num1, num2
Start 7 : Stop
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
60
EXAMPLE 19: Write an algorithm for swapping two no’swithout using a third variable
ALGORITHM FLOWCHART
Step 1 : Start
Step 2 : READ num1, num2
Step 3 : num1 = num1 + num2
Step 4 : num2 = num1 - num2
Step 5 : num1 = num1 - num2
Step 6 : PRINT num1, num2
Step 7 : Stop
1.5 Features of A Good Programming Language
There are various factors, why the programmers prefer one language over the another. And
some of very good characteristics of a good programming language are,
1) Clarity, Simplicity And Unity: A Programming language provides both a conceptual
framework for Algorithm planning and means of expressing them. It should provide a clear,
simple and unified set of concepts that can be used as primitives in developing algorithms.
It should have
• It has minimum number of different concepts
•- with Rules for their combination being
•-simple and regular.
This attribute is called conceptual integrity.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
61
2) Orthogonality: It is one of the most important feature of PL orthogonality is the property that
means " Changing A does not change B".
If I take Real world example of an orthogonal system Would be a radio, where changing the
station does not change the volume and vice versa.
When the features of a language are orthogonal, language is easier to learn and programs are
easier to write because only few exceptions and special cases to be remembered.
3) Support for Abstraction:- There is always found that a substantial gap remaining between
the abstract data structure and operations that characterize the solution to a problem and their
particular data structure and operations built into a language.
4) Programming Environment: An appropriate programming environment adds an extra
utility and make language to be implemented easily like
The availability of- Reliable- Efficient - Well documentation
Speeding up creation and testing by-special Editors- testing packages
Facility- Maintaining and Modifying- Multi Version of program software product.
5) Ease of program verification:- Reusability:
The reusability of program written in a language is always a central concern. A program is
checked by various testing technique like
Formal verification method Desk checking Input output test checking.
B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1
62
We verify the program by many more techniques. A language that makes program verification
difficult maybe far more troublesome to use. Simplicity of semantic and syntactic structure is a
primary aspect that tends to simplify program verification.
6) Portability of programs: Programming language should be portable means it should be
easy to transfer a program from which they are developed to the other computer.
A program whose definition is independent of features of a Particular machine forms can
only support Portability. Example: Ada, FORTRAN, C, c++, Java.

More Related Content

Similar to Problem Solving and Python Fundamentals

Fundamentals of computers (2).pptx
Fundamentals of computers (2).pptxFundamentals of computers (2).pptx
Fundamentals of computers (2).pptxanshparashar5
 
Introduction to computer
Introduction to computerIntroduction to computer
Introduction to computersuraj pandey
 
Discovering Computer Chapter 1
Discovering Computer Chapter 1Discovering Computer Chapter 1
Discovering Computer Chapter 1MuhammedTalha7
 
CHAPTER-ONE to computer science.pptx.fil
CHAPTER-ONE to computer science.pptx.filCHAPTER-ONE to computer science.pptx.fil
CHAPTER-ONE to computer science.pptx.filHaftomYitbarek
 
Introduction to computers pdf
Introduction to computers pdfIntroduction to computers pdf
Introduction to computers pdfblufishocean
 
IT and Computing
   IT and Computing   IT and Computing
IT and ComputingMiXvideos
 
Introduction to Computer Engineering
Introduction to Computer EngineeringIntroduction to Computer Engineering
Introduction to Computer EngineeringBESOR ACADEMY
 
Itc lec 1 introduction to computer applications
Itc lec 1 introduction to computer applicationsItc lec 1 introduction to computer applications
Itc lec 1 introduction to computer applicationsAnzaDar3
 
Introduction to information technology
Introduction to information technologyIntroduction to information technology
Introduction to information technologyEskenderAlAsbahi
 
Application of computer
Application of computerApplication of computer
Application of computerA. S. M. Shafi
 
Introduction to Computer Fundamentals
Introduction to Computer FundamentalsIntroduction to Computer Fundamentals
Introduction to Computer Fundamentalsshivanichauhan1953
 
Applications of computers
Applications of computersApplications of computers
Applications of computerslalith saie
 

Similar to Problem Solving and Python Fundamentals (20)

Fundamentals of computers (2).pptx
Fundamentals of computers (2).pptxFundamentals of computers (2).pptx
Fundamentals of computers (2).pptx
 
Fundamentals of ict n krishantha
Fundamentals of ict n krishanthaFundamentals of ict n krishantha
Fundamentals of ict n krishantha
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Computer applications
Computer applicationsComputer applications
Computer applications
 
introduction to computer
introduction to computerintroduction to computer
introduction to computer
 
Introduction to computer
Introduction to computerIntroduction to computer
Introduction to computer
 
Discovering Computer Chapter 1
Discovering Computer Chapter 1Discovering Computer Chapter 1
Discovering Computer Chapter 1
 
CHAPTER-ONE to computer science.pptx.fil
CHAPTER-ONE to computer science.pptx.filCHAPTER-ONE to computer science.pptx.fil
CHAPTER-ONE to computer science.pptx.fil
 
19_unit 1 PPT-1.ppt
19_unit 1 PPT-1.ppt19_unit 1 PPT-1.ppt
19_unit 1 PPT-1.ppt
 
Introduction to computers pdf
Introduction to computers pdfIntroduction to computers pdf
Introduction to computers pdf
 
chapter 1.pptx
chapter 1.pptxchapter 1.pptx
chapter 1.pptx
 
IT and Computing
   IT and Computing   IT and Computing
IT and Computing
 
Introduction to Computer Engineering
Introduction to Computer EngineeringIntroduction to Computer Engineering
Introduction to Computer Engineering
 
Itc lec 1 introduction to computer applications
Itc lec 1 introduction to computer applicationsItc lec 1 introduction to computer applications
Itc lec 1 introduction to computer applications
 
Introduction to information technology
Introduction to information technologyIntroduction to information technology
Introduction to information technology
 
Application of computer
Application of computerApplication of computer
Application of computer
 
Chapter01 2015
Chapter01 2015Chapter01 2015
Chapter01 2015
 
Introduction to Computer Fundamentals
Introduction to Computer FundamentalsIntroduction to Computer Fundamentals
Introduction to Computer Fundamentals
 
The computer system
The computer systemThe computer system
The computer system
 
Applications of computers
Applications of computersApplications of computers
Applications of computers
 

Recently uploaded

IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...Call Girls in Nagpur High Profile
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 

Recently uploaded (20)

IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 

Problem Solving and Python Fundamentals

  • 1. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 1 B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I INTRODUCTION Introduction: Fundamentals of digital computers. Problem Solving Techniques: Algorithm, Flow Chart, Pseudo code, Program Control Structures, Programming Paradigms: Programming languages: Generations of Programming Languages, Language Translators, and Features of a Good Programming Languages. 1.1 INTRODUCTION: FUNDAMENTALS OF DIGITAL COMPUTERS. Today’s world is an information-rich world and it has become a necessity for everyone to know about computers. A computer is an electronic data processing device, which accepts and stores data input, processes the data input, and generates the output in a required format. The purpose of this tutorial is to introduce you to Computers and its fundamentals. FUNCTIONALITIES OF A COMPUTER Any digital computer carries out the following five functions: Step 1 - Takes data as input. Step 2 - Stores the data/instructions in its memory and uses them as required. Step 3 - Processes the data and converts it into useful information. Step 4 - Generates the output. Step 5 - Controls all the above four steps.
  • 2. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 2 ADVANTAGES OF COMPUTERS Following are certain advantages of computers. High Speed Computer is a very fast device.  It is capable of performing calculation of very large amount of data.  The computer has units of speed in microsecond, nanosecond, and even the picoseconds.  It can perform millions of calculations in a few seconds as compared to man who will spend many months to perform the same task. Accuracy  In addition to being very fast, computers are very accurate.  The calculations are 100% error free.  Computers perform all jobs with 100% accuracy provided that the input is correct. Storage Capability Memory is a very important characteristic of computers.  A computer has much more storage capacity than human beings.  It can store large amount of data.  It can store any type of data such as images, videos, text, audio, etc. Diligence  Unlike human beings, a computer is free from monotony, tiredness, and lack of concentration.  It can work continuously without any error and boredom.  It can perform repeated tasks with the same speed and accuracy. Versatility  A computer is a very versatile machine.  A computer is very flexible in performing the jobs to be done.  This machine can be used to solve the problems related to various fields.  At one instance, it may be solving a complex scientific problem and the very next moment it may be playing a card game.
  • 3. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 3 Reliability  A computer is a reliable machine.  Modern electronic components have long lives.  Computers are designed to make maintenance easy. Automation  Computer is an automatic machine.  Automation is the ability to perform a given task automatically. Once the computer receives a program i.e., the program is stored in the computer memory, then the program and instruction can control the program execution without human interaction. Reduction in Paper Work and Cost  The use of computers for data processing in an organization leads to reduction in paper work and results in speeding up the process.  As data in electronic files can be retrieved as and when required, the problem of maintenance of large number of paper files gets reduced.  Though the initial investment for installing a computer is high, it substantially reduces the cost of each of its transaction. DISADVANTAGES OF COMPUTERS Following are certain disadvantages of computers. No I.Q.  A computer is a machine that has no intelligence to perform any task.  Each instruction has to be given to the computer.  A computer cannot take any decision on its own. Dependency  It functions as per the user’s instruction, thus it is fully dependent on humans. Environment  The operating environment of the computer should be dust free and suitable.
  • 4. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 4 No Feeling  Computers have no feelings or emotions.  It cannot make judgment based on feeling, taste, experience, and knowledge unlike humans. THE APPLICATIONS OF COMPUTER Business A computer has high speed of calculation, diligence, accuracy, reliability, or versatility which has made it an integrated part in all business organizations. Computer is used in business organizations for:  Payroll calculations  Budgeting  Sales analysis  Financial forecasting  Managing employee database  Maintenance of stocks, etc. Banking Today, banking is almost totally dependent on computers. Banks provide the following facilities:  Online accounting facility, which includes checking current balance, making deposits and overdrafts, checking interest charges,
  • 5. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 5 shares, and trustee records.  ATM machines which are completely automated are making it even easier for customers to deal with banks. Insurance Insurance companies are keeping all records up- to-date with the help of computers. Insurance companies, finance houses, and stock broking firms are widely using computers for their concerns. Insurance companies are maintaining a database of all clients with information showing:  Procedure to continue with policies  Starting date of the policies  Next due installment of a policy  Maturity date  Interests due  Survival benefits  Bonus Education The computer helps in providing a lot of facilities in the education system.  The computer provides a tool in the education system known as CBE (Computer Based Education). CBE involves control, delivery, and evaluation of learning.  Computer education is rapidly increasing the graph of number of computer students.
  • 6. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 6  There are a number of methods in which educational institutions can use a computer to educate the students.  It is used to prepare a database about performance of a student and analysis is carried out on this basis. Marketing In marketing, uses of the computer are following: Advertising - With computers, advertising professionals create art and graphics, write and revise copy, and print anddisseminate ads with the goal of selling more products. Home Shopping - Home shopping has been made possible through the use of computerized catalogues that provide access to product information and permit direct entry of orders to be filled by the customers. Healthcare Computers have become an important part in hospitals, labs, and dispensaries. They are being used in hospitals to keep the record of patients and medicines. It is alsoused in scanning and diagnosing different diseases. ECG, EEG, ultrasounds and CT scans, etc. are also done by computerized machines. Following are some major fields of health care in which computers are used.  Diagnostic System - Computers are used to collect data and identify the cause of illness.  Lab-diagnostic System - All tests can be done and the reports are prepared by computer.  Patient Monitoring System - These are used to check the patient's signs for abnormality such as in Cardiac Arrest, ECG, etc.
  • 7. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 7 Pharma Information System Computer is used to check drug labels, expiry dates, harmful side effects, etc. Surgery - Nowadays, computers are also used in performing surgery. Engineering Design Computers are widely used for Engineering purpose. One of the major areas is CAD (Computer Aided Design) that provides creation and modification of images. Some of the fields are: Structural Engineering - Requires stress and strain analysis for design of ships, buildings, budgets, airplanes, etc. Industrial Engineering - Computers deal with design, implementation, and improvement of integrated systems of people, materials, and equipment. Architectural Engineering - Computers help in planning towns, designing buildings, determining a range of buildings on a site using both 2D and 3D drawings. Military Computers are largely used in defence. Modern tanks, missiles, weapons, etc. Military also employs computerized control systems. Some military areas where a computer has been used are:  Missile Control  Military Communication  Military Operation and Planning  Smart Weapons
  • 8. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 8 Communication Communication is a way to convey a message, an idea, a picture, or speech that is received and understood clearly and correctly by the person for whom it is meant. Some main areas in this category are:  E-mail  Chatting  Usenet  FTP  Telnet  Video-conferencing Government Computers play an important role in government services. Some major fields in this category are:  Budgets  Sales tax department  Income tax department  Computation of male/female ratio  Computerization of voters lists  Computerization of PAN card  Weather forecasting CLASSIFICATION OR TYPES OF COMPUTERS Computers can be broadly classified by their speed and computing power.
  • 9. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 9 Sl.No. Type Specifications 1 Micro Computer It is a single user computer system, is minimal in size and storage capacity. 2 Mini Computer It is a multi-user computer system, capable of supporting hundreds of users simultaneously. 3 Main Frame It is a multi-user computer system, capable of supporting hundreds of users simultaneously. Software technology is different from minicomputer. 4 Super Computer It is an extremely fast computer, which can execute hundreds of millions of instructions per second. Micro computer Micro computer, an electronic device with a microprocessor as its central processing unit (CPU). High-performance microcomputer systems began to be used widely in business, in engineering, in “smart” or intelligent machines employed in the factory and office, and in military electronics systems. A microcomputer is now primarily called a personal computer (PC), or a device based on a single-chip microprocessor. Common microcomputers include laptops and desktops. Beyond standard PCs, microcomputers also include some calculators, mobile phones, notebooks, workstations and embedded systems.
  • 10. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 10 Applications of Micro computers: PC is being widely used in many fields like home, office, data collection, business, education, entertainment, publishing, etc. Mini computer It is a midsize multi-processing system capable of supporting up to 250 users simultaneously. A minicomputer is a type of computer that possesses most of the features and capabilities of a large computer but is smaller in physical size. A minicomputer fills the space between the mainframe and microcomputer, and is smaller than the former but larger than the latter. Minicomputers are mainly used as small or mid-range servers operating business and scientific applications.
  • 11. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 11 Applications of Mini computers: The minicomputers are used as real-time applications in Industries, bookings, and Research Centres. Banks also use minicomputers for preparing payroll for employees’ salaries, records, tracking of financial accounts, etc. As well as in the field of Higher Education and Engineering. Mainframe Mainframe is very large in size and is an expensive computer capable of supporting hundreds or even thousands of users simultaneously. Mainframe executes many programs concurrently and supports many simultaneous execution of programs.
  • 12. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 12 Applications of Mainframe Computers: Mainframe computers are mainly used by departmental and commercial organizations like Banks, Companies, Scientific research centers, and governmental departments like railways. These computers can work for 24 hours. Hundreds of users can work on these computations simultaneously. Using the mainframe completes the tasks, Such as keeping details of payments, research centres, advertising, sending bills and notices, paying employees, ticket booking, maintaining details of purchases by users, keeping detailed tax details, etc. Supercomputer Supercomputers are one of the fastest computers currently available. Supercomputers are very expensive and are employed for specialized applications that require immense amount of mathematical calculations (number crunching).
  • 13. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 13 Applications of Super computers:  In research and study of energy and nuclear weapons and designing the aircraft, airplanes, and flight simulators.  Climate research and Weather Forecasting and Prediction of Natural Disasters.  Spaceship and Satellite Launching.  Used in scientific research laboratories.  Used in Chemical and Biological research and for highly calculation complex tasks. COMPUTER COMPONENTS All types of computers follow the same basic logical structure and perform the following five basic operations for converting raw input data into information useful to their users. Sr. No. Operation Description 1 Take Input The process of entering data and instructions into the computer system. 2 Store Data Saving data and instructions so that they are available for processing as and when required.
  • 14. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 14 3 Processing Data Performing arithmetic, and logical operations on data in order to convert them into useful information. 4 Output Information The process of producing useful information or results for the user, such as a printed report or visual display. 5 Control the workflow Directs the manner and sequence in which all of the above operations are performed. Input Unit This unit contains devices with the help of which we enter data into the computer. This unit creates a link between the user and the computer. The input devices translate the information into a form understandable by the computer. CPU (Central Processing Unit) CPU is considered as the brain of the computer. CPU performs all types of data processing operations. It stores data, intermediate results, and instructions (program). It controls the operation of all parts of the computer. CPU itself has the following three components:  ALU (Arithmetic Logic Unit)
  • 15. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 15  Memory Unit  Control Unit Output Unit The output unit consists of devices with the help of which we get the information from the computer. This unit is a link between the computer and the users. Output devices translate the computer's output into a form understandable by the users. COMPUTER MEMORY A memory is just like a human brain. It is used to store data and instructions. Computer memory is the storage space in computer where data is to be processed and instructions required for processing are stored. The memory is divided into large number of small parts called cells. Each location or cell has a unique address which varies from zero to memory size minus one. For example if computer has 64k words, then this memory unit has 64 * 1024=65536 memory locations. The address of these locations varies from 0 to 65535. Memory is primarily of three types  Cache Memory  Primary Memory/Main Memory  Secondary Memory Cache Memory Cache memory is a very high speed semiconductor memory which can speed up CPU. It acts as a buffer between the CPU and main memory. It is used to hold those parts of data and program which are most frequently used by CPU. The parts of data and programs are transferred from disk to cache memory by operating system, from where CPU can access them. Advantages The advantages of cache memory are as follows:  Cache memory is faster than main memory.  It consumes less access time as compared to main memory.  It stores the program that can be executed within a short period of time.
  • 16. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 16  It stores data for temporary use. Disadvantages The disadvantages of cache memory are as follows:  Cache memory has limited capacity.  It is very expensive. Primary Memory /MainMemory Primary memory holds only those data and instructions on which computer is currently working. It has limited capacity and data is lost when power is switched off. It is generally made up of semiconductor device. These memories are not as fast as registers. The data and instruction required to be processed reside in main memory. It is divided into two subcategories RAM and ROM. Characteristics of Main Memory  These are semiconductor memories It is known as main memory.  Usually volatile memory.  Data is lost in case power is switched off.  It is working memory of the computer.  Faster than secondary memories.  A computer cannot run without primary memory. Secondary Memory This type of memory is also known as external memory or non-volatile. It is slower than main memory. These are used for storing data/Information permanently. CPU directly does not access these memories instead they are accessed via input-output routines. Contents of secondary memories are first transferred to main memory, and then CPU can access it. For example : disk, CD-ROM, DVD etc. Characteristic of Secondary Memory  These are magnetic and optical memories It is known as backup memory.  It is non-volatile memory.
  • 17. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 17  Data is permanently stored even if power is switched off.  It is used for storage of data in a computer.  Computer may run without secondary memory.  Slower than primary memories Generations of Computers Generation in computer terminology is a change in technology a computer is/was being used. Initially, the generation term was used to distinguish between varying hardware technologies. Nowadays, generation includes both hardware and software, which together make up an entire computer system. There are five computer generations known till date. Each generation has been discussed in detail along with their time period and characteristics. In the following table, approximate dates against each generation has been mentioned, which are normally accepted. Following are the main five generations of computers. First Generation Computers The period of first generation was from 1946-1959. The computers of first generation used vacuum tubes as the basic components for memory and circuitry for CPU (Central Processing Unit). These tubes, like electric bulbs, produced a lot of heat and the installations used to fuse frequently. Therefore, they were very expensive and only large organizations were able to afford it.
  • 18. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 18 In this generation, mainly batch processing operating system was used. Punch cards, paper tape, and magnetic tape was used as input and output devices. The computers in this generation used machine code as the programming language. The main features of the first generation are:  Vacuum tube technology  Unreliable  Supported machine language only  Very costly  Generated a lot of heat  Slow input and output devices  Huge size  Need of AC  Non-portable  Consumed a lot of electricity
  • 19. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 19 Some computers of this generation were:  ENIAC  EDVAC  UNIVAC  IBM-701  IBM-650 Second Generation Computers The period of second generation was from 1959-1965. In this generation, transistors were used that were cheaper, consumed less power, more compact in size, more reliable and faster than the first generation machines made of vacuum tubes. In this generation, magnetic cores were used as the primary memory and magnetic tape and magnetic disks as secondary storage devices. In this generation, assembly language and high-level programming languages like FORTRAN, COBOL were used. The computers used batch processing and multiprogramming operating system. The main features of second generation are:  Use of transistors  Reliable in comparison to first generation computers
  • 20. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 20  Smaller size as compared to first generation computers  Generated less heat as compared to first generation computers  Consumed less electricity as compared to first generation computers  Faster than first generation computers  Still very costly  AC required  Supported machine and assembly languages Some computers of this generation were:  IBM 1620  IBM 7094  CDC 1604  CDC 3600  UNIVAC 1108 Third Generation Computers The period of third generation was from 1965-1971. The computers of third generation used Integrated Circuits (ICs) in place of transistors. A single IC has many transistors, resistors, and capacitors along with the associated circuitry. The IC was invented by Jack Kilby. This development made computers smaller in size, reliable, and efficient. In this generation remote processing, time-sharing, multi-programming operating system were used. High-level languages (FORTRAN-II TO IV, COBOL, PASCAL PL/1, BASIC, ALGOL-68 etc.) were used during this generation.
  • 21. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 21 The main features of third generation are:  IC used  More reliable in comparison to previous two generations  Smaller size  Generated less heat  Faster  Lesser maintenance  Costly  AC required  Consumed lesser electricity  Supported high-level language Some computers of this generation were:  IBM-360 series  Honeywell-6000 series  PDP (Personal Data Processor)  IBM-370/168  TDC-316
  • 22. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 22 Fourth Generation Computers The period of fourth generation was from 1971-1980. Computers of fourth generation used Very Large Scale Integrated (VLSI) circuits. VLSI circuits having about 5000 transistors and other circuit elements with their associated circuits on a single chip made it possible to have microcomputers of fourth generation. Fourth generation computers became more powerful, compact, reliable, and affordable. As a result, it gave rise to Personal Computer (PC) revolution. In this generation, time sharing, real time networks, distributed operating system were used. All the high-level languageslike C, C++, DBASE etc., were used in this generation. The main features of fourth generation are:  VLSI technology used  Very cheap  Portable and reliable  Use of PCs  Very small size  Pipeline processing  No AC required  Concept of internet was introduced
  • 23. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 23  Great developments in the fields of networks  Computers became easily available Some computers of this generation were:  DEC 10  STAR 1000  PDP 11  CRAY-1(Super Computer)  CRAY-X-MP(Super Computer) Fifth generation computers The period of fifth generation is 1980-till date. In the fifth generation, VLSI technology became ULSI (Ultra Large Scale Integration) technology, resulting in the production of microprocessor chips having ten million electronic components. This generation is based on parallel processing hardware and AI (Artificial Intelligence) software. AI is an emerging branch in computer science, which interprets the means and method of making computers think like human beings. All the high-level languages like C and C++, Java, .Net etc., are used in this generation. AI includes:  Robotics  Neural Networks  Game Playing  Development of expert systems to make decisions in real-life situations  Natural language understanding and generation
  • 24. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 24 The main features of fifth generation are:  ULSI technology  Development of true artificial intelligence  Development of Natural language processing  Advancement in Parallel Processing  Advancement in Superconductor technology  More user-friendly interfaces with multimedia features  Availability of very powerful and compact computers at cheaper rates
  • 25. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 25 Some computer types of this generation are:  Desktop  Laptop  NoteBook  UltraBook  ChromeBook PROBLEM Sometimes referred to as an issue, a problem is any situation that occurs that is unexpected or prevents something from occurring. When dealing with computer problems, you must first understand the source of the problem and then find a solution to fix the problem. PROBLEM SOLVING Problem solving is the systematic approach to define the problem and creating number of solutions. The problem solving process starts with the problem specifications and ends with a Correct program. STEPS INVOLVED IN PROBLEM SOLVING A computer cannot solve a problem on its own. One has to provide step by step solutions of the problem to the computer. In fact, the task of problem solving is not that of the computer. It is the programmer who has to write down the solution to the problem in terms of simple operations which the computer can understand and execute. In order to solve a problem by the computer, one has to pass though certain stages or steps. They are 1. Understanding the problem 2. Analyzing the problem 3. Developing the solution 4. Coding and implementation. 1. Understanding the problem: Here we try to understand the problem to be solved in totally. Before with the next stage or step, we should be absolutely sure about the objectives of the given problem. 2. Analyzing the problem: After understanding thoroughly the problem to be solved, we look different ways of solving the problem and evaluate each of these methods. The idea here is to
  • 26. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 26 search an appropriate solution to the problem under consideration. The end result of this stage is a broad overview of the sequence of operations that are to be carried out to solve the given problem. 3. Developing the solution: Here the overview of the sequence of operations that was the result of analysis stage is expanded to form a detailed step by step solution to the problem under consideration. 4. Coding and implementation: The last stage of the problem solving is the conversion of the detailed sequence of operations in to a language that the computer can understand. Here each step is converted to its equivalent instruction or instructions in the computer language that has been chosen for the implantation. 1.2 PROBLEM SOLVING TECHNIQUES  Problem solving technique is a set of techniques that helps in providing logic for solving a problem. Problem solving can be expressed in the form of 1. Algorithms. 2. Flowcharts. 3. Pseudo codes. 4. Programs 1.2.1. ALGORITHM  An algorithm is defined as a step by step procedure for solving any problem.  It is also asequence of finite instructions used to refer the logic of a program.  It should be precise rules and clearly specify how to solve a problem. Characteristic of Algorithm  The algorithm should be written in sequence using simple English.  Algorithm has a finite number of inputs.  Every instruction should be precise and unambiguous.  Ensure that the algorithm has proper termination.  The desired output must be obtained only after the algorithm terminates. Qualities of an Algorithm The following are the primary factors that are often used to judge the quality of the algorithms.
  • 27. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 27  Time: To execute a program, the computer system takes some amount of time. The lesser is the time required, the better is the algorithm.  Memory: To execute a program, computer system takes some amount of memory space. The lesser is the memory required, the better is the algorithm.  Accuracy: Multiple algorithms may provide suitable or correct solutions to a given problem, some of these may provide more accurate results than others, and such algorithms may be suitable.  Sequence: The procedure of an algorithm must be in a sequential form. Example 1: Write an algorithm to print “Good Morning”. Step 1: Start Step 2: Print “Good Morning” Step 3: Stop Example 2: Write an algorithm to print sum of two numbers. Step 1: Start Step 2: Input a,b Step 3: Calculate c=a+b Step 4: Display c Step 5: Stop BUILDING BLOCKS OF ALGORITHM (Statements, State, Control flow & Functions): Algorithms can be constructed from basic building blocks namely, sequence, selection and iteration. Statements  Statement is a single action in a computer.  It is an instruction written in a high-level language that commands the computer to perform a specified action.  A program written in such a language is formed by a sequence of one or more statements. A statement may have internal components (e.g., expressions). There are two major generic kinds of statements,
  • 28. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 28 1. Simple statements  assignment: A:= A + 5  goto: goto next;  return: return 5;  call: function() 2. Compound statements  block: begin ------- end  for-loop: for (…) ________  if-statement: if ----else----  switch-statement: switch (c) { case ‘a’: alert(); break; case ‘q’: quit(); break; }  while-loop: while (…) DO ----- State:  Transition from one process to another process under specified condition with in atime is called state. Example: Initial state and End state Control flow:  The process of executing the individual statements in a given order is called control flow. It is also called as flow of control. The control can be executed in three ways  sequence  selection  iteration Sequence:  All the instructions are executed one after another is called sequence execution. Example: Algorithm for Baking Bread Step1: Add flour. Step 2: Add salt. Step 3: Add yeast.
  • 29. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 29 Step 4: Mix. Step 5: Add water. Step 6: Knead. Step 7: Let rise. Step 8: Bake. Selection  Selection control structures (or) Decision structures allows the program to make a choice between two alternate paths whether it is true or false.  IF...THEN or IF..THEN..ELSE or a case structures are the selection structures. This logic is used for making decisions. 1) IF..THEN Structures This makes a choice between two processes. If the condition is true it performs the process. If the condition in false it skips over the process. Pseudocode IF condition THEN process 1 … … ENDIF b) IF..THEN...ELSE structure In this structure if the condition is true it executes process 1 else if the condition is false it executes process 2. In this either the process 1 or process 2 gets executed depending on the condition. Pseudocode Flowchart IF condition then process 1 … ELSE process 2
  • 30. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 30 … ENDIF Example: Write an algorithm to check whether he is eligible to vote? Step 1: Start Step 2: Get age Step 3: if age >= 18 print “Eligible to vote” Step 4: else print “Not eligible to vote” Step 6: Stop 1.2.3.3 Iteration:  In some programs, certain set of statements are executed again and again based upon conditional test. i.e. executed more than one time.  This type of execution is called looping or iteration. Example: Find the factorial of a given number. Algorithm Step 1 : Start Step 2 : Initialize the value of fact and i to 1 Step 3 : READ the value of n. Step 4 : If i<= n do the following else Goto step6. Step 4.1 : fact = fact*i Step 4.2 :i=i+1 Step 5 :Goto step4 Step 6 : Print fact Step 7 : Stop Functions:  Function is a sub program which consists of block of code (set of instructions) that performs a particular task.  For complex problems, the problem is been divided into smaller and simpler tasks during algorithm design.
  • 31. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 31  Once a function is written, it can be used over and over and over again. Functions can be “called” from the inside of other functions. Steps to Writing a Function  Understand the purpose of the function.  Define the data that comes into the function from the caller (in the form of parameters)!  Define what data variables are needed inside the function to accomplish its goal.  Decide on the set of steps that the program will use to accomplish this goal. Benefits of Using Functions  Reduction in line of code  code reuse  Better readability  Information hiding  Easy to debug and test  Improved maintainability Example: Algorithm for addition of two numbers using function Main function() Step 1: Start Step 2: Call the function add() Step 3: Stop sub function add() Step 1: Function start Step 2: Get a, b Values Step 3: add c=a+b Step 4: Print c Step 5: Return NOTATIONS FLOW CHART  A flow chart is a diagrammatic representation that illustrates the sequence of operations to be performed to arrive at the solution.
  • 32. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 32  Each step in the process is represented by a different symbol and contains a short description of the process step. The flow chart symbols are linked together with arrows showing the flow direction of the process.  The purpose of flowchart is making the logic of the program clear in a visual representation. Rules for drawing a flowchart 1. The flowchart should be clear, neat and easy to follow. 2. The flowchart must have a logical start and finish. 3. Only one flow line should come out from a process symbol. 4. Only one flow line should enter a decision symbol. However, two or three flow lines may leave the decision symbol.
  • 33. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 33 5. Only one flow line is used with a terminal symbol. 6. Within standard symbols, write briefly and precisely. 7. Intersection of flow lines should be avoided. Advantages of flowchart:  Communication: - Flowcharts are better way of communicating the logic of a system to all concerned.  Effective analysis: - With the help of flowchart, problem can be analyzed in more effective way.  Proper documentation: - Program flowcharts serve as a good program documentation, which is needed for various purposes.  Efficient Coding: - The flowcharts act as a guide or blueprint during the systems analysis and program development phase.  Proper Debugging: - The flowchart helps in debugging process.  Efficient Program Maintenance: - The maintenance of operating program becomes easy with the help of flowchart. It helps the programmer to put efforts more efficiently on that part. Disadvantages of flow chart:  Complex logic: - Sometimes, the program logic is quite complicated. In that case, flowchart becomes complex and clumsy.  Alterations and Modifications: - If alterations are required the flowchart may require re- drawing completely.
  • 34. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 34  Reproduction: - As the flowchart symbols cannot be typed, reproduction of flowchart becomes a problem.  Cost: For large application the time and cost of flowchart drawing becomes costly. PSEUDO CODE Pseudocode is a kind of structure english for designing algorithm. Pseudocodes came from two words. Pseudo and code pseudo means imitation and code refer to instructions, written in a programming language.  Pseudocode cannot be compiled nor executed, and there are no real formatting or syntax rules.  The benefit of pseudo code is that it enables the programmer to concentrate on the algorithms without worrying about all the syntactic details of a particular programming language.  In fact, you can write pseudo code without even knowing what programming language you will use for the final implementation.  It gives us the sketch of the program before actual coding.  It is not a machine readable  Pseudo code can’t be compiled and executed.  There is no standard syntax for pseudo code. Guidelines for writing pseudo code:  Write one statement per line  Capitalize initial keyword  Indent to show hierarchy, improve readability, and show nested constructs.  End multiline structure  Keep statements language independent Common keywords used in pseudocode The following gives common keywords used in pseudocodes. 1. // : This keyword used to represent a comment. 2. BEGIN,END : Begin is the first statement and end is the last statement. 3. INPUT, GET, READ : The keyword is used to inputting data.
  • 35. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 35 4. COMPUTE, CALCULATE : used for calculation of the result of the given expression. 5. ADD, SUBTRACT, INITIALIZE:used for addition, subtraction and initialization. 6. OUTPUT, PRINT, DISPLAY : It is used to display the output of the program. 7. IF, ELSE, ENDIF : used to make decision. 8. WHILE, ENDWHILE : used for iterative statements. 9. FOR, ENDFOR :Another iterative increment/decrement tested automatically. Example Advantages:  Pseudo is independent of any language; it can be used by most programmers.  It is easy to translate pseudo code into a programming language.  It can be easily modified as compared to flowchart.  Converting a pseudo code to programming language is very easy as compared with converting a flowchart to programming language.
  • 36. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 36 Disadvantages:  It does not provide visual representation of the program’s logic.  There are no accepted standards for writing pseudo codes.  It cannot be compiled nor executed.  For a beginner, It is more difficult to follow the logic or write pseudo code ascompared to flowchart. Comparison of algorithm, flowchart and pseudocode 1.3 Programming Paradigms Paradigm can also be termed as a method to solve some problems or do some tasks. A programming paradigm is an approach to solve the problem using some programming language or also we can say it is a method to solve a problem using tools and techniques that are available to us following some approach. There are lots of programming languages that are known but all of them need to follow some strategy when they are implemented and this methodology/strategy is paradigms.
  • 37. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 37 Imperative programming paradigm: It is one of the oldest programming paradigm. It features close relation relation to machine architecture. It is based on Von Neumann architecture. It works by changing the program state through assignment statements. It performs step by step task by changing state. The main focus is on how to achieve the goal. The paradigm consists of several statements and after execution of all the result is stored. Declarative programming paradigm: It is divided as Logic, Functional, Database. In computer science the declarative programming is a style of building programs that expresses logic of computation without talking about its control flow. It often considers programs as theories of some logic.It may simplify writing parallel programs. The focus is on what needs to be done rather how it should be done basically emphasize on what code code is actually doing. It just declare the result we want rather how it has be produced. This is the only difference between imperative (how to do) and declarative (what to do) programming paradigms. Getting into deeper we would see logic, functional and database. Python supports three types of Programming paradigms  Object Oriented programming paradigms  Procedure Oriented programming paradigms  Functional programming paradigms
  • 38. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 38 Object Oriented programming paradigms In the object-oriented programming paradigm, objects are the key element of paradigms. Objects can simply be defined as the instance of a class that contains both data members and the method functions. Moreover, the object-oriented style relates data members and methods functions that support encapsulation and with the help of the concept of an inheritance, the code can be easily reusable but the major disadvantage of object-oriented programming paradigm is that if the code is not written properly then the program becomes a monster. Advantages  Relation with Real world entities  Code reusability  Abstraction or data hiding Disadvantages  Data protection  Not suitable for all types of problems  Slow Speed Procedural programming paradigms In Procedure Oriented programming paradigms, series of computational steps are divided modules which means that the code is grouped in functions and the code is serially executed step by step so basically, it combines the serial code to instruct a computer with each step to perform a certain task. This paradigm helps in the modularity of code and modularization is usually done by the functional implementation. This programming paradigm helps in an easy organization related items without difficulty and so each file acts as a container. Advantages  General-purpose programming  Code reusability  Portable source code Disadvantages  Data protection  Not suitable for real-world objects  Harder to write
  • 39. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 39 Functional programming paradigms A functional programming paradigm is a paradigm in which everything is bind in pure mathematical functions style. It is known as declarative paradigms because it uses declarations overstatements. It uses the mathematical function and treats every statement as functional expression as an expression is executed to produce a value. Lambda functions or Recursion are basic approaches used for its implementation. The paradigms mainly focus on “what to solve” rather than “how to solve”. The ability to treat functions as values and pass them as an argument make the code more readable and understandable. Advantages  Simple to understand  Making debugging and testing easier  Enhances the comprehension and readability of the code Disadvantages  Low performance  Writing programs is a daunting task  Low readability of the code 1.4 PROGRAMMING LANGUAGE  A programming language is a set of symbols and rules for instructing a computer to perform specific tasks. The programmers have to follow all the specified rules before writing program using programming language.  The user has to communicate with the computer using language which it can understand. Types of programming language 1. Machine language 2. Assembly language 3. High level language Machine language: The computer can understand only machine language which uses 0’s and 1’s. In machine language the different instructions are formed by taking different combinations of 0’s and 1’s. Advantages:  Translation free:Machine language is the only language which the computer understands. For executing any program written in any programming language, the conversion to
  • 40. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 40 machine language is necessary. The program written in machine language can be executed directly on computer. In this case any conversion process is not required.  High speed: The machine language program is translation free. Since the conversion time is saved, the execution of machine language program is extremely fast. Disadvantages:  It is hard to find errors in a program written in the machine language.  Writing program in machine language is a time consuming process.  Machine dependent: According to architecture used, the computer differs from each other. So machine language differs from computer to computer. So a program developed for a particular type of computer may not run on other type of computer. Assembly language:  To overcome the issues in programming language and make the programming process easier, an assembly language is developed which is logically equivalent to machine language but it is easier for people to read, write and understand.  Assembly language is symbolic representation of machine language. Assembly languages are symbolic programming language that uses symbolic notation to represent machine language instructions. They are called low level language because they are so closely related to the machines. Ex: ADD a, b Assembler: Assembler is the program which translates assembly language instruction in to a machine language. Advantages  Easy to understand and use.  It is easy to locate and correct errors. Disadvantages  Machine dependent: The assembly language program which can be executed on the machine depends on the architecture of that computer.  Hard to learn: It is machine dependent, so the programmer should have the hardware knowledge to create applications using assembly language.
  • 41. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 41  Less efficient: Execution time of assembly language program is more than machine language program.Because assembler is needed to convert from assembly language to machine language. High level language High level language contains English words and symbols. The specified rules are to be followed while writing program in high level language. The interpreter or compilers are used for converting these programs in to machine readable form. Translating high level language to machine language The programs that translate high level language in to machine language are called interpreter or compiler. Compiler: A compiler is a program which translates the source code written in a high level language in to object code which is in machine language program. Compiler reads the whole program written in high level language and translates it to machine language. If any error is found it display error message on the screen. Interpreter Interpreter translates the high level language program in line by line manner. The interpreter translates a high level language statement in a source program to a machine code and executes it immediately before translating the next statement. When an error is found the execution of the program is halted and error message is displayed on the screen. Advantages  Readability: High level language is closer to natural language so they are easier to learn and understand  Machine independent: High level language program have the advantage of being portable between machines.  Easy debugging: Easy to find and correct error in high level language Disadvantage  Less efficient: The translation process increases the execution time of the program. Programs in high level language require more memory and take more execution time to execute.
  • 42. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 42 They are divided into following categories: 1. Interpreted programming languages 2. Functional programming languages 3. Compiled programming languages 4. Procedural programming languages 5. Scripting programming language 6. Markup programming language 7. Concurrent programming language 8. Object oriented programming language 1. Interpreted programming languages:  An interpreted language is a programming language for which most of its implementation executes instructions directly, without previously compiling a program into machine language instructions.  The interpreter executes the program directly translating each statement into a sequence of one or more subroutines already compiled into machine code. Examples:Pascal, Python 2. Functional programming language:  Functional programming language defines every computation as a mathematical evaluation. They focus on the programming languages are bound to mathematical calculations Examples: Clean, Haskell 3. Compiled Programming language:  A compiled programming is a programming language whose implementation are typically compilers and not interpreters.  It will produce a machine code from source code. Examples: C, C++, C#, JAVA 4. Procedural programming language:  Procedural (imperative) programming implies specifying the steps that the programs should take to reach to an intended state.  A procedure is a group of statements that can be referred through a procedure call.
  • 43. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 43  Procedures help in the reuse of code. Procedural programming makes the programs structured and easily traceable for program flow. Examples: Hyper talk, MATLAB 5. Scripting language:  Scripting language are programming languages that control an application.  Scripts can execute independent of any other application. They are mostly embedded in the application that they control and are used to automate frequently executed tasks like communicating with external program. Examples: Apple script, VB script 6. Markup languages:  A markup language is an artificial language that uses annotations to text that define hoe the text is to be displayed. Examples:HTML, XML 7. Concurrent programming language:  Concurrent programming is a computer programming technique that provides for the execution of operation concurrently, either with in a single computer or across a number of systems. Examples:Joule, Limbo 8. Object oriented programming language:  Object oriented programming is a programming paradigm based on the concept of objects which may contain data in the form of procedures often known as methods. Examples: Lava, Moto Iterations: A sequence of statements is executed until a specified condition is true is called iterations. 1. for loop 2. While loop
  • 44. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 44 Flow chart Recursions  A function that calls itself is known as recursion.  Recursion is a process by which a function calls itself repeatedly until some specified condition has been satisfied. Algorithm for factorial of n numbers using recursion: Main function: Step1: Start
  • 45. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 45 Step2: Get n Step3: call factorial (n) Step4: print fact Step5: Stop Sub function factorial(n): Step1: if(n==1) then fact=1 return fact Step2: else fact=n*factorial(n-1) and return fact Flowchart Pseudo code for factorial using recursion: Main function: BEGIN GET n CALL factorial(n) PRINT fact BIN Sub function factorial(n): IF(n==1) THEN fact=1
  • 46. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 46 RETURN fact ELSE RETURN fact=n*factorial(n-1) EXAMPLE 1: Write an algorithm to find area of a rectangle ALGORITHM PSEUDOCODE FLOW CHART Step 1: Start Step 2: get l,b values Step 3: Calculate A=l*b Step 4: Display A Step 5: Stop BEGIN READ l,b CALCULATE A=l*b DISPLAY A END
  • 47. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 47 EXAMPLE 2: Write an algorithm for Calculating area and circumference of circle ALGORITHM PSEUDOCODE FLOW CHART Step 1: Start Step 2: get r value Step 3: Calculate A=3.14*r*r Step 4: Calculate C=2.3.14*r Step 5: Display A,C Step 6: Stop BEGIN READ r CALCULATE A and C A=3.14*r*r C=2*3.14*r DISPLAY A END EXAMPLE 3: Write an algorithm for calculating simple interest ALGORITHM PSEUDOCODE FLOW CHART Step 1: Start Step 2: get P, n, r value Step3:Calculate SI=(p*n*r)/100 Step 4: Display S Step 5: Stop BEGIN READ P, n, r CALCULATE S SI=(p*n*r)/100 DISPLAY SI END
  • 48. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 48 EXAMPLE 4: Write an algorithm for calculating engineering cutoff ALGORITHM PSEUDOCODE FLOW CHART Step 1: Start Step2: get P,C,M value Step3:calculate Cutoff= (P/4+C/4+M/2) Step 4: Display Cutoff Step 5: Stop BEGIN READ P,C,M CALCULATE Cutoff= (P/4+C/4+M/2) DISPLAY Cutoff END EXAMPLE 5: To check greatest of two numbers ALGORITHM PSEUDOCODE FLOW CHART Step 1: Start Step 2: get a,b value Step 3: check if(a>b) print a is greater Step 4: else b is greater Step 5: Stop BEGIN READ a,b IF (a>b) THEN DISPLAY a is greater ELSE DISPLAY b is greater END IF END
  • 49. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 49 EXAMPLE 6: To check leap year or not ALGORITHM PSEUDOCODE FLOW CHART Step 1: Start Step 2: get y Step 3: if(y%4==0) print leap year Step 4: else print not leap year Step 5: Stop BEGIN READ y IF (y%4==0) THEN DISPLAY leap year ELSE DISPLAY not leap year END IF END EXAMPLE 7:To check positive or negative number ALGORITHM PSEUDOCODE FLOW CHART Step 1: Start Step 2: get num Step 3: check if(num>0) print a is positive Step 4: else num is negative Step 5: Stop BEGIN READ num IF (num>0) THEN DISPLAY num is positive ELSE DISPLAY num is negative END IF END
  • 50. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 50 EXAMPLE 8: To check odd or even number ALGORITHM PSEUDOCODE FLOW CHART Step 1: Start Step 2: get num Step 3: check if(num%2==0) print num is even Step 4: else num is odd Step 5: Stop BEGIN READ num IF (num%2==0) THEN DISPLAY num is even ELSE DISPLAY num is odd END IF END EXAMPLE 9: To check greatest of three numbers ALGORITHM PSEUDOCODE Step 1 : Start Step 2 : Read the value of a, b, c Step 3 : Compare the values of a, b and c. Step 4 : If a is greater than b, compare a with c. If a is greater than c then print a is big. Step 5 : If a is not greater than b & c then compare b and c. Step 6 : If b is greater than c print b is big else print c is big. Step 7 : Stop BEGIN READ a, b, c IF (a>b) THEN IF(a>c) THEN DISPLAY a is greater ELSE DISPLAY c is greater END IF ELSE IF(b>c) THEN DISPLAY b is greater ELSE
  • 51. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 51 DISPLAY c is greater END IF END IF END FLOW CHART
  • 52. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 52 EXAMPLE 10: Write an algorithm to check whether given number is +ve, -ve or zero. ALGORITHM PSEUDOCODE Step 1: Start Step 2: Get n value. Step 3: if (n ==0) print “Given number is Zero” Else goto step4 Step 4: if (n > 0) then Print “Given number is +ve” Step 5: else Print “Given number is -ve” Step 6: Stop BEGIN GET n IF(n==0) THEN DISPLAY “ n is zero” ELSE IF(n>0) THEN DISPLAY “n is positive” ELSE DISPLAY “n is positive” END IF END IF END FLOW CHART
  • 53. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 53 EXAMPLE 11: Write an algorithm to print all natural numbers up to n ALGORITHM PSEUDOCODE Step 1: Start Step 2: get n value. Step 3: initialize i=1 Step 4: if (i<=n) go to step 5 else go to step 8 Step 5: Print i value step 6 : increment i value by 1 Step 7: go to step 4 Step 8: Stop BEGIN GET n INITIALIZE i=1 WHILE(i<=n) DO PRINT i i=i+1 ENDWHILE END FLOW CHART
  • 54. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 54 EXAMPLE 12: Write an algorithm to print n odd numbers ALGORITHM PSEUDOCODE Step 1: start step 2: get n value step 3: set initial value i=1 step 4: check if(i<=n) goto step 5 else goto step 8 step 5: print i value step 6: increment i value by 2 step 7: goto step 4 step 8: stop BEGIN GET n INITIALIZE i=1 WHILE(i<=n) DO PRINT i i=i+2 ENDWHILE END FLOW CHART i=i+2
  • 55. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 55 EXAMPLE 14: Write an algorithm to find sum of a given number ALGORITHM PSEUDOCODE Step 1: start step 2: get n value step 3: set initial value i=1, sum=0 Step 4: check i value if(i<=n) goto step 5 else goto step8 step 5: calculate sum=sum+i step 6: increment i value by 1 step 7: goto step 4 step 8: print sum value step 9: stop BEGIN GET n INITIALIZE i=1,sum=0 WHILE(i<=n) DO sum=sum+i i=i+1 ENDWHILE PRINT sum END FLOW CHART
  • 56. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 56 EXAMPLE 15: Write an algorithm to find factorial of a given number ALGORITHM PSEUDOCODE Step 1: start step 2: get n value step 3: set initial value i=1, fact=1 Step 4: check i value if(i<=n) goto step 5 else goto step8 step 5: calculate fact=fact*i step 6: increment i value by 1 step 7: goto step 4 step 8: print fact value step 9: stop BEGIN GET n INITIALIZE i=1,fact=1 WHILE(i<=n) DO fact=fact*i i=i+1 ENDWHILE PRINT fact END FLOW CHART
  • 57. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 57 EXAMPLE 16: To print the reverse of a number. ALGORITHM PSEUDOCODE Step 1 : Start Step 2 : Initialize r=0, sum=0 Step 3 : READ the value of n Step 4 : If n>0 do the following else goto step 6 Step 4.1 r=n mod 10 Step 4.2 sum=sum*10+r Step 4.3 n=n div 10 Step 5 : Goto step 4 Step 6 : Print sum Step 7 : Stop Set initial sum=0, r=0 READ the value of n WHILE (n>0) r=n%10 sum=sum*10+r n=n//10 ENDWHILE Repeat while until the condition fail WRITE the sum Stop
  • 58. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 58 EXAMPLE 17: Find Fibonacci Series for the first ‘n’ terms ALGORITHM PSEUDOCODE Step 1 : Start Step 2 : Assign F1=0, F2=1, F=0 Step 3 : Read the value of n Step 4 : print the values of F1, F2 Step 5 : Calculate F = F1+F2 Step 6 : If (F<n) do the following else goto step 8 Step 6.1 : F = F1+F2 Step 6.2 : F1 = F2 Step 6.3 : F2 = F1 Step 6.4 : Print F Step 7 : Goto step 6 Step 8 : Stop Set initial zero to F, F1 and 1 to F2 READ the value of n WRITE F1, F2 Calculate F=F1+F2 WHILE (F<n) F=F1+F2 F1=F2 F2=F i=i+1 WRITE F ENDWHILE Repeat while until the condition fail Stop
  • 59. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 59 EXAMPLE 18:Write an algorithm for swapping two no’s using a third variable ALGORITHM FLOW CHART Step 1 : Start Start 2 : READ num1, num2 Start 3 : temp = num1 Start 4 : num1 = num2 Start 5 : num2 = temp Start 6 : PRINT num1, num2 Start 7 : Stop
  • 60. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 60 EXAMPLE 19: Write an algorithm for swapping two no’swithout using a third variable ALGORITHM FLOWCHART Step 1 : Start Step 2 : READ num1, num2 Step 3 : num1 = num1 + num2 Step 4 : num2 = num1 - num2 Step 5 : num1 = num1 - num2 Step 6 : PRINT num1, num2 Step 7 : Stop 1.5 Features of A Good Programming Language There are various factors, why the programmers prefer one language over the another. And some of very good characteristics of a good programming language are, 1) Clarity, Simplicity And Unity: A Programming language provides both a conceptual framework for Algorithm planning and means of expressing them. It should provide a clear, simple and unified set of concepts that can be used as primitives in developing algorithms. It should have • It has minimum number of different concepts •- with Rules for their combination being •-simple and regular. This attribute is called conceptual integrity.
  • 61. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 61 2) Orthogonality: It is one of the most important feature of PL orthogonality is the property that means " Changing A does not change B". If I take Real world example of an orthogonal system Would be a radio, where changing the station does not change the volume and vice versa. When the features of a language are orthogonal, language is easier to learn and programs are easier to write because only few exceptions and special cases to be remembered. 3) Support for Abstraction:- There is always found that a substantial gap remaining between the abstract data structure and operations that characterize the solution to a problem and their particular data structure and operations built into a language. 4) Programming Environment: An appropriate programming environment adds an extra utility and make language to be implemented easily like The availability of- Reliable- Efficient - Well documentation Speeding up creation and testing by-special Editors- testing packages Facility- Maintaining and Modifying- Multi Version of program software product. 5) Ease of program verification:- Reusability: The reusability of program written in a language is always a central concern. A program is checked by various testing technique like Formal verification method Desk checking Input output test checking.
  • 62. B19CST101- PROBLEM SOLVING AND PYTHON PROGRAMMINGUNIT 1 62 We verify the program by many more techniques. A language that makes program verification difficult maybe far more troublesome to use. Simplicity of semantic and syntactic structure is a primary aspect that tends to simplify program verification. 6) Portability of programs: Programming language should be portable means it should be easy to transfer a program from which they are developed to the other computer. A program whose definition is independent of features of a Particular machine forms can only support Portability. Example: Ada, FORTRAN, C, c++, Java.