ALGORITHMS-1

Analysis, design approaches, searching, sorting, hashing, trees 1. Consider the ollo!ing three clai"s 1. #n $ %&" ' (#n"&, !here % and " are constants ). )n $ 1 ' O#)n& *. )n $ 1 ' O#)n& +hich o these clai"s are correct, #a& 1 and ) #-& 1 and * #c& ) and *

#d& 1,) and *

). The ollo!ing are the starting and ending ti"es o acti.ities A, /, C, 0, 1, 2, G3 and H respecti.ely in chronological order4 5as -s cs ae ds ce es s -e de gs ee e hs ge he6. Here, 7s denotes the starting ti"e and 7e denotes the ending ti"e o acti.ity 7. +e need to sched8le the acti.ities in a set o roo"s a.aila-le to 8s. An acti.ity can -e sched8led in a roo" only i the roo" is reser.ed or the acti.ity or its entire d8ration. +hat is the "ini"8" n8"-er o roo"s re98ired, #a& * #-& : #c& ; #d& < *. S8ppose each set is represented as a lin%ed list !ith ele"ents in ar-itrary order. +hich o the operations a"ong 8nion, intersection, "e"-ership, cardinality !ill -e the slo!est, #a& 8nion only #-& intersection, "e"-ership #c& "e"-ership, cardinality #d& 8nion, intersection :. Let A=l, ... , n> -e an array storing a -it #1 or ?& at each location, and #"& is a 8nction !hose ti"e co"ple7ity is (#"&. Consider the ollo!ing progra" rag"ent !ritten in a C li%e lang8age4 co8nter ' ?3 or #i'l3 i@n3 i$$& Ai #A=i> ' ' 1& co8nter $$3 else A #co8nter&3 co8nter ' ?3B B The co"ple7ity o this progra" rag"ent is #a& (#n)& #-& C#n log n& and O#n)& #c& (#n& #d& o#n& ;. The !orst case r8nning ti"e to search or an ele"ent in a -alanced -inary search tree !ith n)n ele"ents is #a& (#n log n& #-& (#n)n& #c& (#n& #d& (#log n&

<. Let +#n& and A#n& denote respecti.ely, the !orst case and a.erage case r8nning ti"e o an algorith" e7ec8ted on an inp8t o siDe n. +hich o the ollo!ing is AL+AES TRF1, #a& A#n& ' C#+#n&& #-& A#n& ' (#+#n&& #c& A#n& ' O#+#n&& #d& A#n& ' o#+#n&&

G. A list o n strings, each o length n, is sorted into le7icographic order 8sing the "erge-sort algorith". The !orst case r8nning ti"e o this co"p8tation is #a& O#n log n& #-& O#n) log n& #c& O#n) $ log n& #d& O#n)&

H. In the ollo!ing C 8nction, let n I ". int gcd #n, "&

+hat is the s"allest . Then O is e98al to4 #a& "a7 #E.ing 1?% records.e pac%ages A and / are a.aila-le or processing a data-ase ha. #a& (#log n& #-& C#n& #c& (#log log n& #d& (#Kn& L. M). a? $ ES)& #c& "a7 #E. r 7 s and s 7 t respecti. Ln$1&..A i #n J " '' ?B ret8rn "3 n ' n J "3 ret8rn gcd #".ely can . #a& 1) #-& 1? #c& < #d& . %eeping the order o the re"aining ele"ents the sa"e.en se98ence is N8st the gi. i either i' ? or N ' ? ' e7pr1.en -elo!4 l#i. 9 7 r.e calls are "ade -y this 8nction. #a& The algorith" 8ses dyna"ic progra""ing paradig" #-& The algorith" has a linear co"ple7ity and 8ses -ranch and -o8nd paradig" #c& The algorith" has a non-linear polyno"ial co"ple7ity and 8ses -ranch and -o8nd paradig" #d& The algorith" 8ses di. 1?. +e are gi. #a& e7pr1 R l#i-1. N&& 11. N-1&& #d& e7pr) R "a7 #l#i-1. N -1& #c& e7pr) R "a7 #l#i-1. N& ' ?.. an-1 o real n8"-ers is de ined as a?$a1S)$. l#i. n&3 B Ho! "any rec8rsi. an-1.. 2or all i s8ch that ? T i T n-) 2inally the length o the longest "onotonically increasing se98ence is "a7#L?. Ll.en t!o se98ences O="> and E=n> o lengths " and n.e de inition or the 8nction l#i. +hich o the ollo!ing state"ents is TRF1..en se98ence !ith so"e ele"ents #possi-ly none or all& le t o8t. !ith inde7es o O and E starting ro" ?.. U.1> ' E =N -1> ' e7pr). The !eight o a se98ence a? al . Let Li denote the length o the longest "onotonically increasing se98ence starting at inde7 i in the array InitialiDe Ln-1 ' 1. An algorith" to ind the length o the longest "onotonically increasing se98ence o n8"-ers in an array A=?4 n-1> is gi. an-1S)n-1.al8e o % or !hich pac%age / !ill -e pre erred o. Mac%age A re98ires ?..ely. a? $ )E& #d& a? $ ES) 1). i i. N& $ 1 #-& e7pr1 R l#i.1> Q E=N -1> +hich one o the ollo!ing options is correct.???1 n) ti"e 8nits and pac%age / re98ires 1?n log1?n ti"e 8nits to process n records. 2o8r "atrices Ml.ide and con98er paradig" 1*. Let O denote the "a7i"8" possi-le !eight o a s8-se98ence o a? al . M* and M: o di"ensions p 7 9.en -elo!. n&. an-1 and E the "a7i"8" possi-le !eight o a s8-se98ence o a1 a) .. N&. l#i. N-1&. +e !ish to ind the length o the longest co""on s8--se98ence #LCS& o O="> and E=n> as l#". a? $ E& #-& "a7 #E. !here an inco"plete rec8rsi. i i. A s8-se98ence o a se98ence is o-tained -y deleting so"e ele"ents ro" the se98ence.. A s8--se98ence o a gi. N& to co"p8te the length o the LCS o O="> and E=n> is gi. respecti.er A. N P ? and O=i .N P ? and O=i . T!o alternati.

. The n8"-er o lea. !e 8se -inary search to identi y the position. ). and t ' H?.??? 1:. In a co"plete %-ary tree. then the "ini"8" n8"-er o scalar "8ltiplications needed is #a& ):H??? #-& ::??? #c& 1L??? #d& ). +hat is the res8ltant hash ta-le. )*.eral !ays !ith di erent n8"-er o total scalar "8ltiplications. *.ot. I p ' 1?. #a& . 1<. 2or e7a"ple !hen "8ltiplied as #M1 7 M)& 7 #M* 7 M:&. The 8s8al (#n)& i"ple"entation o Insertion Sort to sort an array 8ses linear search to identi y the position !here an ele"ent is to -e inserted into the already sorted part o the array. #a& #-& #c& #d& . S8ppose there are log n sorted lists o nSlog n ele"ents each. 9 ' 1??. the !orst case r8nning ti"e !ill #a& re"ain (#n)& #-& -eco"e (#n #log n&)& #c& -eco"e (#n log n& #d& -eco"e (#n& 1. 1H.es in s8ch a tree !ith n internal nodes is #a& n % #-& #n V 1&% $ l #c& n #% V 1& $ 1 #d& n #% V 1& 1G. e. s ' .-e "8ltiplied in se. and 1. the total n8"-er o sca1ar "8ltiplications is p9r $ prs $ pst. The "a7i"8" n8"-er o -inary trees that can -e or"ed !ith three 8nla-eled nodes is #a& 1 #-& . in !hich "edian is selected as pi. Ho! "any distinct -inary search trees can -e created o8t o : distinct %eys. are inserted into an initially e"pty hash ta-le o length 1? 8sing open addressing !ith hash 8nction h#%& ' % "od 1? and linear pro-ing. +hen "8ltiplied as ##M1 7 M)& 7 M*& 7 M:. The ti"e co"ple7ity o prod8cing a sorted list o all these ele"ents is4 #Hint4 Fse a heap data str8ct8re& #a& O#n log log n& #-& (#n log n& #c& C#n log n& #d& C#n*S)& 1H. #c& : #d& * )?. the total n8"-er o scalar "8ltiplications is p9r $ rst $ prt. +hich one o the ollo!ing is correct a-o8t the co"ple7ity o 98ic% sort. The %eys 1). 1*. The "edian o n ele"ents can -e o8nd in O#n& ti"e. r ' )?. #-& 1: #c& ): #d& *. I instead. #a& (#n& #-& (#n log n& #c& (#n)& #d& (#n*& 1L.ery internal node has e7actly % children. .

Sign up to vote on this title
UsefulNot useful