[go: up one dir, main page]

0% found this document useful (0 votes)
22 views19 pages

CS Unit I

The document discusses computational thinking and problem solving. It defines a computer and its basic components. It then explains key concepts in computational thinking like decomposition, pattern recognition, abstraction, and algorithms. It provides examples of using these concepts to solve problems. Finally, it discusses algorithms, their characteristics, and provides examples of algorithms to interchange values and find the radius of a circle.

Uploaded by

Hemavathy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views19 pages

CS Unit I

The document discusses computational thinking and problem solving. It defines a computer and its basic components. It then explains key concepts in computational thinking like decomposition, pattern recognition, abstraction, and algorithms. It provides examples of using these concepts to solve problems. Finally, it discusses algorithms, their characteristics, and provides examples of algorithms to interchange values and find the radius of a circle.

Uploaded by

Hemavathy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

COMPUTATIONAL

THINKING &
PROBLEM SOLVING
NOTES

Hemavathy Kannan UNIT I BTECH AI&DS


1)FUNDAMENDALS OF it with programs stored in its
COMPUTING memory to reduce the output. All
the modern computers like
A computer is a machine or a laptops,desktops including
device that performs process, smartphones are digital
calculations and operations based computers.
on the instructions provided by a HYBRID COMPUTER
software or hardware program.
Hybrid computers has features
TYPES OF COMPUTER of both analogue and digital
We can categorize computer computer. It is fast like an
in two ways; on the basis of data analogue computer and has
handling capabilities and size. memory and accuracy like digital
computers. It can process both
 Analogue computer
continuous and discrete data. It
 Digital computer accepts analogue signals and
 Hybrid computer convert them into digital form
ANALOGUE COMPUTER before processing.
Analogue computer are FUNCTIONALITIES OF A
designed to process analogue COMPUTER
data. It is continuous and cannot  Takes data as input
have discrete values. We can say
 Stores the data/instructions
that such as speed, temperature,
in its memory and use them
pressure and current.
when required
DIGITAL COMPUTER  Processes the data and
Digital computer is designed converts it into useful
to perform calculations and information
logical operations at high speed.  Generates the output
It accepts the raw data and input
in the form of digits or binary
numbers(0 and 1) and processes
INPUT-PROCESS-OUTPUT MODEL
Computer input is called data and the output obtained after
processing it , based on user’s instructions is called information.

INPUT PROCESS OUTPUT

COMPUTER COMPONENTS
Any kind of computer consist of
 Hardware
 Software

HARDWARE
It represents the physical components of a computer like its
electronics parts. For example CPU, memory, hard disk, monitor,
printer,mouse etc,.

SOFTWARE
It represents the programs which perform different tasks on a
computer system. It is a programming code which is executed by CPU,
which can takes instructions from input devices like keyboard, mouse,
and can show output on output devices like monitor, printer etc,.

DIFFERENCE BETWEEN HARDWARE AND SOFTWARE:


KEY HARDWARE SOFTWARE
Type Hardware is a set of Software is a program
physical parts of or set if instruction
computers which aactually which are to be
executes the instruction. executed by CPU to
Development
do the intended task.
A hardware is A software is
manufactured in factories. developed engineered
Dependency by software
development
A hardware cannot do any
companies.
task with a software
Tangible A software cannot
instructing it.
execute if-underlying
hardware is not
Categories A hardware can be present.
touched being a physical
electronic device. Software being digital
Hardware categories: can be seen but cannot
Virus impact Input devices, output be touched.
devices ,storage devices, Software categories:
internal components of Programming,
Digital Transfer CPU and mother board. application softwares
and operating system.
Hardware remain
Replacement unaffected by viruses.
Software is affected
by virus being primary
A hardware can be only barget.
physically transferred.
Software can be
If hardware gets damaged, transferred
it is replaced with new electronically.
one. If software gets
damaged, it is
reinstalled.
2) COMPUTATIONAL Computational thinking
allows us to take a complex
THINKING
problem, understand what the lead to grouping, organizing or
problem is and develop possible streaming problems for more
solutions. It is a set of problem efficient outcomes.
solving methods that expressing ABSTRACTION
problems and this solutions in
ways that a computer could also Generalization of problems-
execute. focusing on the important
information only, ignoring
The four key techniques to irrelevant details. Abstraction
computational thinking: allows us to create a general idea
 Decomposition of what the problem is and how
 Pattern recognition to solve it.
 Abstraction
 Algorithm
ALGORITHMS
DECOMPOSITION
When solving a problem , it is
Breaking down the problems important to create a plan for
into smaller sections. Breaking your solution. Algorithms are a
down the problems can make strategy that can be used to
complicated challenges more determine the step by step
manageable. This enables other instruction on how to solve the
complicational thinking elements problem.
to be applied more effectively to
complex challenges. The 3) IDENTIFICATION OF
solutions to the smaller problems COMPUTATIONAL
are then combined to solve the PROBLEMS
original, larger problem.
Many systems in the natural
PATTERN RECOGNITION sciences can be represented by
Recognizing if there us a means of a mathematical
pattern and determining the expressions, known as
sequence. Eraminig solved mathematical model. This
problems can simplify the expression may be fairly complex
solution. Pattern recognition can in form and thus it may not be
possible to make a reasonable true for the problem, then
application of the standard reassess the problem and try
methods of evaluation to the the process again.
expression.
4) ALGORITHM
If this is true, then it is
An algorithm is a finite set of
standard practice to make an
instruction used for solving
attempt at evaluating the
problems in a step-by-step
expressions by various
manner. It is an ordered sequence
approximation methods. For any
of finite, well defined instruction
problems that we must consider
for completing a task.
there are a number of steps that
are suggested for one to take in CHARACTERISTICS OF
the process of finding a ALGORITHM
computational solution of the
problem, and then for assessing
the viability of this solution.
THE FIVE STEP PROCESS:
1. Identify the problem
2. Express the problem in
terms of a mathematical
model
3. Construct a computational
method for solving the
model
4. Implement the
computational method on a
computer.
5. Access the result; if there is
a releatively large display
between your solution and
the actual solution or what
you know can actually br
 Control flow
 Functions
INSTRUCTION/STATEMEMT
ALGORITHM FOR An instruction written in a high
INTERCHANGING OR level language. It directs to the
SWAPPING TWO VALUES computer to perform a action. It
STEP 1: Start the program. can be classified into simple
statement, compound statement.
STEP 2: Read two numbers a,b
Simple statement Compound
STEP 3: Set temp=a statement
assignment: block:begin……end
a=b sum=0
goto:goto big While:while…action
b=temp return:returnsum for:for(……..)
Functioncall:add()
STEP 4: Print a and b
STATE
STEP 5: Stop
The state of an algorithm is
ALGORITHM TO FIND THE defined as its condition regarding
RADIUS OF CIRCLE: current values or contents of the
STEP 1: Start the program. stored data.
STEP 2: Read radius r CONTROL FLOW
STEP 3: Calculate area=3.14*r*r The logic of the program may
not always be a linear sequence
STEP 4: Print area
of statements to be executed in
STEP 5: Stop order. It has been proven that any
5)BUILDING BLOCKS algorithm can be constructed
from three building blocks.
OF ALGORITHM
1. Sequence
An algorithm starts from an 2. Selection
sequence of instructions 3. Iteration
 Instruction/Statements
 State
SEQUENCE CONTROL Making decisions. It is usually
SELECTION depicted as if…., if…..else
The sequence logic is used statements.
for performing instructions one (eg)ALGORITHM TO TEST
after another. The sequence THE 2 NUMBERS ARE
control structures use top-down EQUAL OR NOT
approach. STEP 1: Start
(eg)ALGORITHM TO FIND STEP 2: Read two numbers x,y
SUM OF 2NO’S
STEP 3: If x==y print “Equal”
STEP 1:Start the program. else print “not equal”
STEP 2:Read two values a and b STEP 4: Stop
STEP 3:Sum=a+b
STEP 4:Print sum
STEP 5:Stop

START

ITERATION OR REPETATION
PROCESS Which involves executing
one or more steps for a number
of times, can be implemented
using constructs such as the
STOP while loops and for loops. There
loops execute one or more steps
until some condition is true.
SELECTION CONTROL
STRUCTURE (eg)ALGORITHM TO FIND
THE SUM OF FIRST N
The selection logic is used for NUMBERS
STEP 1: Start Sub fun add()
STEP 2: Read n STEP 1: Function Start
STEP 3: Set i=1, sum=0 STEP 2: Read two values
STEP 4: Repeat step 4 & step 5 STEP 3: sum=a+b
while i<=n STEP 4: Print sum
STEP 5: Set sum=sum+I, set STEP 5: Return
i=i+1(end of loop)
STEP 6: Stop
6)NOTATION
A series or system of written
FUNCTIONS
symbols used to represent
Function is a subprogram numbers, amounts or elements in
which consist of blocks of code programming language is called
that performs a particular task, as notation.
for complex problems the
problem is divided into smaller  Pseudo code
and simpler tasks during  Flow chart
algorithm design. PSEUDO CODE
Function provide reduction Pseudo code is a compact
in line of code, code reuse, better and informal high level
readability, easy to debug and descrption of an algorithm that
test. uses the structure conventions
(eg)ALGORITHM TO FIND “code” means the set of
SUM OF 2NO’S USING statements or instructions written
FUNCTION in a programming language. It is
also called as “ Program Design
Main function Language”-PDL
STEP 1: Start RULES FOR WRITING
STEP 2: Call the function add() PSEUDOCODE:
STEP 3: Stop 1. Write one statement per line
2. Capitilize initial keywords
3. Indent to show hierarchy
Indentation is the process of
4. Keep statements language showing the “boundaries” of the
independent. structure . in case of sequence
5. End multiline structure structure we would not have any
WRITE ONE STATEMENT indentation, but in the loop or
PER LINE: selection structure we must use
indentation.
Each statement in the
pseudo code should express just (eg) READ name,m1,m2,m3
one action for the computer. CALC tot=m1+m2+m3
(eg)TO CALCULATE CALC avg=tot/3
STUDENT TOTAL AND If Avg is greater than 90
AVERAGE
PRINT DISTINCTION
READ name,m1,m2,m3
ENDIF
CALC tot=m1+m2+m3
PRINT NAME
PRINT name,tot,avg
END MULTI LINE
CAPITALIZE INITIAL STRUCTURE
KEYWORDS:
Each structure must be
The keywords in the pseudo ended properly,which provide
code should be written in all more clarity. It indicates where
capital letters , because they the loop or selection is completed
begin the statement and they are or ended.
command words, they give
special meaning to the operation (eg) ENDIF, ENDWHILE

READ,WRITE,IF,ELSE, KEEP STATEMENTS


LANGUAGE INDEPENDENT:
FOR…….are keywords , that
must be written in capital letters Pseudo code can be written in
any language.
INDENT TO SHOW
HIERARCHY ADVANTAGES:
 Converting pseudo code to  The standard symbols
programming language is should only be used.
easy.  The arrow heads in the
 It can be easily modified as flowchart representsd the
compared to flowchart. direction of flow of control
 It’s implementation is very in the problem.
useful in structured design.  The usual direction of the
 It can be read and floe of procedure is from top
understand easily. to bottom or left or right.
DISADVANTAGES:  Only one flowline should
come to a process symbol
 There is no standardised and only one flowline
style or format. should out from a process
 For a beginner it is more symbol
difficult to follow the logic
or write pseudo code.
 It is not visual.
FLOW CHARTS
A flowchart is a graphical or
symbolic representation of a  Only one flowline should
process. It is basically used to enter a decision symbol, and
design and visualize the logic of two or three flowline, one
the process. for each possible answer
When designing Flowchart, should leave the decision
each step in the process is symbol.
depicted by a different symbol
and is associated with a short
description.
BASIC GUIDELINES TO
DRAW A FLOWCHART:
 Only one flowline is used in Flow lines
conjunction with terminal represents the
symbol. sequence of
steps and
direction of
 Flowlines should not flow used to
intersect with each other. connect
symbols.
Connectors are
 Ensure that the flowchart
used to indicate
has a logical startand stop.
a continued
flow.
 Write with in the standard Process symbol
symbol briefly, As represents
necessary use the annotation arithmetic and
symbol to describe data or data movement
computational steps more instruction.
clearly---[Read n values Input /output
used to get
SYMBOLS DESCRIPTION input from the
Terminal users or display
symbol the results.
represent the Predefined
start and stop of processor (or)
the program. function is a
Decision marker for
symbol is another process
always used to step or series of
depict a yes/no process flow
que or true/false steps that are
test formally
defines
elsewhere.

ADVANTAGES OF
START STOP FLOWCHART:
 To understand logic clearly. Low level programming
 Better communication language is a programming
 Effective analysis. language that provides little or no
 Effective coding. abstraction from a computer
 Systematic testing. instruction set architecture. It
 Effective program refers either machine code or
maintanence. assembly language.
Machine code: It is the only
DISADVANTAGES OF language a computer can process
FLOWCHART: directly without any
transformation. It is a stream of
 Complex logic binary data.(eg) 0110110000001
 Alterationsn and
modifications. Assembly language: Second
 Reproduction. generation programming
language use a simple processor
Draw a flowchart to check the called an assembler. Assembly
given no is palindrome or not . language has little semantics or
PROGRAMMING LANGUAGE formal specification,being only a
mapping of human-readable
A programming language is
symbols, including symbolic
a formal language that specifies a
addresses to opcodes,addresses,
set of instructions that can be
numeric constants, strings and
used to produce various kinds of
soon.
outputs. Programming language
generally consist of instructions In general assembler instructions
for a computer. have 3 components,
It can be classified into 2 types:  Mnemonic-easily
remembered instruction
 High-level programming
name.
language .
 Operand- the data to be
 Low-level programming
used such a memory
language
addresses or a register.
LOW LEVEL  Command-to make reading
PROGRAMMING LANGUAGE the code easier.
(eg)LD ACC,#43500;load the Statistical and Engg type
number into the accumulator. procedures.
STO ACC, 46000;store the Java- Mobile application, web
contents of a memory location apps, GOI app etc,.
in acc. Pascal- Application
HIGH LEVEL programming.
PROGRAMMING Python- Web programming,
LANGUAGE: Scripting programming.
A high level language is any
programming language that 7)ALGORITHMIC
PROBLEM SOLVING
Enables development of
aprogram in a much more
user-friendly programming Algorithmic problem
context and is generally solving is about the formation
independent if the computer and solution of problems, where
hardware architecture. the solution involves the
The first high level language principles and techniques that
were introduce in 1950s . have been developed to assist in
There includes BASIC,C,C+
+,COBOL,
FORTRON,JAVA,PASCAL,
PYTHON,PHP,RUBY etc,.
Basic- It is an easy to
understand programming
language.
C- It is used for creating
computer application.
C++-System oriented
applications, Graphic
designing applications.
Fortan-
Scientific ,Mathematical,
the construction of correct complex and not able to get excat
algorithm solution, then we have to choose
UNDERSTANDING THE an algorithm is called
PROBLEM: approximation algorithm.

Read the problems (eg) Extracting square roots,


description carefully to solving non-linear equation and
understand the problem statement evacuating define integrals.
completely. It is compared with SELECT THE APPROXIMATE
earlier problems, if it is similar to DATA STRUCTURES:
them then the same algorithm is A datatype is a well defined
used, otherwise a new one have collection of data with a well
to be developed. defined set of operations on it. A
data structure is basically a group
DETERMINING THE of data elements that are put
CAPABILITIES OF THE together under one name and
COMPUTATIONAL DEVICE: which defines a particular way of
storing and organizing data in a
After understanding the computer.
problem, the capabilities of the
computing device should be The elementary data structures
known. For this the type of are:
architecture, speed and memory List: Allows fast access of data.
availability of the device are Sets: Treats data as element of a
noted. set. Allows application of
Choice of computational operations such as intersection,
devices like processor and union and equivalence.
memory is mainly based on space Dictionaries: Allows data to be
and time efficiency. stored as a keyvalue pair.
EXACT/ APPROXIMATION ALGORITHM DESIGN
SOLUTION: TECHNIQUES:
An algorithm used to solve An algorithm design
the problem exactly and produce technique is a general approach
correct result is called excat to solving problems
algorithm. If the problem is to algorithmically, that is applicable
to a variety of problems from of CPU time and memory space
different areas of computing. required to execute the algorithm.
Developing an algorithm is This is a challenging task and is
an art which may never be fully often used to compare different
automated. algorithms for a particular
problem. The result of the
METHODS OF SPECIFYING comparision helps us to choose
AN ALGORITHM: the best solution from all possible
An algorithm is just a solutions.
sequence of steps are instructions Analysis of the algorithm
that can be used to implement a also helps us to determine
solution, After writing the whether, the algorithm will be
algorithm, it is specified either able to meet any efficiency
using a natural language or with constraint that exists or note.
the help of pseudo code or
flowcharts. CODE THE ALGORITHM:

PROVING ALGORITHMS The coding/ implementation


CORRECTNESS: of an algorithm is done by any
suitable programming language.
Writing an algorithm is not Implementing an algorithm
enough . we need to prove that it correctly is necessary.
computes solutions for all the
possible valid inputs. This 8) SIMPLE STRATEGIES
process is often referred to as FOR DEVELOPING
algorithm validation. Algorithm ALGORITHM
validation ensures that the
algorithm will work correctly ITERATION
irrespective of the programming Iteration or repetation which
language in which it will be involves executing one or more
implemented. steps for a number of times until
ANALYSING THE a condition is met.They use
PERFORMANCE OF repetitive constructs like for loop
ALGORITHMS: and while loop.
An algorithm is analysed to Key features are used to design a
measure its performance in terms loop,
Press(or iteration)- one For loop is the most
complete execution of the body. comfortable loop. It is also called
Loop entry- the point where as entry check loops. The
flow of control passes to the condition is checked in the
body. beginning and the body of the
loop is executed only if the
Loop test- the point at which the condition is true otherwise the
decision a made to re enter the condition is not executed.
body or not.
Definite loops have explicit
Loop exit- the point at which the iteration variables that change
iteration ends and control passes each time through the loop.
to the next statement after the These iteration variables move
loop. through the sequence or set.
Termination-the condition that
causes the iteration to stop.
WHILE LOOP The iteration variables iterates in
In the while loop , the the sequence. The body of code
Boolean expression is examined is executed once for each value in
before each pass through the the sequence. The iteration
body of the loop. If the Boolean variable moves through all of the
expression is true; the loop body values in the sequence.
is executed.If it is false execution
pseudo code to the first statement
for i in set
after the loop body.
n=0
print
Print i
i exit

n<5
RECURSION
It is a technique of solving a
Print n problem by breaking it down into
smaller and smaller subproblems
Cond is until we got to a small enough
n=n+1 false
problem that it can be easily
FOR LOOP solved. Recursion involves a
function calling itself until a 9)TOWERS OF HANOI
specified condition is met. Every
recursive solution has two major
cases.
Base case: In which the problem
is simple enough to be solved
directly without making any
further calls to the same function.
Recursive case: The problem is
divided into simpler subparts.
Second the function calls itself
but with subparts of the problem
obtained in the first step. Third
the result is obtained by
combining the solutions of
simpler subparts.
(eg) calculate the factorial of an
integer number:
n!=1x2x3x……xn where n is an
integer
we can also express this by n!
=n*(n-1)!

(eg) def fact(n):


If n==1:
return 1
else:
return n*fact(n-1)
fact(3) || function call

You might also like