CS Unit I
CS Unit I
THINKING &
PROBLEM SOLVING
NOTES
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,.
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
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.
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)!