python
python
python
I. FUNDAMENTALS OF COMPUTING:
A computer is an electronic device that can be programmed to accept data (input), process it and
generate result. A computer along with additional hardware and software together is called a computer
system.
Data: Data is defined as an un-processed collection of raw facts, suitable for communication,
interpretation or processing
Information: Information is a collection of facts that is processed to give meaningful, ordered or
structured information.
Characteristics of Computer:
Speed
Diligent
Accuracy
Reliability
Storage capability
Resource Sharing
Resource Sharing
Output Unit:
- It provides the processed data (information) to the user,
- It is understandable by the user
- Some output devices are monitor, printer and speaker.
(ii). Registers
Registers are high speed storage area within CPU
Registers store data, instructions, addresses and intermediate results of processing. So, registers
are often called as CPU’s working memory.
The data and instructions that require processing must be brought in the registers of CPU before
they can be processed.
Some of the important registers are
ACC : Accumulator stores the result of arithmetic and logical operations
IR : Instruction register contains the current instruction most recently fetched
PC : Program counter contains the address of next instruction to be executed
MAR : Memory Address register
MBR : Memory Buffer register
DR : Data Register
1. Memory Unit:
Cache Memory:
3
Primary Memory:
Primary memory is the main memory of computer. It is used to store data and instructions during the
processing.
It is of 2 kinds: RAM and ROM
RAM:
RAM is volatile
It stores data when computer is on, so it is a temporary storage
It provides limited storage capacity due to its high cost
ROM:
ROM is non-volatile and read only memory.
It is a permanent storage
It comes programmed by the manufacturer.
Secondary Memory:
The secondary memory stores data and instructions permanently.
It is non-volatile memory
Examples: Hard disk drive, floppy drive and optical disk drive
It takes longer time to access data. It has high storage capacity
It is cheaper than RAM
Applications:
Science
Education
Medical and Health Care
Engineering/Architecture/Manufacturing
Entertainment
Communication
Business Application
Publishing
Banking
The first step of computational thinking is decomposition. This stage stars by analyzing the problem,
stating it precisely, and establishing the criteria for the solution.
A computational thinking approach to a solution often starts by breaking the problem down into smaller
more familiar components so they can managed easier. The more you can break a problem down, the
easier it to be solve.
Pattern recognition:
Abstraction:
The abstraction stage involves the identification of key components of the solution
It requires the ability to filter out unnecessary elements of a problem so that only focus on the important
elements.
Algorithm Design:
The final stage within the computational thinking process is algorithm design whereby a detailed step by
step set of instructions are created which explain how to solve the problems
III. ALGORITHMS:
Algorithm is a step by step procedure for solving problem
It is an ordered sequence of finite and well defined instructions for completing a task
It is independent of any programming language.
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.Properties of
Algorithm:
Algorithm 3 Write an algorithm to find the minimum number in a given list of numbers.
Step 1: Start
Step 2: Read n.
Step 3: Read all n elements and store in list A.
Step 4: Assume first element in the list as min.
Step 5: Read all elements in the list one by one
If A[i] < min then assign
Min = a[i]
Step 6: Repeat step 5 till all the elements are compared.
Step 7: Print min as minimum element.
Step 8: Stop.
4. Functions:
The complex problem will become simpler if the problem is broken into smaller called functions
and the smaller problems are solved.
A function is a block of organized, reusable code that is used to perform a specific task.
A function provides better modularity and high degree of reusability.
V. NOTATION:
1. PSEUDOCODE :
Pseudo-imitation, Code- instruction
Pseudocode is a short, readable and formally styled English language for explaining an algorithm.
It is an outline of a program, written in a form that can be easily converted into realprogramming
statements
Some keywords used are;
Input : INPUT, HET, READ AND PROMPT
Output : OUTPUT, PRINT, DISPLAY AND SHOW
Processing: COMPUTE, CALCULATE, DETERMINE, ADD, SUBTRACT, MULTIPLY AND
DIVIDE.
Initialize : SET and INITIALIZE
Incrementing: INCREMENT
Benefits of pseudocode
Language independent.
It is easier to develop a program from a pseudocode than with a flowchart.
It is easy to translate pseudocode into a programming language.
It is compact and does not tend to run over many pages
. Its simple structureand readability make it easier to modify.
Limitations of pseudocode
It does not provide visual representation of the program’s logic
Programmers use their own style of writing. There are no accepted standards.
It cannot be compiled nor executed
Example: Find the product of any 2 numbers
READ values of A and B
COMPUTE C by multiplying A and B
PRINT the result C
2. FLOW CHART
A flowchart is a pictorial representation of an algorithm
A flowchart is drawn using boxes of different shapes with the lines connecting them to show the
flow of control.
Boxes represent operations and the arrows represent the sequence.
Flowchart Symbols
Examples:
10
Computer programming languages are used to communicate instructions to the computer. They
are based on certain syntactic and semantic rules, which define the meaning of each of the
programming language construct.
11
Compiled language is a programming language whose implementations are typically compilers and
not interpreters.
Procedural (Imperative) programming language implies specified in the steps that the programs
should take to reach to an intended state.
It makes the programs structured and easily traceable for program flow.
A markup language is an artificial language that uses annotations to text that define how the text is to
be displayed.
Logic programming is a type of programming paradigm which is largely based on formal logic.
Any program written in logical programming language is a set of sentences in logical form,
expressing facts and rules about some problem domain.
Concurrent programming is a computer programming technique that provides for the execution of
operations concurrently, either within a single computer, or across a number of systems.
In the later case, the term distributed computing is used.
12
There are various kinds of algorithm development techniques formulated and used for different types of
problems.
1. Iteration 2. Recursion
1. ITERATION:
Iteration is a process of repeating the same set of statements again and again until the specified condition
holds true. Computers execute the same set of statements again and again by putting them in a loop.
The number of iterations to be performed is known in advance. The counter-controlled loop starts with
the initial value of the loop counter and terminates when the final value of the loop counter is reached.
Since the counter-controlled loops iterate a fixed number of times, which is known in advance, they are
also known as definite repetition loops.
Example: Consider a program segment to find the sum of first 100 integers.
i =1
sum = 0
while (i<=100):
sum = sum + i
i=i+1
(ii)Condition-Controlled Loops
The number of times the iteration is to be performed is not known. The termination depends on the
special value in the condition. If the condition value is true, the loop body will be executed, otherwise
it will not. This is indefinite repetition loop.
Example: Consider a program segment to find the sum of first 100 integers.
1. Start
2. Read N
3. Assign sum = 0, i = 0
15
2. RECURSION:
In a recursive programming, a function calls itself. Recursion is used to solve the problems that can be
expressed in terms of similar problems of smaller size.
Direct Recursion:
A function is directly recursive if it calls itself.
Indirect recursion:
Indirect recursion occurs if the function calls another function.
Problem statement:
Finding the minimum number in a list
16
Flow Chart:
Start
Read n, List A
Min=A[0]
No
iF A[i]<Min
yes
Min=A[i]
PrintMMin
Stop
Pseudocode:
Min = A[0]
i=1
WHILE (i < = n-1)
IF(A[i] < MIN) THEN
Min = A[i]
END IF
i=i+1
END WHILE
PRINT Min
Problem Statement:
17
Algorithm:
Step 1: Start
Step 2: Read all numbers in an array A.
Step 3: Read Key.
Step 4: From the first position to the end of the array compare key and array element.
Step 5: if key < A then assign i to pos, and return pos.
Step 6: from n-1 to pos move the elements one position down.
Step 7: Now store key value in pos location.
Step 8: Stop
Flowchart:
Start
for i=0;i<=n-1;i++
No
Yes
if key<A[i]
pos=i
for (i=n-1;i>=pos;i--)
A[i+1]=A[i]
A[pos]=key
Print array A
Stop
Pseudocode:
18
Problem Statement:
The objective is to randomly generate integer number from 0 to n. Then the player has to guess the
number. If the player guesses the number correctly output an appropriate message.
If the guessed number is less than the random number generated, output the message “Your guess
is lower than the number. Guess again” .Then the player guesses another number. This process is
repeated until the player guesses the correct number.
Algorithm:
1. Start
2. Generate a random number and read num.
a. Enter the number to guess.
b. If(guess is equal to num)
Print “You guess the correct number”
Otherwise
If guess is less than num0
Print “Your guess is lower than the number. Guess again”
3. Stop
Flowchart:
Start
19
<num >num
if guess
=num
Stop
Pseudocode:
Binsearch( int value)
{
int upperBound, lowerBound, mid;
upperBound = n - 1;
lowerBound = 0;
while ( lowerBound < = upperBound)
{
mid = (upperBound + lowerBound) / 2;
If(A[mid] = = value)
return mid;
else
if(value < A[mid])
upperBound = mid - 1;
else
lowerBound = mid + 1;
}
return;
}
4. TOWER OF HANOI PROBLEM:
Problem Statement:
20
The “Tower of Hanoi problem” is to find a sequence of disk moves so that all the disks moved from
Stand-1 to Stand-3, adhering to the following rules.
The general strategy for solving the Tower of Hanoi problem with n disks is shown below.
21
Flowchart:
Hanoi
No
If disk=1
yes
Stop
22
Pseudocode:
START
Procedure Hanoi(disk, source, dest, aux)
If disk==1, THEN
Move disk from source to dest
ELSE
Hanoi(disk-1,source.aux,dest)
Move disk from source to dest
Hanoi(disk-1,aux,dest,source)
END IF
END Procedure
STOP
23