computer science textbook

16
PEARSON CUSTOM SOIVI PUTER SCI ENCE Introduction to Computer Science csct 127 Pearson Learn ing Solutions New York Boston San Francisco London Toronto Sydney Tokyo Singapore Madrid Mexico City Munich Paris Cape Town Hong Kong Montreal

Upload: samson-fung

Post on 27-Oct-2015

126 views

Category:

Documents


20 download

TRANSCRIPT

Page 1: Computer Science Textbook

PEARSON CUSTOM

SOIVI PUTER SCI ENCEIntroduction to Computer Science

csct 127

Pearson Learn ing Solutions

New York Boston San Francisco

London Toronto Sydney Tokyo Singapore MadridMexico City Munich Paris Cape Town Hong Kong Montreal

Page 2: Computer Science Textbook

Senior Vice President, Editotial and Marketing: Patrick F. BolesExecutiae Marketing Manager: Nathan WilburSenior Acquisition Editor: Debbie ConiglicrD ea e I o p ment E dit o r : Annette FantasiaE dito i al As sist ant : J eanne Ma rtinOperations Manager: Eric M. KenneyPrcduction Manager: Jennifer BerryArt Director: Ren6e SartellCoaer Designer: Kristen Kiley

Coz,er Art: "Blend," courtesy of Getty Images/Jason Reed; "Binary Data Flcxving," courtesy ofiSkrckphoto/Andrev Solovyev; "Beech Forest," courtesy of iStockphoto; "Small Plant," courtesy ofiSkrckphoto/Fkrrea Marius Catalin; "Netrvork," courtesv of iSkrckphoto,/Andrev Prokhorov.

Copyright O 2011 bv Pearson Learning SolutionsAll riehts resen'ed.

Permission in rvriting must be obtained from the publisher before anv part of this work may be reproduced or transmitted inanv form or by any means, electronic ()r mechanical, including photticopying and recording, or by any information storage orretrieval svstem.

Printecl in the United States of America.

Please visit trur tveb site at it)r{'i{,.llr'tt rsL) tl c t t s to n t. a() t I I

Attention Btrtrkstores: For permissit)n t() return anv unsold stock, contact us;rt;r, ils:ust()ntrcttu'ns'<!p(Ltrs()n.L'()nr.

['earson Learning So]utions, 501

A Pearson Education Company!v rv\l''.pearsoned.com

Boylskrn Street, Suite 900, Boston, \4A 02116

lSBN 10:1'256-18594-9ISBN 1 3: 978-1-256-18594-9

Page 3: Computer Science Textbook

Importont Informotion Regordlng SupplementolMoteriols for Your Book

Your custom book comes with additional student resources, designed to aid you, including source code, develop-ment environments, etc. These materials are available to you via the following website, searchable bv author lastname and title:

http ://www.pearsonhi ghered.com,/cs_custom

Before completing a project, it is sometimes necessary to download and open data files. These files provide thestarting point for the project and the data with which to work. Check with your instructor for the best way todownload these files, or use the following instructions.

Downlooding Procedures for the Stuclent Doto FiIes in the PeorsonCustom Publishing Progrqm 1n Computer Science

l. From an open Web browser go to: http://www.pearsonhighered.com/cs_custom. Note: You may want tobookmark the appropriate page. as it contains links to additional products that you may be using in class.

2. Click on the appropriate title of your Computer Science text. This is where you will find all of the datafiles to complete the projects.

3. Because you have a Custom book, the chapter references in these data files may not rnatch up with thechapter order in your book. This can be solved by browsing through the posted folders and rnatching thefile name to the appropriate topic covered in your book.

4. When you find the frle that you need, you may open it to view the file immediately, or you may save thefile to a specific location on you hard drive. We recommend saving the files to your desktop to frnd themeasily.

Any resources not fbund on http://www.pearsonhighered.conVcs_custom can be found at www.mycodemate.com.

t'lyCodet'1ote ffiffiMyCodeMate is a book-specific Web resource that provides tutorial help and evaluation of student programs. In addi-tion to Student Data Files, your book may reference specific programs available through the www.mycodemate.comwebsite. If your professor ordered an access card to accompany your book, you have access to the materialsavailable through MyCodeMate. If you do not have an access card, you can purchase a subscription online atwww.mycodemate.com.

The additional student resources through http://rvww.pearsonhighered.con-/cs_custom and www.mycodemate.comare provided to assist you in learning and practicing the concepts covered in your Custorn book. When theseresources are mentioned in a chapter, please refer back to these instructions to access and download the coffectcontent.

Page 4: Computer Science Textbook
Page 5: Computer Science Textbook

Contents

1 Introduction,1. Glenn Brook.shear I

2 Data Storage,J. Glenn Brcok.sheor i g

3 Oata ManipulationJ. Glenn Brook.shcur 79

4 Operating SystemsJ. Glenn Brookshear iig

5 Networking and the InternetJ. Glenn Brookshear

6 AlgorithmsJ.GlcnnBrooksheur ....20j

7 Programming Languages.J. Glettn Brookshear 257

8 Rrtificial IntelligenceJ. Glenn Brookshear 319

$ Appendix: ASCIIJ.GlennBrcok.shear ....371

10 nppendix: circuits to Manipulate Two's complement RepresentationsJ.GlennBrook.sheur ....323

11 Appendix: A Simple Machine LanguageJ.GlennBrooksheor ....377

12 Appendix: High-Level Programming LanguagesJ.GlennBrookshear ....37913 Rppendix: The Equivalence of Iterative and Recursive StructuresJ.GlennBrookshear ....381

14 Introduction to Computers and Programming

1 E,4

Tonv Gaddis 383

Page 6: Computer Science Textbook

15 Introduction to C++Tont-Gaddis ....413

16 Expressions and InteractivityTont,Gaddis ....47517 Making DecisionsTonvGaddis .... S4S

18 Loops and FilesTonyGaddis ....629

19 FunctionsTbry,Gaddis ....70520 ArraysTonyGaddis ....7BsIndex 863

Page 7: Computer Science Textbook

Introduction

In this chapter we consider the scope of computer science, develop

a historicalperspective, and establish a foundation from which

to launch our study.

1 The Role of A{gorithms 3 The science 5 An outline of

? The Histsrv of ,{tgorithms our Study

of {ornputing 4 Abstraction 6 sscial Repercussicns

From Chapte r 0 of ContptLter Scietice: Ai1 OL,el r'ieu,, Eler.enth Edition, J. Glenn Brookshear. Copvrieht @'2012bv Pearson Ldr-tcation, lnc. Pubhshcd bv pearson Aclclison-\Vesler,. All rights reserved.

Page 8: Computer Science Textbook

I ntroduction

Computer science is the discipline that seeks to build a scientific foundation forsuch topics as computer design, computer programming, informauon process-ing, algorithmic solutlons of problems, and the algorithmic process itseli. It pro_vides the underpinnings for today's computer applications as well as thefbu ndations for tomorrolr''s com puting in frastructure.

This text provides a comprehensive introduction to this science. we willinvestigate a wide range of topics includlng most of those that constitute a typi_ca1 university computer science curriculum. we \4/ant to appreciate the ful1 sctpeand dynamics of the field. Thus, ln addition to the topics themselves, n'e will Leinterested in their historical development, the current state of research, andprospects fbr the future. Our goal is to establish a functional understanding ofcomputer scienr;e-one that u'ill support those who rn'ish to pursue more special-ized studies in the science as u'ell as one that u'ill enable thosi: in other fields toflourish in an increasingly technical sctciety.

1 The Rote of Algorithmswc begin with the most fundamental concept of computer scjence-that of analgorithm. Infbrmally, an algorithm is a set of steps thar clefrnes how a task isperformed. For example, there are algorithms for cooking (ca11eri recipes), forfinding your \l/ay through a srranse city lmore r;ommonly called directilnsl, ftrroperating rvashing machines (usr-ra1lr. displayr:d on the insicle of the n,ashcr,s liclor perhaps on the lr'all of a laundromat), fbr playing rnusic (expressecl in thefbrm of sheet music), and fbr perfbrn-rinu magic tricks (Figure 1.1.

Betore a machine such as a computer can perfbrrn a task, an algorithm fbrperforming that task must be discovered ancl reprt:sentecl in a form that is cont-patible n'ith the machine. A representation of an algorithm is called a program.Ior the convenienr:e of humans, compurer programs are usually printerl onpape r or displaycd on colxputer screens. Ful the convenience of machines, pro-grams arc encoded ln a manner corrpatible r.r'ith thet technology of the machine.'1-hc process of developin.g a prr)qrJnt, ct.rr.oding it in machine<;ompatible form,and ir-rst:rting it into a machine is callcd programming. proerams, and thc algo-rithn-rs tht:y reprcsetnt, are collcctiveil' refi:rred to as software, in contrast to then.rachine rV itself, r,vhich is knotvn as hardware.

The studv of algorithms began as a snb.ject in mathcrnatir;s. Inclecd, thgsearch fbl algorithms was a slgnificant activlt\/ of'mathematicians long be forethe dr:velopment of'toclar.'s colnpLlters. -fhe goal \\,as to finc1 a single set of'clirec-tions that described hor,r' a1l problerns of a partit;u1ar type could be scllved. one ofthe berst knor.r'n exanples of this edrlr,r 1ss6'2.ch is the long division algorithrn fbrfinding the quotient of tu'o multiple-digit numbers. Another example is theEur;lidt:an algorithm, discovered bv the ancient (ireek nlathenlatician lruclicl, fbrfinding the greatest co1r1r11on divisor of ilr'o positivr: integers (F igure 2).

Once an algorithm for pcrformine a task has bee n fcrnnd, the pe rfbrmance <tfthat task no longer requiles an nnderstanding of the prir-rciples on r,r'hich thealgt)rithm is based. Instead, the performance of the task is recluced to the processof merel\' fbllorving dir"ections. (\4Ie can foliorv the long division algorithm to finda cluotient or the Euclidean algoritl-n'n to frnd a greatest comnton divisor withoutunderstandlng r,r'hr, the algorithm u'orks.) In a sense, the intelligence required tosolve the problem at hand is encocled ir-r the algorithrr.

Page 9: Computer Science Textbook

I ntroduction

Figure 1 An algorithm for a magic trick

Effect: The performer places some cards from a normal deck of playing cards facedown on a table and mixes them thoroughly while spreading them out on the table.Then, as the audience requests either red or black cards, the performer turns over cardsofthe requested color.

Secret and Patter:

Step 1 . From a normal deck of cards, select ten red cards and ten black cards. Deal these cardsface up in two piles on the table according to color.

Step 2. Announce that you have selected some red cards and some black cards.

Step 3. Pick up the red cards. Under the pretense of aligning them into a small deck, hold themface down in your left hand and, with the thumb and first finger of your right hand, pullback on each end ofthe deck so that each card is given a slightly backwardcurve. Thenplacethedeckof redcardsfacedownonthetableasyousav, "Herearetheredcardsin this stack."

Step 4. Pick up the black cards. In a manner similar to that in step 3, give these cards a slightforward curve. Then return these cards to the table in a face-down deck as you say,"And here are the black cards in this stack. "

Step 5. lmmediately after returning the black cards to the table, use both hands to mrx the redand black cards (still face down) as you spread them out on the tabletop. Explain thatyou are thoroughy mixing the cards.

Step 6. As long as there are face-down cards on the table, repeatedlvexecute the following steps:

6.1. Ask the audience to request either a red or a black card.

6.2. lf the color requested is red and there is a face-down card with a concaveappearance, turn over such a card while saying, ,,Here is a red card."

6.3. lf the color requested is black and there is a face-down card with a convexappearance, turn over such a card while saying, ,,Here is a black card.,,

6.4. Otherwise, state that there are no more cards of the requested color and turn overthe remaining cards to prove your claim.

Figure 2 The Euclideanpositive integers

atgorithm for finding the greatest common divisor of two

J

Description: This algorithm assumes that its input consists of two positive inregers anoproceeds to compute the greatest common divisor of these two values.

Procedure:

Step '1. Assign M and N the value of the larger and smaller of the two input values, respectively.

Step 2. Divide M by N, and callthe remainder R.

step 3. lf R is not 0, then assign M the value of N, assign N the value of R, and return to step 2;otherwise, the greatest common divisor is the value currently assigned to N.

Page 10: Computer Science Textbook

Introduction

It is through this ability to capture and convey intellige nce (or at least intel-ligent behavior) by means of algorithms that rve are able to build machines thatperform useful tasks. consequentry, the leve1 of intelligence displayed bymachines is limited by the intelligence that can be conveyedlhrough algorithms.we can construct a machine to perform a task only if an algorithm exists for per-forming that task. In turn, if no algorithm exists for solving a problem, then thesolution of that problem lies be'onc1 the capabilities of -u"hirr"r.Identifying the limitations of algorithmic capabilities solidified as a subjectin mathematics in the lg3Os u'ith the publlcation of Kurt G6del's incompletenesstheorem. This thr:.rem essentiallr, states that in any mathematical theoryencompassing our traditional arithmetic system, there are statements u,hosetruth or falseness cannot be establisheci b5, algorithmic means. In short. anvcomplete study of our arithmetic svstem lies beyond the capabilitie s of algorith-mic activities.

This realization shook the foundations of mathematics, and the stucly of algo_rithmic capabilities that ensuecl rr.as the beginning of the fleicl known-t1-1c1ay'ascomputer scienr;e. Indeed, it is the studv of'algorithms that firrms the r;ore ofcomputer science.

2 The Historyof Computing'Irlday's computers have an extcnsivt: gi:nealogv. One of the earlicr cemputin.qdevir;es n'as the abacus. I Iistory tells us that it most likely hacl its roots in ancienrChina and was used in the early Cireek ancl Roman civilizations. 'l'he mar;hins iscluite simple, r;onsisting of beads strung on rocls that are in turn mclunted in aroctancular frame (l igure 3). As the bcacls are movccl back and firrth 9n thertlds, their positions represent storecl values. It is in thet positions 9f the bgaclsthat this "conlputer" reprosents:tncl stores clata. For control of'an algorithm's exe-cution, the machine reliers on the hur-n:rn operator. Thus the abacus algr-rt: isI1lclrol,v a data storatgtt s\rstelr; it nrLrst bc cornblnetcl r,r'ith a human to create ;lcomplete computational ntar;hine.

In the tlme period atter the Nliddle Agcs ancl betfore the Mocleln Era thc clucstfbr more sophisticated computinq mar;hines u'as seeded. A f-eu, inventors beganlo expcrimt:nt n'ith tl-tc technolog], of gears. Among these r,r.ere Blaisc pascal( 1623- 1 6{i2) ot I.r'ance, (}ottfried \\rilhelm Leibniz (r 646- 1 716) of (ierm;rny, and(,1'rarlcs lSabbage Q79'2-187r) of Er-rslancl 'lhesc machines representecl datathrough ge ar positioning, u'ith data beins input mechanically by establishing ini-tial gear positions. output fr^om pascal's and Leibniz's machines was achieved bvobserving the final gear positions. Babbage, on the other hand, envisionedmachines that u'oulr.l prirtt resr-rlts clf computatjcrns or.r papcr so that the possibil-ity of transcription errors r,vould be elininated.

As for the abi1it5, to follou. an algorithm, \\/e can see a progression of f1exibi1it1,in these machinr:s. Pascal's macl'rine u'as built to perform only acldition.Consequently, the appropriate sequence ot steps r,r'as embeclded into the structureof the machine itselt-. In a sin-rllar manr-]e1, Leibniz's mar:hine haci its algorlthmsfirmly embedded ir-r its architecture, althor-rgh it offered a variety of arithmeticoperations from rt'hich the operator could select. Babbage,s DifTerence Engine (ofu,hich on1\' s demonstration model \\'as constructecl) could be modified to performa variety of calculatictns, but his Analt.tical Er-rgine (the construction for lr4tich he

Page 11: Computer Science Textbook

I ntroduction

Figure 3 An abacus (photography by Wayne Chandter)

"An abacus ". O Wavne Chandler.

never received funding) n'as designed to read instrur.tions in the f9r1r of holes inpaper crards. 'fhus Babbager's Analvtical I-ngine \\/as prosralln;rblt:. In fact,Augusta Ada Byron (Ada Lovelace), rvho publishecl a paper in u,hich she demon-strated hor'r' L3abbagc's Analytical l-nginc could br: programnreci to pcrflrln varir-ruscomputations, is often identificd toda\r as thc rrorlcl's flrst pr-9grarir-16r.

lhc idc.r ol con)ntunicatin!, arr llg,,r iLltrrr vi,r holr:s'i rr p;p,,1 rr..rs not orr!,i-nated by Babbage. He got the idt:;r fi'om Joseph Jacqr-rard (\75'2-ItJ-t4), who, in1801 , had developed a r,r'eaving loom in n'hich the steps to bc pcrfbrmed cluringthe r'veaving process r,r'ere determined bv patterns of hole s in large thick cardsmacle of r'r'oocl (or carrlboarcl;. In this rnanner, tl-rc algorithm follou,ecl by the loomcould be changed easily to procluce differe nt \\/oven clesigns. Another be ne ficiaryof Jacquard's idea rvas IIt:rman Hollcrith (1gtiO-1929), rr,ho applied the concept 9frepresenting infbrmation as holt:s in papt:r cards to specd gp the tabulationprocess in the 1890 li.S. cetnsus. flt was this,,r.orkbv Hollerith that lecl to thc cre-atiorl of iBM.) Such cards ultirnately carne to be knorr,n as punchecl carcls ancl sur-vived as a popular means of conmunicaring rvith cornputers u,ell lnto the 1970s.Indeed, thc technique lives on todav, as r,r'itnesseci b), the voting issues raised inthe 2000 tJ.S. presidential electiolt.

The technology of the time tvas unable to prodnce the corlplex gear-clrivennachines of Pascai, Leibniz, and Babbage in a flnanciallv feasible manner. Butlvith the advances in electronics in the early 1900s, this barrier \,ras overcome.Examples of this progress include the electr"omechanical machine of GeorgeStibitz, completed in 1940 at Bel1 Lallorarories, ancl rire N,lark I, completecl in lg44

Page 12: Computer Science Textbook

Introduction

Difference Engine

:i;fr?$Ttr$":lr$:h:r'H1-,Tffi ,:il-,'#il:ir':ffiffi:',;ff i:fnomically basible manner ana lrtte oata processing dernands of commerce and ssv.ernment had been on thC scate of today's requirements, Babbage's ia"as couta tiaueIed to a computer revolution in the 1go0s. As it was, only a demonstratlon model ofhis Difference Engine was constructed in his iifetime. This machine deterrnined"numerical values by computing.successlw differences." We can gain an insicht tothis technique by considednfthe problem of computing the squares of the intJce;.we begin with the knowledge that the square of 0 is 0, the square or r ii rltnesquare of 2 is 4, and the squarc of 3 is 9. with this, we can determine the souare of 4in the following manner (see the foflowing diagram). we first compute tire differ.encesof thesguareswealre'adyknow:12 -02 = 1,22 - !2:3,and32 _22 = 5.Then we compute the differenc€s ofthese results: 3 - 1 = 2, and 5 - 3 = 2. Notethat these differences are both 2. Assuming that this consistency continues (mathe-matics can show that it does) we conclude that the difference between the value{4' - i? and the value g^2 - 22} must also- be 2. Hence (42 - 3\ rnust be 2 greaterthan (32 - 2),so 42 * j2 = z and thus 42 = 32 + 7 = l6.Nowthatwe know thesquare of 4, we could continue our procedure to compute the square of 5 based on thevalues of 12,22,3t, and 42. (Althoustr a more in-depth discussion of successive differ.ences is beyond the scope of our current study, students of calculus may wish toobserve that the preceding example is based on the fact that the derivative of y : ,, isa stralght line with a slope of 2.)

0

7

2

3

4

5

0

1

4

9

ffi +-- "ffi -ffi-ffi

at llarvar:d LJniversitv br. Ilon.ar-d r\iken and a group of IBM r:ngineers (figure 4).These machines made heavv use of electlonicalh, controlled mechanical ri:1ays. Inthis sense thev n'ere obsolete alnost as soon as thr:y u'ere built, because otherresearchers rvere apph'ing the technokrgr. of vacuum tubes to construct totallyelectronic computers. The flrst of'these machines u,as apparentlSr 11-r" AtanasofflBerry machine, constructed durins the perlod fl'om 1937 to 1941 at lo$'a stateCollege (nou' Ion'a State I-Iniversitr') b1, John .,\tanasoff and his assistant, Clif1brdBerry. Another u'as a machlne called Colossus, built under the clirecticln of Tommrr

Page 13: Computer Science Textbook

Introduction

Figure 4 The Mark I computer (courtesy of rBM archives. unauthorized use is nor permitted.)

"The Mark I computer." Courtesy of IBM corporate archives. Unauthorized use is notoermitted.

lilrlu'ers in England to decodc (ierman messagcs cluring rhe lattcr part of Worldwar II. (Actually, as many as ten of these machines \^/ere apparently built, but mil-Itary se(lrecy and issues of national securitr,' kept their existence from becomingpart of the "computer fami11, trec.,') Othr:r, ntorc flexiblc ntachincs, sur;h as theENIAC (elcctronic numerical intcgrator ancl cak;ulator) dt:veloped b5, .lohnMauc;hlv and ,1. Prespcr Eckrtrt at tl.re Nloorr: School of Elt:ctrical Enginecring,IInivcrsity of l,ennsyivania, sor_rr-t fit]ktn,etd.

lrom that point on, the history, of cotrputing rnachines has bt:en closelylinktld to advantllng tcchnolosv, includir-rg the ir-rvr:ntion of'transistrlrs (for lr,hichpht,sicists William Shclcklel', John l3arcleen, and \Aralter Brattain r.r,cre an,arclecl aNobel l']rize) and the subsi:quent cle velopme nt of complete circuits constructe clas singie units, ca1led integrated circuits (for n,hich .Iack Ki1b1, also won a NobelPlrizr: rn physics). with thesc devclopmenrs, the room-sizt:d machlncs of theI940s u,ere rcduct:d ovcr the der;ades to thc size of singlc r_abine ts. At the samt:timt:, thc procr:ssine power of computing machincs began to clouble every twoycars (a trend that has continued to this day). As u'ork on integratecl circuitryprogresst:ci, manv of thg circuits rvitirin it colltputer became reaclily available onthe open market as integrated circuits encased in to\,-sizecl blocks of plasticcalled chips.

A rrrajor step to\^iard popularizing colnpltting rvas the developrnent of desk-top computers. The origins of these machines can be tracecl to the computer hob-byists u'ho built homemade computers from combinations of chips. It n,as withinthis "underground" of hobby activitv that Steve Jobs and Stepl.ien wozniak built aconrmercially viable home computer and, in 1g76, establishecl Apple computer,Inc. (norv Apple Inc.) to manufactnre ancl market their- proclucts. other compa,nles that nlarketed similar products u'ere Comn-Ioclore, Heathkit, ancl RadicrShack. Although these products \\rere populal amons conlpurer hobbvisls, thsy

Page 14: Computer Science Textbook

Introduction

.'

ffi ffi :^.[iffi $STl"S$"i{!:,"',::r':Tffi':r#';.:r(1815-1852) that was mmpticated by poor health and ttre iact tt ai str* uftls a non4conformist in a society that timited ihe professionat role of women. ntthoush stt* *"r t

inter€sted in a wide range of science, she concentrated her studi;iin rnath€rnaUii.Her interest in "compute scienceo began when the becarne iis.inaieo bv ttuemachines of charles Babbage at a demonstration of a prototype of tris nir*r*n."En$ne in 1833. Her contribution to computer science stems frorn trer transtaff;;:ftom French into Engtish of a paper discussing Babbage's desiens for the AnatwiealEngine. To this translation, Babbage encouraged her to aitach an addenJum oeiciir-ing applications of the engine and containing examples of how the engine coula beprogrammed to perform various tasks. Babbage's enthusiasm for Ada Byront workwas apparently motivated by his hope that its publication would lead io financialbacking for the construction of his Analytical Engine. (As the daughter of Lord Bvron.Ada Byron held celebrity status with potentially significant financial connections.jThis backing never materialized, but Ada Byront addendum has survived and is con-sidered to contain the first examples of computer programs. The degree to whichBabbage influenced Ada Byronb work is debated by historians. some arsue thatBabbage made major contributions whereas others contend that he was mire of anobstacle than an aid. Nonetheless, Augusta Ada Byron is recognized today as theworldt first programmer, a status that was certified by the u.s. Deoartm.nt oiDefense when it named a prominent programming language (Ada) in heihonor.

\^/cre not n'idelt' acceptcci b]' the busiltess r;omt-nunity, lvhich continuecl to lookto the r'r'e1l-esmblished IBN{ fbr the majoritv of its computing neecls.

In l98l,lBM introdr-rr;ed lts first desktop corxputer, calkrcl thi: personal com-pute r, or PC, n'hose undi:rlyine sofru'arc u'as dcvelopecl by a newly fbrmed r;om-pany kno$'n as Microsoft. The PCI rr,as alr instaltt succcss ancl legitimized thedesktop clomputer as an establishecl comr-noclitv in the mincls of'the businesscommunity 'lodat,, thc term P(,' is n,idely used to refi:r to all those machines(from various tnanufacture lsl n'1.rosc clesign has evolr,ecl fiom IllM,s initial clesk-top computer, most of lvhir;h continue to be marketed with sclftr.r,are fromMicrosoft. At times, horvever, the term 1,c is useci interchangeably with thcgeneric terms deskrqt or laptop.

As the tr't'entieth centur\r dre\\' to a clctse, the ability to connect indiviclualcomputers in a worlcl-n'ide svste m ca1led the Internet r,r'as revolutionizing curn-nlunicatiot-l. In this context, Iim Berners-Lee (a Britisl-r scientist) proposecl a sys-tenl by r'vhich documents stored o1-] compurels throughout the lnternet could belinked together producing a nlaze of linked information callecl the World Wideweb (often shortened to "web"). Tb make thc information on the web accessible,softr,r'are svstems, called search engines, u'ere developed to ,,sift through,, the\A/eb, "categorize" their t-indines, and ther-r use the resuits to assist users research-ing particular ropics. Major plavers in this fjeld are Google, yahoo, and Microsoft.'Ihese companies contitrue to expanci their \4reb-related activities, often in clirec-tions that challenge our traditional rr.a\, of thinking.

Page 15: Computer Science Textbook

I ntroduction

At the same time that desktop computers (and the ne\\/er mobile laptopcomputers) were being accepted and used in homes, the miniaturization ofcomputing machines continued. Today tinl' computers are embedded withinvarious devices. For example, automobiles no\.\, contain smal1 computers run-nine. Clobal Positioning Systerns 1CPS1. rnoniroling rhe function of the engine,and providing voice command serwices for controlling the car's audlo and phonecommunication systems.

Perhaps the most potentiallv revolutionary application of computer miniatur-ization is found in the expanding capabilities of portable telephones. Indeed, whatn'as recentiy merely a telephone has evolved into a small hand-held general-purpose computer knon'n as a smartphone on u'hich telephony is only clne ofmany applications. -I'hese "phones" are equipped lvith a rich arra1, of scnsorsand interfaces includins cameras, microphones, compasses, touch screens,accelerometers (to detect the phone's orientation and mclticln), and a number ofu'ireless tcchnologies to communicate n'ith other smartphones and computers.'I'he potential is enormous. Indeed, manv argue that the smartphone u'ill have aqrc:rtcrr effect on societv thar-r the I)(1.

'l'he rniniaturization of computers and their expanding capabilities havebrought computer technitlclgv to the forefiont of todar,,'s societv. (.t.rmputer tcch-nttlogy is so prevalent no\l' that tamiliaritv u'iti-r it is fundamental to being a

membcr of modt:rn society. Computing ter;hnologv has altered the ability ofgovernments to exert <;ontrol;had enormous impact on global economir;s; led tcr

startling advances in sr;ientifrr: research; r'evolutionized the role of data collec-tion, storase, and applications; provided ne\\, means fbr people to communicateand interact; and has repeatedlv challengecl societv's status quo. 'l'he result is aprcllif'eration of subjects surxrunding conlputer sc.it:nce, t:acl-r of lvhich is now asignificant fleld of study in its or,r'n right. Moreover, as rvith mech:rnical engi-t-iet:ritrg and ph5rsi6s, it js often djfllcult to dral' a line be6,r'een rhose fjelds and

Google

Founded in 1998, Google Inc. has become one of the worldb most recoginzed techol-ogy companies. lts core seruice, the Google search engine, is used by millions of peo-ple to find documents on the World Wide Web. In addition, Google provideselectronic mail service (calted Gmail), an Internet based video sharing service (catledYouTube), and a host of other Internet services (including Google Maps, GoogleCalendar,Google Earth, Google Books, and Google Translate).

However, in addition to being a prime example of the entrepreneuriat spirit,Google also provides examples of how expanding technology is challenging soci-ety. For example, Google! search engine has led to questions regarding the extentto which an international company should comply with the wishes of individualgovernments; YouTube has raised questions regarding the extent to which a com-pany should be tiabte for information that others distribute through its services aswell as the degree to which the company can claim ownership of that information;Google Books has generated concerns regarding the scope and limitations ofinlelectu,a! property rights; and Google Maps has been accused of violatingprivacy rights.

Page 16: Computer Science Textbook

Introduction

computer science ltself. Thus, to gain a proper perspective, our study will notonly cover topics central to the core of computer science but will also explore avariety of disciplines dealing r,r'ith both applications and consequences of thescience. Indeed, an introduction to computer science is an interclisciolinarvu nde rra kins

3 The Science of AlgorithmsConditions such as limited data storage capabilities and intricate, time-consumingprogramming procedures restricted the complexity of the algorithms utilizecl inearlv computing machines. Hon'ever, as these limitations began to disappear,machines tvere applied to increasingly larger ancl more complex tasks. Asattempts to exprcss the composjtion of thesr: tasks in algorithmic form began totax the abilities of the human mlnd, more ancl more research efforts weredirected ton'ard the study of algorithms and the pr.gramming process.

It \'\'as in this context that the theclrt:tical n'ork of mathematicians began topay dividencls. As :l consecllrence of (;ddel's incompleteness thcprem, rnathe-maticians had alreadv been investigating thosc questions regarcling al.qorithmicprocoss€ls that advancing technolosy \\/as nou, raising. with that, the stage wasset fbr the emergenr-e of a nerv cliscipline knou,n as cotllpLtter scienrr;.

'loday, compute r science has established itself as the science of algorithms. 'l-he

scope of this science is broad, drarving fi"om such diverse subjects as mathematics,engineering, psycho1og1,, biology, business adrninistration, and linguistics. Indet:cl,researchcrs in differcnt branches of r;omputer sr;ience may have vcry distinct clefi-niticlns rlf the science. l-or cxantplt:, ii researchcr in the field of computer architec-tllre mav fircus ot-t the task of miniaturizing circuitrv and thus vicu, (tomputersciencc as thet advancement and application of'ter;hnology. l3ut, a researcher in thefreld of database systems ma\r see conrputor scie nce as sceking u,ays to make infor-matioll systems more useful..'\nd, a researcher in the field of'artiflcial intclligcnr:emay relgard (lompllter sr:icnct: as the studv of intellieetnce ancl intellieent behavirtr.'lhus, an intrttduction to conlputer scienct: nrust inclr-rde a varicty o1'topir;s.In each case, our goal u'ill bc to introduce the ce ntral idcas in thc subject, thc:current topics of rese arch, and some of tl-re techniques being appliecl to aclvanceknon'le dge in the area. With such a varietl, of topics, it is eas5r to losr: track of theoverall picture. we therefbre pause to collect orlr thoughts by identifying somcquestions that provide a focus for its studv.

r Which problems can be solved by algorithmic processes?r FIon' can the cliscoverv of algorithn.rs be made easier?r How can the technlques of representir-rg and communicating algorithms

be improved,'r IIou' can the characteristics of diflerr.nt ;lqnrithms hc "naTyzed

and compared?. How can aleorithms be used to manipulate information?r Ilolr' can algorithms be applied to produce intelligent behavior?r llou'does the application of algotithn-rs affect society?

Note that the theme conlmon to all these questions is the study ot'algorithms(Figure 5).

10