Cf&om - 1
Cf&om - 1
LEARNING GOALS
Computers are now affecting every sphere of human activity and bringing about many changes
in industry. government, education, medicine, scientific research. law, social scitncei;, and even
in arts such as music and painting. They are at present used, among other apphcations, to:
• Assist in bus, airlines, and railway reservation
• Send email and chat with friends using applications such as Fiicebook, Twitter, and
Skype (for video conferencing)
• Search for information using search engines such as Google, Bing. and Yahoo
• Refer to encyclopedias such as Wikipedia available on the World Wide Web
• Shop online for books, music, mobile phones, and many other consumer goods
• Simulate landing of aircrnfts
• Compose music
• Create animated movies
• Play video games, chess. and card games
• Store and retrieve data on land records
• Assist doctors in diagnosing diseases using medical images such as CAT r:,can.s
1
11111111
2 I I 1111d,111w11Ud\ ,,l C'orllf~t•r~
1. 1 ALGORITHMS
In otd,·r lo solw a prnhll'lll u,i11!' a computer, it is necessary to evolve a detailed and . .
',fc"p by ~1e•p 111t·1lmtl ol M,lution. Step-by stl'p methods for solving problems are not ~~ec,se
P•~l' 1d1:11 111 co111p1111·1,, , 'f'ht·y have hccn in use for a very long time and in almost all Wal~ or
Ille. C>n,· such 11wlhmJ, lnkcn from II popular magazine, is given as Example (. (. of
'fllc:, i11slrn\'li1111-: r:ivt·n hi pn 1n.·ss llw inputs art\ lu1wl'\'l't, 110, ,,,,Tis,·. 1'lwy Ut\' nmbiguous.
J·v1 t~u111plt\ 111 Step •I. ,n- :in· t11stnarlrd tn 'b,·at wdl till n smooth und. rrl·amy ballt't i~
oh1n1m·tl' 'l11e i11t,•1p1l'l11tit 111 111' 's111t1,ifh aud t'tt·nmy' l'an v:uy fwm pt'rstin to p,:rson. Owrng
to st1t'h 1111p1t·1.·t!il' iw,t111rti1111s. tlilf1·11·11t flt'IM>11s ti.,111,,, ing till' s:uni.: l'l'ript' with tlw samt' inputs
1.-.111 phidun: 1w111111 li11mf11,; which diflc'r in silt\ sh1tpl'. 1111d tastt•'
\\ (' \\ tll 110w 1..·,.1111iu,• a11111ht•r .'-lt'p by s1q, prnt·1•dt11\, lagain tak\'ll fwm a p\l(Hil,1r
IIU~"/ JIH' ) .
Materials required
Needles No. 12:2, Wool 4 ply: 9 balls.
Method
Step 1: Case on 133 stitches.
Step 2: Repeat Steps 3 and 4, 11 times.
Step 3: Knit 2, * Purl 1, Knit 1, Repeat from * to last stitch, Knit 1.
Step 4: Knit 1, * Purl 1, Knit 1, Repeat from * to End.
····················································································
••••••••••••••u•• ••••••••••••••••• ••••••••••••••••• ••••••••••••••••• •••••••••••••••
(Similar Steps)
Result
A sweater.
' Tht· s,•,111,,,ir,· <!( i11.1·tructio11s specified in the nlgoritlm1 must he precise and un:unbi,.
ln other won.fa. the instructions must not be vague. It must also be possible 1; ~
tht·tn m11 . Fllr ,•xnmpk, tht· instrucrion 'Go to hell ' is precise. but cannot he Cllnied -•i {i)
J . Fnch i11srm,·tii111 m11s1 be snffkkntly basic such tlmt it cnn. in principle. be C3rrie(I OQi. (i i)
hj :1 pc•rson with pnper nnd pencil. ~ (iii)
(iy )
4 . l'lw 11,1.II rim,· Ill c'tlff) ' out nil tht' stt'ps in tht: nlgmithm must he finite. As. :ilgon~
tn;I)' c,1n1nin instrn,·tions 1,, rt'petirivdy cnrry out n group of instruction,-, iliis re-q~
implies th;it thr numlwr 1,f n'p,'tithms must hr finiu.
l V)
:, . ,\n ,11µ<,rithm nmst pm1hl\' t' ,,,w m nmre <l11tpurs (n:1mdy. the re$lllt of prot' essing t..~
t'i)
111p11ts). (, ii)
n.1s,•.f ,,n r\w ''"'" ,, d,•tini!ll,n, ,, t' s,·,· thm th,• n.·.:-i1x· of lhmnpk I. I doe:- not qn:.ilit'\' -:l!-
alr,11 llhm ;I" 1t ,,, m11 pr1.,•is,·. nw 1-.nittin~ pnttrm. ,,11 the ,,thcr hnnd. dt1 l'S qu:tlif~·. • l:.
\\'r ,, tll no\\ ,,, ,,h ,, ,1 .-;1,•p-h) .-;1,•p pn.1c,•dmx· t,, s,,\v,· :\ ,!:it;\ ptxx-e,__~i11g .kh, The r.n.lll~
I!, "' 1111.I tilt' ,I\ ,'t:\tt' 11\11\\h,·1 ,,r \ ,m·,•l.-; 1\,' 1c'\l\111\g in ;\ ~hMt p;1::~;1g,'.
A -:_'nl
Ex•mplo 1.3 Proe1tdur-. to Find the Average Number of Vowels in a Passage -
- .
l N Numh<'r
----
,,t , h.,r.,cr.,,~ 0
- ,'\."ll\ll~\:
ak,,rid
~
.m,\ '-"-"
I
r' II
oil) 11 h,.
uhl,·1 '"
1.. ,, ''" 111 • 1thl1
r, ,~h1111ld 11, 11tld 1111d dlvtd1,.I"' ""' """
I
l 1\ It l 'I I I
l f
1'l11 II 'h/-ltl\Nt I
IINII'
I
l '1 I, ,,1·111 11t,11 II iN jlll'i~ l\,I, 111 ,h I I' "'" 1 111 \'l\lllllhltl • 11111111,, I 1•l ,htt, ,, ·111
'
111 I , ,111111I I 11,II\\,, 'f"llllll 11111 ,111, I l 111\II IIt'
I II 1111 II II '\\ litt ih "''' 1 11( llbltlll ''"''~ lh,~ 1111111,1 I I
i,11, II ,lltlt• f'll "111 ~ I 11 I 11• 11111 II I ,,1,111111, I ' 1•111,' ·,•ol11f1 111111 \I '" I
p11111 !pl, I , ,, ~, d 111 l111tld111p
I 1111 1,11, '"'' I '''" I 1 , ... II'j 1lII II1 ,1111111111 h 11,11111. I\
w 11 ·, Itl I I I Ii 111 111 11 ' ,,
i,
1lh111~ II h 1111,, ibh• 11, I'• 1(,11111 I 1.nr ,'
1
\'111hl 11 1111h,1111'"" •1"111 11 1" " '' 11 '
:.':..-.t:,
_':, 'lb :::::,~ ':t::s-, l.lf .6;., =..:.,:- ~, :::i .?.gc-::±.r;. :-c- ~,·~ u':e J:!Q~Jem is forrnu1~J. fil:'
~_f';,,ri:..:::, ~.:c;:j ~ ~~'~ :-u:::i.:-_'-t ~J ~--r.i::-ig:-~.x:.., B.s...-;ed oo our .1is..,1ssm::,,.. Tc
~-::..~ ~ .::.t"C\!;;!n .z:.__tl~~~.:l::. is .::.."E.:-..tlt ~ ti,o..1-.~~-umim: .
-
.= ~ .::.~:::=i Ii;; : : - ~ ~ j ::. ~ ~.::i...'= Ql~.:c__ ...-\n '!1~"\Ilthm e"\~,""'1 .. 51r~ !
-
;r.:-,t'-!' ::3...-c::::!~ r,; :~~ !l ,"'t...,,...~:....~ ;-r-.. gr.:a Ibe ~ x " ;:-....".U!i:lt.m is -~~e-J '!in~
!,.,.---~~-~
~:, .. - . _ ~~
.:-- "".....,..r
--.i::---..~~
(_j_ ·· tputer ~ai..101, f
We will now consicJ_cr an example ~f formulating a cornpuler algorithm l;l_,1 d writ.t ~ cou,;,t
program corrcsponc.lmg to the algorithm.
1.4.1 Flowchart
Having obtained an algorithm for solving the problem, we express the algorithm in a pictorial
form called a flowchart. The flowchart is primarily used as an aid in formulating and
understanding algorithms. The sequencing of instructions and repetition of groups of instructions
Tu may be quickly seen by inspecting a flowchart. The flowchart for the algorithm of Example I .4
is shown in Figure 1.2.
For easy visual recognition, a standard convention is used in drawing flowchans. In this
0) standard convention, the following shapes are used for various blocks in a flowchart:
(i) Rectangles with rounded ends are used to indicate START and STOP.
(ii) Parallelograms are used to represent input and output operations.
(iii) Diamond-shaped boxes are used to indicate questions asked or conditions tested.
based on whose answers appropriate exits are taken by a procedure. The exits from
the diamond-shaped box are labelled with the answers to the questions.
(iv) Rectangles are used to indicate any processing operation such as storage and
arithmetic.
8 I F1111,l11111r11111h, ,11 l \n11p111c•, ~
I l 'iTAU'I )
""~"MAl<K.S
) _R_o_u_.NO, -)
..-~1~~-
MAXROLLNO IH)LLN<J
3
MAXMARK., ◄- MARK,,
y
4
1/
'
Ye&
5
B.E.Af)
ROLlNO. MP..?.KS
l ;..,;; ~ j ,··:
'
l I th~ 111pu1
ROl I,;-.:()
cont~nh 1
\~ ,:x1
'\
L -l
fi~•
~J
'" :i,!-c-,tl
1h~n th.:-1
:--t,)rCd i
\h.:- pat
~)f t-,,.,,
M \ '\.R
~\
~'I},,,\,\ ,\.. '"'""'''" . ,, ~ ... ~ '\N~ , ,\,~ v~.'>,1 ,~, l'',,~l ,, {'\.<,, U'l',~ th,, "•'-l ,~~
), ,._,,_'\'I.
'\,'\.-._ .. • ..'
,"'\.:.,, -ci'-.~ . -. ,\..."'- ',
, '\. -l:'-
... :, '-I': ') ' ' ~\\\ '"'! ,.
'~ -~'
'•~.,,..,. •' ,..,
" "',,H'-t,
'\,\ · ',..._, ,. U I~ \
'.,. ........._.,. ~•
l"\,o11.tJ~,,,.._
MAXROLLNO ROl l ,O
MAXMARKS
0 450
Figure 1.5 Status of memory bo,es after executing in~tru\·thm~ in b (X" -4 ,md
block 5 of Figure 1.2.
1
Next. block 6 in the flowchart is reached in" hich a quc-,ti0n 'b \I \RkS , \ t \ '\. \ 1 \~1'.S
is asked. This is interpreted ns 'ls the number st0rl.)d in nwmot) t,..), \,1~·!k'\1 \1 \R1'.S ~l\'.\t,•r
tlrnn the number stored in 1\1AXl\1:\RKS'?' Refomng to Figure l.5, "-' ,,.,' th;11 1t\t• •wmt--.•1
stored in MARKS, namely, 78, is greater thnn that stored 111 l\ l.'-\ '\\ l -\RkS, n;uud), :-.:. 1 "'''"·
the path labelled ·Yes· is followed and bl\)Ck 7 is n-ncht·d. which tnst1111:ts th.11 th,· "''tll,•:u,
of box MAXMARKS should be replaced by the Clmlt'nl1' ,)f l\ L\lU;.s an,l th,' '-'\)~*·ut:-. \"'!
MAXROLLNO by the contents 0f ROLLNO. The status of vnlne~ :-.h't\',l 111 mt'llk'l) tx,,l., ,1t
the encl of this step is shown in Figure 1.6.
78 521
t Copy
Figure 1.6 Status oi memory bn,f's ,,ftN t"'\t't 11t1n~ in:-trn1.-111,n:- in bl\'l "-' (, ,,nd ., l)I
figure 1.2.
The path lending out or hll1ck 7 in tht' tl1)\h'hnrt k:1\\s h\\l'K h~ M, 1,·k -l ,,r th,• ,'\I.II t
Executing hlnck 4, we :-:eo that n papt'r is still lt'ft, l-ht','\ltin~ \11\\'k \ th,' m1ml,•1, ~('-I ,,11,t
54 are rend into ROIL.NO nncl l\ tr\R KS, 1<':-p,x•tivc-lv lF\}~lllt' I.?). F'u·,·111111~ M\,'t,, o, ,, ,, s,·,·
lhat 54 ~toretl in MARKS is lt-ss thnn 7~ st111\'\l ln l\lX\~1.\Rk~. \'ln1,, ti\\' ''x,1 ' 11.;1th 1:-. t,1k,•11
oul of hluek 6 and Wt' rt•ad, hlo\'k -L
Jot
MAXMARKS MA\.ROI LNO
, --1 r 5~1
l l
, Wht•u hlnck •I is ~xt•1·11t.·d, wt' s,•1• th111 1w 11\\II\' p,\\'n, Id\ 11, th\' \lll'\\l q\1,'IW.
lit\'
11111 ~, l'Xt•rntion 11f hlol'k ., gtws 'NO' l\S ,11\SW\'I 1111,I \\1' ,~1,d1 h\,"'l.. ~ ,,r th,, n\,\\\-h,\£1
I
J2 Fundarnentab of Compurcrs -----
~
The imtruct ,on ·111 bJ
1
·k 8 comm:m d \ that the contents b · 521MAXROLLNo
h of boxes
b oi.; ' I •d by Ih C Olitput unit. TilUs. t e num ers
and
an. d 78 are Print,.,,
'1J
MAXMARKS arc
After dorng this, to
the e.
mstru
•
pnn c
ction .
rn bJ oc k 9 is reached which stops computation. ·
TI,e model of a compute, we described in Sect;on 1.2 (figure I.I) is h;ghly s;mpJ;fied. It .
used to expJa;n how algorithms are executed by computecs. A ceaJ computer ;s moce eom ~•
It has several Input un;ts. For example, a desktop computer wHJ have a keyboa,d. , mo ve,
scannec, a mkrophone. and a video camera as input un;ts. A compute, also has severa1 m,":·'
units. Apart from the main memory shown in Figure l.J, a compute, has disk storage, CORO~
and removable pen drive. The processing un;t consists of a microprocessor and a numi,,, •
support chips. The computer also has many output units. The most common output unio .,
a video monitor, a printer, and a speaker.
The block diagram of a compute, shown in Fig, l.J ;s that of a 'stand-:done' eomp"'•
Nowadays an isolated single compute, ;s rare. A computer has a Network lnte,fa" corn
(NIC) which connects it to other computers. A computer also has a unit called , 'Oodem ,mo
connects it to the Internet-a worldwide network of computers. A computer not connected to
the Internet cannot use applications such as email, Facebook, Twitter. etc.
The units of a computer we described above constitute what is known as hardwar1·. A
computer is useless unless it has a nurnber of ready-made progrnms to enable easy use of ii._.
hardware. This is provided by software. The 1110,1 ;mportunt software rcquh,d to u,e a'""'"
is what is known as an Operating System (OS). An OS coordinates U1t! uctivitics of ,-ruii;;;
parts of a computer. namely. the CPU. the Input- Output units. and the memoi). It optinu..":<
the use of !he resources of a computer. Bcs;des the OS, it is ttlso ""nti:tl !Or''"'"~'"' LS
have a set of application progGuns. The most ;mporl:tn! applkuHou pt\1grans '""';" ot' '. ' l.6
processor, a program to scnd/recdve email, ont: which systcmntkally Ol'/!UHi11.·s .1uJ .tN'•~ , l.7
. . dala, anti a program lo al'cess thl' World \V1t. {e \Vell,
retnevmg i.. I
n t IIt' 1· llowing, rhap1,·1). .
0 l.8
will describe some of thesl' application programs.
i •llllf\\ll.'T 1\,hl, ~ ) 3
\\,' :-..\\\\\\\\,\\• ,, \hi\\ \h,' \\\,\\\\ p, 111,,, p,,,,,,\\k,I I\\ 1hb ,'h,l\'I, I
,. h, ,\\\k\ ,,, ,,,:\, .\ \'\\'''"'"' "~"'~~ ., '''"'''''"'', \I h 11. •'·''"''f' 11, ~, ,,h ~ .m nlwITTthm
: ' "''~',\\\t~\\\ ,, .\ 11\nh~ ,,\\\'-'''-',' ,,r 1\\,\1\l,'ll,,1" F.vh ln,1t1i.•11,,n ,, pi-', 1,:"1, Ho,nnh1! 11C)11,,
,\\\\\ ,'.\\\~\\t,' ,,t t,,,,11, , \\,h1,\ , 111t t,, ,1 11\.1,•hm,1 111 n h1111, 1 11111,, t\lt\.'\l oh,\Jtthm, X\tll
t\\,, \'~'\\\, ,\\1,\ , 1\\q'III'
,\.. , "''~'\\\,'' ,, ,, \\\{1,hm,, ,, t111'h ,,\,\'\It,•, ,,n t1\~1tw11l11\I \\ 1ill,'n t,, """'"''' ,brn l<',t r<,
, ,"h\ \lh\.\\\, ,,, 1'1,, 1\'1\\ .i ,,1,\1\\, 1 ,,,
"- , ,, ,,~\,\\\\h\'\\ ,, ,,, 1,1, "•',\ 1\1 1\ ~•h1ph11-.1\ "'"" l-.11,," n U'\ n 11<)\\,h,m , 11,,,,. h.m "
\\: \ ,t, ,,,,L,, \\\ ,.1,I \\ll,kl,\\1\1,\h~\ ,,, \llf,'1\lhll\\,
~ \ \ ,~\,m\\\\\\~~ \,\\~l_\\,\f,' '" ,, ,,,,.,,1,,' n,,t,\h,\\\ H,,•,1 t,\ ,'\l'h',, .,1~',\fitl11n, J\n .1lr,wuhn,
,,., ,,,,,,\ 1\\ ,, \\\1~\h\\\\\m\~\ h1\\~1ms,1 , , ,\1ll,-.t n ,·,,111p11h'1 l''''Jlh'"'
"' \ ,,"\~~\t,'\ i, ,t,,~}\\,',\ \\''"il t~''" h'\,h' ,'l\.1bl, 1 ,t "' 1w,'-\',, ,l!lt.1 It h;1, ,,n
1111ib "'
- -.: \\ \\,,-~ ,'-'•'-'\'\\ th,' ,\m., m1,\ \h, \ ' " ' } ~ " ' ' " h' l'"'' •'" ,11,,
1
lt ,t,\t-', tlh·,.- ,b,.,
.\ ,\ \~,., p1,,t1t1\\1 \\'\\ 11•, ,' ,\ tt\''" lhi' n1,'m,11, 11n11 ,, ml,'fl'h'li",I ~n,1
""'"'\' .,,\ h\ ,i J' , , , " ~ ttm), \'h,' , ,1,,1\1, ,,(' ,. ._ ,111,,1,1:1t11 ,11 ,11 ,• ,t.w,·,t rn m,'m,\\, .in,t
, "'\ \h\\\~ ,\\\ I
~ \,\ ,'~ , , .\, ''"'l'llh'I ;II\' 1t, ,,,•,\\, ·'-"'"""'', ,,·1,,111\11, ,., ,,.,1,"'""
,\l ~~, ,\\\.' \''\')::.1,11n ,'\,\ n1i,,n \\ 11\\,,,11 \111"'·'" 11\t.'\\ ,·1111,m, :\n,I ,'Jl); ,,,,~
., \ ,'\_\,\\'~''\•,II\,' ,,h, h'lll\lh'l\ ,\1\\ 1\n\\\l1,'\ ,,t 11\ll,',
•. "•'" ,·•~' "·' '"':1:~'1:1,'\' ,, ~,,,t\t,'d \ \''"''""''~ ,\\\' ,,,,,111~,-,.,.,, ,_, ,11\1.:-1 ,~,\l\\pnl,'1' \\'-H'S;
~ ~"i\\,._., m ..>-t1~,'\" ,'~1,\ .111,l 11, Ill,' \1\h'\'\\,'1 111-11~ ,\ 11\\h\.'m.
-- - - - -
' '
'
' '
--- L - -
l.t i\..~ ,~:t -~ l',","-l'" l\\\l\\ :\ \'-'!'\\\.\\' m:~.,,11,,' ~,1.1 ,'\\'l\'" u m :, ,i--1' 1,, , ..,, l\t,,,..,t1, .,,
~\ ,'\ \'f\'-',',~\\\"' ~\\,'I\ l\\1 .\ \\'\'I\'' 11\ ,\ ,,~,I. I\\',\.\.. U\~ 1h'I I," ~,•~,'\} fil)
l..S \\~
" ..1 ~-'~r-...1mt,\\~ kt\\~"-~'-'''
.. \\ \ .., " .:l. ,'\~,~~•"l f't\\~f,\\\\'\
l.' ~
• ~'.\I, ... ~ .,i.. ,t,~~1~m ,,, {\ ,'l\t\'ll\\t,'f \•\.phnn th,' nm,'\\,\\\ ,,t ,~'l\ ,,, th-' N,,\..,
~~ it'!..~-~ • ~ .. ~ r,t\"-"'i.,tnw t,, hn,t th,, h\,,~h.-,, n\.\tl-., ,~\\,m'I-.,\ ,,, ,, "'""' '"''\ t\ \t I\,
:-;.: ~ :\'I\\~ l'l\l,~, -~t.l\\'tt";.l
l.<11 ~~ ~ ~ \'4\,~u"" ,,1 \',.m\f,l." \ 4 "''"'''th-',\\,'\,'}"' \\1A1\-, ,\t "- ,·'~"