0% found this document useful (0 votes)
50 views

Computer Science Sample Test

Uploaded by

Abeba Abeba
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
50 views

Computer Science Sample Test

Uploaded by

Abeba Abeba
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 10
What does 1001, plus 11105 equal A. tonne B 1001, © um, bout E320 ‘What ouput by the code to he ihe? A 9 B10 ew int y= 2 Systemsout.peintin( x 4 y * x17 boa Boge ‘Whats ouput by the coe tothe ihe? for(int 4 = 0; 6 <5; S4H0T Ao Bos ce total += 23 1 bos RW System.out.printin¢ total) (UN ccc ccc ccc ceca csecceeeeeeeeccea seccceacacececce seeeeeeeeeeeeeeaieeeaeacaay ‘Wht opt bythe coe tothe ihe? A sourn =, SOUTHBE ¢,sourne Systen.cut.printia( s.tolppercaset) } D. soutnas g,souraie ‘Wht tpt bythe code to the itt” es fel) data = (3, 2, 4. 3, 1, Oh Gatalt} = aneatt) + anea(3} Ds Systom-outsprintln( daea(1] 12 ‘Whats ouput by the cde tothe ight? — B20 G03 int v = 20; Systen-out-printiat x ¥ v} as Which answer logically aquvalento the following boolean expression, whee p and q ste bootean vasabls? pas te A pillg B tpua fupil@ Do eile & Hp ee al ‘What oupat bythe ede to the ight? ee aa Bo? eo “system.out print ( 1) ists 10 bo There ito ouput Systen.out print ( 2 )7 ‘Whetrepiaces <*1> inthe code oth ight india thatthe method caketrip does ot retum value? AL retur static D. private Assune ie iledin corset ‘Which ofthe fellowingcestes a car objet whose imide instance variable iniaied oe? AL Car © = new Car(*0"); ©. car © = new car (0): D. car © = now carimilee.0)7 public privat fe Cer (int =) | fc takereip(int 2en) | fe Ane getdiatance ) { turn miles? = ‘What opty the coe thei ce A a 2 ine 2 is Systemsout-prine( k 6 295 D> Boe | ow many lines of up des code tothe roms? syeten.out.print ("iret sting") ‘ aA : Syeten.out print second string): = a : system, println ("third string"). b> a4 om . ‘Whats ouput the code oth rig oie Cy systom.out.printin¢ Mathai (28, 7) 93 pou Bk 2 ‘Wit sutpy th code tei? 2. A 0019 19.0 avoo1s DB, 19.00 1» Syatan.out prints ("804d Ean ‘What retumed by the method call spo (3)? A 6 Bos cw Bo8 Bo ‘What soup bythe cde to the i? public static int aimpletine 19 ( eee eee cece occa eee eeca eee ceeeeeeeeeeeaecececees E “There no oul de oa rine eno Whats ouput bythe ede to the ih? A. true grace B, true falee C true true, Falae false B fatee true se Boa ce String nares = "Bob on J Tints Steingl] chopped = ames. splie (\\80"); D. Theeis 0 ouput keto ee err System. out prine( enopped: lenge 7 BTheeis so op ean RrrayindenOutOboundstcoptio ee : Whats remedy Re metiod ell 2004)? tet <0) ae nan Saco, bow oe | Torn a ase = 0: = eee ay inti ouput by te coeto ie righ whe method two | PHPLEC state tnt one ine iter ‘ 3 Boa 1 public static int onetine x, Ant yt D. Theeisaa ouput eto esa er oturn # + ys , pubtic static void ewot)( System. out print ( one (2, , os OR eee eee eee eee eee eee cece eeeeee eee cece ce eeceeeeaaaet syatan, system obj = new opject fout.prine{ ob} instanceof string 1; futspeane( "" y3 fUE:PEAME| str instanceof Object 1s ‘What out by the code othe ght? AD false |B true door D. Therefeno ouput die toa sya ere There isno out due toa runtime evr. cnn ‘Wha is ouput by the code othe right? AG Bm Doo 3) B 10,3, 71 RNUNNNOT eeeeeeeeeeeeeeeeeeeeeey | Wich ofthe follwing could replies <*1> inthe code | sotheriehtas a symtcil egal denier? AL value BL int coy D, mom2 More than on of these, Syatom.oue-prine( item.metches ("dor") 7 ecient ama.aad (0) System.out:peint ( mums 1; int en = 425 ‘The ce tothe ight contuins x yntix er, Which the following best describes the ease forthe sian | A. Duplicates my notbeaddedioa set. BL "btina chas,nola String C._Instance of interes cannot crete Sets cannot be tested aver wing the fenhanesd for lop Exr ‘Whats ouputby he code to thei? Ax Boy «2 Dow Rox sraiisetaad(7A") ‘mai set ada ("5") ‘smal lset ada ("A for( string str! smallset ) System.outepeine( str )7 Quevecstring> q ~ new LinkedLstesteing> (07 Seada( graday Gradat sr" 93 Systom.out print ( q.renove() | | ‘Whats ouput bythe code to he ihe? inte) ary = (5, 7, 317 inet] etherary = axy: Aa Boo «6 etheeary(t]+s7 Otherary = new ine {5}: bo? RS Systom.out print aryl] 9 =z | ‘ow many se out by the cod tthe ight? An Bo c 10 D3 Row Ean ‘What replaces <#1> inthe code tothe ight that ifthe clement at index 3 sles than the dement at index em ‘Sccrding othsir astral ordering te steent temp = 37 executed? A jreo aatatj1 < daca[temp) emp. compareto datatj} -compareTo| ditattemp) a « D. j.compareto( data{tesp] ) > 9 E datalj] comparoto| dataltompl ) <0 “Assume ‘filled corey ‘What replaces <#2> inthe code tothe ight thatthe | elements oinalyatindices anc 3 inary data tre swapped wih ach ee? Joa ine na BL Comparabie t ~ aataliit | | aata(il = aatalily aatats] =e ©. datatiy = datalsy > a | aee(j} = datals] * dacal}) atatl} = data(j] * dacatil: DB. datali) = datatils fatata) = datatils More than one of thes, [ Resume and ae led omel =—“=i‘OSOSOCS What soring lgsithm s implement by methods sort aid. ewapt ‘A, Insertion sort Bie Sort © Selection SoD. SllSoet 5 Merge Sort public static void sort (Comparablet] data) | for(int i= 07 4 den ~ 27 464 for(int j= £41 4 < dens 549 Steely | temp 5 1 suap( data, i, temp)? ' 1 public static void swap(Comarablet} data, int i, ine a} ‘What replaces <¥1> inthe code othe ight io ingiete hl the Proetinp named encode has String fr Keysand Integers fr values? B, D. cint> | & filled comet aN cece ccc cccccceereeeeccaes ‘What ouput by the code othe ihe? 199, Bon seamaperi> encode pur ("Mm, 21217 fencode put ("A", 193) encode pue ("9 22107 Keeratore Map.Enteyerd> > its = encode .entcyse rator(): Systen.out-print{ se-noxt{) -getvaive() bs ‘Whats ouput by the code othe ight when method First ised? noo ds B, Thereisno ouput doe oa rime err ‘What searching soins mpl by methods ind and help? ‘A. finer search 1B. interpolation search random search comb each Ebina serch {Given an ray tut contin N cements what is tbe | expected running ine of method Fine? Chose the A ON) BOM) OLogN) DL O(Nogs) B—OfsarN) (+ pre: data != null, elements of date are a a public static Int find(ine tat, ine{) datay | fen = data. lengtn - 1p A HelplO, eny tat, dal Tne egt, inet] ent Get tem / 2 data ed J Tel vel == tat | else if( tgt < val } Fesult = hepist, sd result = help(nd + int helplint sty gata) ty tat, datal: 4, eny tot, datay: return resulty 1 public static void fizst() Ene{y data = {0) 5 19, 10017 Systan.out print find(s, data) ) y public class Seructurecs ‘What replaces <*> inthe code othe ight otha method istinpty retims true ifthe Arraylsst imyCon contin 0 element? public at cease) [ myCon.eize() == 0? falee + teve ‘nycon = new AreayLA 0 , 03 sized) > oF : public vold add(e ob) ( rmyCon sade (905) A 8 return supersize) D, return ayCon.size|) == 0 1 B_auper.myCon. isbapty (17 public E peskid{ “numne isle in conety Psst yloneget mycon.size) = 194 INI cece cece eeececeeceecceed What i onpt by the cde tothe ih when metho. public boolean isEmpty (| second incall? Neb: A BA Rone public & resove() ( , EnDrEs 1 ‘Wat ype of daa sucuredoesthe Steucture else | ///////// etient code ////1//11 implemen? public static void second oe ee ee oY po stxacture() s.aday "at yy D. Heap _Blnay Search Tree siada( "5" ); | thile( te-Asbmeey() ) System. out -prine( =. zenove() ) ‘Assunetie mead sample (int (data) O(N whee N—data- length. Whenthe mead sample pase fry wit Length ~ 10000 tik secon fort serps complet ied spe sth psd sy ‘it Length = 20000 wat she pete ine wil ke mead sano compce? 1 ‘A Qawconds «BS Satonds == Cameos =D, Gaceonds, «=, Raconde I cccccccccccccacaiaces “The following values re ines in fe oder show ino a binay search te sing the wana neton algorithm, What i theres of post oder avers of he resling Fee? 2, 8 ty BO A 21068 B 01268 C 01862 D 21608 £ 08162 Which keyword is sed in msthod declaration to india the stad may generate an exception, but wll a ry to handle Iocally? boa ey BR throws eaten D. throw B fineity Standard Classes and Interfaces — Supplemental Reference clase Java. tang.chsect ‘© ‘boolean eqvals (Object o:her) © int hashCode () sptertace java-lang.Conparablect> (© ant conpareto# other} Rem valve if ch sean ote, elses Ja Aang. tmtager Saptonant ‘Conparsble © int conparcto(Integer arotherinteger) ‘Somparabiecooumte> © double doublevValue() © hootean equals ovject 03) clase Jave tang. string implements boolean equals object obs) “Rerursthe substing staring a inex eoin ‘espe stsing Reta Sif stot ona Index Reurm “Dif ste it String tollppescave (} Steingl eplie(steing reg) java tang character Static char tolppercece char ch) save tang men sqrt (double @) Static 1eng round idouble a) reqalto 0.0 tedlesdan 2.0. setertace java.util Listers © oviean aati eb © Listiteratore®s Listiteratorg (class jave-util Arrayiist teplenants Liatce> Mets matin tbe st metho © E settine Sader, Eo) Repl he ele de wh ‘do and per fe ia oer es} an dune size Removes clnewt fom posion nox sling erent pesos (andes 1) and bigherto het (ence onde) a ade sae lace java.util tinkedListc> inplanente Elser, Geeuec> Fomover rst) java weet stacker clase Fenovet) java util riorityguesee> toslean ada (Ee) ntorface java. utii. sete Boolean senoveali (Coblestione®> ©) java.util lachsetce> implements Set ‘java. utia.teeesetcR> implements Setce> interface java. otsl.Maper ¥> Ceres pute ee Waet object aoyi boolean contatnatey (Object key) Vvatve) java.utal tastapen, > seplenante Mapa v> Java wea teeetapen > Septamants Mapa > ntesface java .otid.ttap Entry, astkey sntertace java otii.Tearatoret> ct) Sava util. Tearatorei> std nsdn eth Teeratoe note java tang txception Boolean hastlentDoubieQ) Computer Science Answer Key UIL Invitational A 2008 LA ue aA 3A 2A 2B 2. E 2A 3 E Bc 23. ¢ 33. E 48 “A 24. c 34. c = 0 18. D 25.8 35. D 6 16. B 26. D 36. A ic 7. D 2B 37. 2B oD 18 A 28. B 38. E 9 E 9B 29..€ wc oc 20. B 30. E 40. B Notes: 22. Choices A and D are both syntacically legal identifies 31. The TreeMap stores keys in ascending order, thus the frst entry inthe map willbe ("A, 193) and "A" is the key for that entry ‘The clause "Choose the most restrictive correet answer." is necessary because per the formal definition of Big O, an algorithm that is O(N’) is also O(N’) , O(N"), and so forth

You might also like