Introduction to Computer ScienceCSCI109
AndrewGoodneySpring2018
Lecture1:IntroductionAugust20,2018
China– Tianhe-2
Purpose of this Course
u Introducecomputerscienceasadiscipline,abodyofknowledge,andadomainofscience/engineeringv Thefocusisonideasandconceptsv Significantamountsofreadingbutnoprogramming(seeCSCI103L)
u Whatiscomputing,acomputer,science(andengineering)?u Howdocomputerswork?
v Computers,architectures,datastructuresandalgorithms,programming,operatingsystems,networks,abstractmachinesandtheory,artificialintelligence,robotics,humancomputerinteraction,…
u Whatiscomprisedwithinthedomainofcomputing?v Comprehendingitscontentandstructurev Appreciatingitspast,presentandfuture
u Provideabasisuponwhichyoucanbuildthroughouttheremainderofyourcomputingeducation
2
Purpose of this Course
3
Course Outline
4
ìSurvey:https://usc.qualtrics.com/jfe/form/SV_1zfPlEZPkAFZvr7Password:CS109Fall2018
5
1.Howmanycollegelevelcomputerclasseshaveyoucompleted?a.0 b.1 c.2 d.3 e.4ormore
2.Howmanyyearsofcomputerprogramminghaveyoudone?a.0 b.1 c.2 d.3 e.4ormore
3.Howmanyprogramminglanguagesdoyouknow?a.0 b.1 c.2 d.3 e.4ormore
4.AreyoutakingCS103concurrentlywiththisclass?a.Yes b.No
5.YourreasonfortakingCS109isa. Requiredforyourcurrentmajororminor.b. Notrequiredforyourcurrentmajororminorbutisrequiredforamajororminoryouwanttoadd(ormoveto).
c. NotrequiredforyourcurrentmajororminornorforamajororminoryouareconsideringbutyouareinterestedinlearningaboutComputerScience.
ìLogistics
6
Instructor and TAsu Instructor:AndrewGoodneyu Office:PHE434u OfficeHour: TBD(Seecoursewebsite)
7
u ContactInfo:[email protected]
TeachingAssistants(TAs)
Office: RTH406OfficeHour:Mon15:00-17:00
Office: RTH406OfficeHour:Tu 15:00-17:00
Artem [email protected]
Office:RTH406OfficeHour:Wed14:00-16:00
Important Info
u Classv Location:SGM123 Days&Time:M12:00-13:50
uTherearenodiscussionorquizsectionsv Classisnow2units(usedtobe3)
u Co-requisite:CSCI103Lv Thereisnoprerequisite
u RequiredTextbookv ComputingforOrdinaryMortals,St.Amant,R.OxfordUniversityPress,2013
u Syllabusisonhttp://bytes.usc.edu/cs109/u Slideswillbepostedon“bytes”uOtherreadingmaterialwillbemadeavailablethere
8
Homework (30%)
u Fourhomeworks (7.5%each)u Collaborationiswelcomeonthehomework
v Butcopyingisnotpermittedu Youareallowedatotaloftwolatedaysonthehomeworkv Onehomeworkmaybe2dayslate,ortwomaybe1daylate,withnopenalty
v Oncelatedaysareused,onedaylatereducesthescoreby25%,twodayslatereducesthescoreby50%,nocreditisgivenforthreeormoredayslate
v Allhomeworks mustbesubmittedtoearnapassinggradeu Allhomeworksubmissionsmustbetyped
9
Quizzes (5%), Midterm (30%),Final (35%)
u ~8in-classquizzesuNocollaborationispermittedonthequizzesu Bestfivescoreswillberetainedsoquizzesareworth5%ofyourgrade
u 1midterm:worth30%ofyouroverallgrade
u 1finalexam(cumulative):worth35%ofyouroverallgrade
10
Quiz policy
Thereareabsolutelynomakeupquizzes.Ifyouneedtobeawayfromclasstoseeadoctor,ortoplayonasportsteam,themissedquizzesneedtocomefromyourquotaofthetwo‘allowedmisses.’Pleaseplanonthis.Ifyoumissquizzesearlierinthesemesterbecauseyoudon’tcometoclassfornogoodreasonandthenarefacedwithasituationlaterinthesemesterwhereyouneedtoseethedoctor,pleasedonotrequestamedicalexemption.Youshouldmarshalthequotaof‘allowedmisses’carefully.Thequizzeswillbeadministeredinclassbutitisimpossibletopredictexactlywhenduringthelecturetheywilloccur.Ifyoucometoclassafterthequizforthatdayhasbeenadministered(orleavebeforeitisadministered),youarenotentitledtoamakeuportohavethequizre-administeredforyou.
11
How is the final grade assigned?
u Eachhomework,quizandexamreceivesarawnumericscoreu Bestfivequizscoresareretainedu Weightedcombinationofrawnumericscoresproducestotalrawscore(outof100)
u Thetotalrawscoreisnormalized– i.e.eachtotalrawscoreisdividedbythe95thpercentilerawscoreintheclass
u Gradeboundariesdrawntogroupsimilarnormalizedscoresinsamefinalgrade
12
ìWhat is a Computer?
13
Computer or Not?
14
Standard Definitions (dictionary.com)
u Anelectronicdevicedesignedtoacceptdata,performprescribedmathematicalandlogicaloperationsathighspeed,anddisplaytheresultsoftheseoperations
u Aprogrammablemachinethatperformshigh-speedprocessingofnumbers,aswellasoftext,graphics,symbols,andsoundv Allcomputerscontainacentralprocessingunit thatinterpretsandexecutesinstructions;
inputdevices,suchasakeyboardandamouse,throughwhich dataandcommandsenterthecomputer;memorythatenablesthecomputertostoreprogramsanddata;andoutputdevices,suchasprintersanddisplayscreens,thatshowtheresultsafterthecomputerhasprocesseddata
u Anelectronicdevicethatstoresandmanipulatesinformationv Unlikeacalculator,itisabletostoreaprogram andretrieveinformationfromitsmemory
u Amachinethatcanbeprogrammedtomanipulatesymbols
u Apersonwhocomputes;computist.v 1640s:“onewhocalculates”
15Aninformationtransformer
Types of Information
u Bits:0/1,T/F,True/False,Yes/Nov Andstringsofbits,suchas010110
u Numbers:5,101,-3,3.14159,i,πv Andnumericexpressions,suchas(3+2)
u Statementsinlogic:"x At(x,USC)Ù Person(x)Þ Smart(x)u Letters,words,sentences,paragraphs,articles,booksu Audio,imageandvideofilesu URLs(suchashttp://www/google.com)andwebpagesu Databasesu …
16
Binary
u Moderncomputersusebinaryarithmeticu Examples:
v 2410 =16+8=24 +23
=1 *24+1 *23+0 *22+0 *21+0 *20
= 110002v 9010 =64+16+8+2
=1 *26+0 *25+1 *24+1 *23+0 *22+1 *21+0 *20
=10110102v 101112 =1 *24+0 *23+1 *22+1 *21+1 *20
=16+4+2+1=2310
17
Information Transformation
u Convertonebodyofinformationtoanotherv Thatis,compute
u Example:Booleanalgebrav Informationexpressedinbits:0/1(orF/T)v Operationstransforminputbitstoyieldoutputbits
u AND,OR,NOT,…
18
AND 0 10 0 01 0 1
OR 0 10 0 11 1 1
NOT 0 11 0
XOR 0 10 0 11 1 0
AND(0,1)è 0 OR(0,1)è 1
AND(1,1)è 1 0OR(0,0)è
Information Transformation
19
AND 0 10 0 01 0 1
OR 0 10 0 11 1 1
NOT 0 11 0
Whatisthetruthtableforf(x,y)=AND(OR(x,y),NOT(AND(x,y)))?x y OR(x,y) AND(x,y) NOT(AND(x,y)) AND(OR(x,y),NOT(AND(x,y)))0 0 0 0 1 00 1 1 0 1 11 0 1 0 1 11 1 1 1 0 0
f 0 10 0 11 1 0
More on Information Transformation
u Otherexamplesv Mathematicalcalculations– (10+2)/2=6– andlogicalproofsv Solvingpuzzlesv Sortinglists:4,2,1,3,6,5v Computationalthinkingv Transformingdataintoinsights(bigdata oranalytics)v Transformingknowledgeintodecisionsaboutwhatactionstoperformv Literary,musicalandartisticcomposition
u Hardware enablesimplementingtransformationsu Software (programs)control(s)transformationsu Algorithms areabstractdescriptionsoftransformations
20
Computational Thinking
u “thoughtprocessesinvolvedinformulatingproblemsandtheirsolutionssothatthesolutionsarerepresentedinaformthatcanbeeffectivelycarriedoutbyaninformation-processingagent” (Cuny,Snyder,Wing)
v wayofsolvingproblems,designingsystems,andunderstandinghumanbehaviorthatdrawsonconceptsfundamentaltocomputerscienceu Toflourishintoday'sworld,computationalthinkinghastobeafundamentalpart
ofthewaypeoplethinkandunderstandtheworldv creatingandmakinguseofdifferentlevelsofabstraction,tounderstandand
solveproblemsmoreeffectivelyv thinkingalgorithmically andwiththeabilitytoapplymathematicalconcepts
suchasinduction todevelopmoreefficient,fair,andsecuresolutionsv understandingtheconsequencesofscale,notonlyforreasonsofefficiency
butalsoforeconomicandsocialreasons
21
Humansthinking(i.e.,transforminginformation)todeviseproceduresforexecutionbyinformationtransformers(humanand/ormachine)
Computer or Not?
22
Implications
u Definingcomputersintermsoftheirfunctionality…v Stripsawayancillaryattributespreviouslythoughtessential
u Machine,electronic,speed,explicitprogrammability,…
v Enablesappreciatingthefullscopeofcomputersandcomputing
u Facilitatesrecognitionof“natural”computersv Brain:Thoughtispreeminentlyinformationtransformationv Embryonicdevelopment:BasedoninstructionswritteninDNAv Evolution:CombinesandmodifiesinformationinDNAv Immunesystem:Includespatternrecognizers,memory,…
23
DavidBaltimore:“Howbiologybecameaninformationscience”RichardDawkins:“Thedifferencebetweenlifeandnon-lifeisa
matternotofsubstancebutofinformation”
ìComputer HistoryLooms,thediscretemachineabstraction,andthefirstcomputerprograms
24
A History of Human-Built Computers
u Althoughcomputerscan(andhavebeen)builtusingallkindsofhardware,moderncomputingreallytookoffwiththeinventionofelectroniccomputerswhichwereprecededbymechanicalcomputers
u AhistoryofcomputingandtheJacquardLoomuMechanicalComputers
v TheDifferenceandAnalyticalEnginesv TheHollerithMachine
u ElectronicComputersv FromEDSACtotheMacbook
25
Reading:St.Amant: Introduction,Ch.1andCh.2
Before Mechanical Computers
Electroniccomputerswereprecededbymechanicalcomputersandmechanicalcomputerswereprecededby…
…looms
26
A Simple Mechanical Loom
u Pressingtreadlescausesharnessestoliftthreadsu Theshuttleslidesacrossthreadundertheliftedthreadsu Thenthethreadsareloweredu Pressingtreadlescausesharnessestoliftthreadsu Theshuttleslidesacrossthreadundertheliftedthreadsu Thenthethreadsareloweredu Pressingtreadlescausesharnessestoliftthreadsu Theshuttleslidesacrossthreadundertheliftedthreadsu Thenthethreadsareloweredu …u Whatkindofpatternsdoesthisproduce?
27
Discrete Machines: State
uHowdoestheloombehaveasafunctionoftime?u Atanygiventimeasetofthreadsisraisedandtherestarelowered
uWritingdownthesequenceofraised(andlowered)threadstellsusthestepsthemachinewentthroughtoproducethecloth/tapestry/whatever
u Thepatternofraised(andlowered)threadsiscalledthestate ofthemachine
28
State
u StateisaverycommonCSconceptu Herewehavethestateofamachine
u InCSwetalkaboutthe“state”ofanobjectv Ofadatabasev Ofarobotv Ofa“state-machine”(finite,Turing,etc…)v Ofasystem(physicalorvirtual)v …
u Thenweneedawaytodescribethestateu Givesusthenotionofanencoding
29
Discrete Machines: State and Encoding
u Choosingastaterepresentationtakesskill.Thestateshouldbev Parsimonious:itshouldbea“small”descriptorofwhatthemachineis
doingatanygiventimev Adequate:itshouldbe“bigenough”tocaptureeverything“interesting”
aboutthemachine
u Thesearesometimescontradictory.Theyarealsoqualitativeanddependonwhatbehaviorofthemachinewewanttodescribe
uUsuallyyouneedavocabulary(encoding)todescribestate.Inthecaseofaloom,statecanbeexpressedasabinarypattern(1forraised,0forlowered)
30
Discrete Machines: Abstraction
u Theloomisadiscretemachinev Stateisbinarypattern– i.e.discretev Thenotionoftimeisdiscrete– i.e.timeismodeledasproceedinginstepsor
finitechunks
uMoreprecisely,theloomcanbeusefullymodeledasadiscretemachine
u Thisisanexampleofanabstraction – akeyconceptinComputerScience
31
Abstraction
u Oneofthefundamental“things”wedoinCSu Reducingordistillingaproblemorconcepttotheessentialqualitiesv Simplesetofcharacteristicsthataremostrelevanttotheproblem
u Many(most,all)ofwhatwedoinengineeringandcomputerscienceinvolvesabstractions
u Heretheabstractionismodellingtheloomasasimplediscreetstatemachinev Makesitpossibletounderstandv Andmakesitpossibleto“program”theloom
32
Weaving Complex Patterns
u Howtoproducemorecomplexpatterns?u Earlysolutionwashuman– thedrawloom
v Masterweavercallsoutwhichthreadstoliftv Drawboy liftsthreadsv Masterweaverthreadstheshuttlev Masterweavercallsoutwhichthreadstoliftv Drawboy liftsthreadsv Masterweaverthreadstheshuttlev Masterweavercallsoutwhichthreadstoliftv Drawboy liftsthreadsv Masterweaverthreadstheshuttlev …
33
The Jacquard Loom (1801): Mechanism
uMechanism:v Threadsattachedtospring-loadedrodsv Springsmakeallthreadswanttoliftunlessstoppedsomehow
v Ametal‘card’withholesisinsertedintothepathofthethreads
v Aholeinthecorrespondingplaceallowsathreadtolift.Noholearreststhethreadmotionandstopsitfromlifting
u TheJacquardLoom(fromtheTeachingPaletteviaYouTube)
34
The Jacquard Loom: Programming
uWeavingbecomestheprocessofv Creatingcardswithholesinthem(punchedcards)
v Sequencingthecardsintherightorder
u Eachcardisaninstruction tothemachinetodopreciselyonething(i.e.,putitselfintooneparticularstate)
u Asequenceofcards(i.e.,asequenceofinstructions)causesthemachinetostepthroughasequenceofstates.Thecardsequenceisaprogram
u Theweaverasaprogrammer35
JosephMarieJacquard(aswovenbyhisloomviaaprogramof24,000instructions).ImagecourtesyofWikipedia.
The Jacquard Loom: Programming
u Adiscrete,‘automatic’machineu Sincewehavechosenabinaryencodingthemachinestateisabinarynumber
u Eachinstruction isalsoabinarynumbersinceeachinstructionis(literally)thestatetheprogrammerwantsthemachinetobeinwhenthatinstructionisexecuted
u Theprogram forthemachineisasequenceofinstructions.Eachprogramis(literally)asequenceofstatestheprogrammerwantsthemachinetostepthrough
u Theprogram isthusasequenceofbinarynumbers36
A Loom Program
000000000010000010
001000100000101000
000010000
000101000001000100
010000010000000000
37
0130
6840
16
4068
1300
u Thismachine’sstateiscapturedina9-bitword
u Eachinstructionintheprogramisalsoa9-bitword
u Thestateandeachinstructionisthus9bitswide
u Thisprogramis9instructionslong
Loom Program Limitations
uDoesnotscale:v Largeinstructions:Toprograma‘big’machineyouneed‘big’words(largestateimplieslargeinstructionwidths)
v Nocounting:Norepeatsorloopstodothingsoveracertainnumberoftimes(No“do..while”or“repeat..until”)
v Nomodularity:Nologicalchunksforsub-patternsthatcanbereusedwithoutreplication(No“functions,methods,subroutines…”)
uNodecisionmakingonthefly:v Nobranchingtodecidetodoonethinginsteadofanotherbasedonacondition(No“if-then-else”.Nojumpsor“goto”)
38
How Big/Fast is a Modern Computer?
u TypicalMacbook Prolaptophas~1billiontransistorsu Thestateofthemachineisabinarynumberwith~1billionbits(abinarywordofwidth~1billion)v NotpossibletoprogramaMacbook Probywritingasequenceofinstructionseach~1Billionbitswide
u AMacbook Proexecutes~5billioninstructionspersecondv Possible tohaveprogramsthatarebillionsofinstructionslongandyethavethemfinishoperatinginareasonabletime
39
Modern Computers?
u Ifmoderncomputersaresobig,howdoweprogramthem?u Wemodel(abstract)thecomputerassomethingmoresimple
u Programtothatmodel
u ThenletthehardwareandOSsortoutthedifferencebetweenrealityandourabstraction
u Thismethodofproblemsolvingisvery,verycommoninCS
u Morelaterinsemester
40
ìComputer HistoryMechanicalcomputers:Thedifferenceandanalyticalengines,theHollerithmachine
41
The Difference Engine (1822)
u CharlesBabbageuMechanicalcalculator tocomputemathematicaltables
v Loom:programtransformsthreadstopatternsonclothv Differenceengine:programtransformsnumbersintoothernumbers
u PolynomialfunctioncomputationusingdifferencesuOutputwasviaa‘printer’– adevicethatproducedprinter’splatessotheycouldbestampedontopaper
uNobranchingorlooping,limitedinwhatitcouldcompute
42
VideofromYouTube.
The Analytical Engine (1837)
u CharlesBabbageuWorld’sfirstgeneralpurpose mechanicalcalculator
v Memoryv Arithmeticunitv Branchingv Looping
u ProgrammedbypunchedcardslikealoomuOutputwasviaa‘printer’– adevicethatproducedprinter’splatessotheycouldbestampedontopaper
43
VideofromYouTube.
The Hollerith Tabulator (1890)
uHermannHollerithu Firstdevicetoreaddata intoamachine:anelectromechanicalsystembasedonpunchedcards
u BuilttotabulatetheresultsofUScensusuHollerithwentontoformtheTabulatingMachineCompany.MergedwithotherstoformtheComputingTabulatingRecordingCompany(CTR).Renamedin1924toInternationalBusinessMachines(IBM)
44
HermannHollerithandoneofhispunchedcards.ImagescourtesyofWikipedia.
The ENIAC (1943-46)
u ElectronicNumericalIntegratorAndComputer
u EckertandMauchly (UniversityofPennsylvania)
u Firstelectronic,generalpurposecomputer.Turing-complete,digital,reprogrammable(cumbersome)
u Vacuumtubeanddiode-based
45
The EDVAC (1944-49)
u ElectronicDiscreteVariableAutomaticComputer(EckertandMauchly)
u Firststoredprogramcomputer,binary(ENIACwasdecimal).Operational1951.
u PopularizedbyvonNeumann(FirstDraftofaReportontheEDVAC)– firstreportonamoderncomputerarchitecture
46
Computer History Summary
47
u Althoughcomputerscan(andhavebeen)builtusingallkindsofhardware,moderncomputingreallytookoffwiththeinventionofelectroniccomputerswhichwereprecededbymechanicalcomputers
u AhistoryofcomputingandtheJacquardLoomuMechanicalComputers
v TheDifferenceandAnalyticalEnginesv TheHollerithMachine
u ElectronicComputersv FromEDSACtotheMacbook
Fundamental Concepts
uStateanddiscretemachinesuAbstractionandmodelsuEncodingdataandinstructionsuProgramminguTobegeneral,programsneedtoaccessamemory,andtobeabletocontroltheorderoftheinstructionstoexecutebasedontheresultsofcomputation
48
Review of terms
uState:Theconditionofasystematapointintime
uEncoding:Symbolicexpressionusedtorepresentinformation
uDiscrete:Proceedinginfinitesteps,individuallyseparateanddistinct
uBinary:Numericalnotationthatusesbase2uAbstraction:Simplified(“higher-level”)description 49
ìNext time: Computer ArchitectureHowarecomputersbuilt?
50