Exam Questions Chapter 1
Total Page:16
File Type:pdf, Size:1020Kb
Exam questions Mark Allen Weiss School of Computer Science Florida International University University Park Miami FL Abstract This rep ort contains a collection of multiplechoice questions organized by b o ok chapter that can b e used 1 a for examinations Answers are provided at the end This rep ort was typeset in L T X Original source is E available Chapter What is the approximate value of log a b c d e none of the ab ove If log n equals what is the value of log n a b c d e none of the ab ove When p erforming a pro of by induction which is the case that is trivially true a the basis b the inductive hypothesis c the lemma d the theorem e none of the ab ove 1 Many of these questions app ear in dierent form in the Instructors Resource Manual for Algorithms Data Structures and Problem Solving with C published by AddisonWesley The following routine violates which rules of recursion function Recurse N Integer return Integer is begin if N then return else return N Recurse N Recurse N end if end Recurse a No base case b Fails to make progress c Performs redundant work d Two of the ab ove e All of a b and c Which of the following is the most likely result of failing to make progress towards a base case in a recursive call a compiler enters into an innite lo op b error at compilation time c exception is raised at run time d recursive routine enters an innite lo op when it runs e recursive routine terminates with bad value but no other error Answers B A A D C Chapter Which of the following functions grows fastest a n log n n b c log n 2 d n 20 e n Which of the following functions grows fastest a n log n b n log n c n log n d n e There is a tie among two or more functions for fastest growth rate The next three questions apply to the fol lowing code fragment for i in N loop for j in i loop for k in ij loop Sum Sum end loop end loop end loop for p in NN loop for q in p loop Sum Sum end loop end loop How many times is statement executed a O N 2 b O N 3 c O N 4 d O N e none of the ab ove How many times is statement executed a O N 2 b O N 3 c O N 4 d O N e none of the ab ove What is the running time of the fragment 4 a O N 5 b O N 6 c O N 7 d O N e none of the ab ove Supp ose T n O F n and T n O F n Which of the following are true 1 2 a T n T n O F n 1 2 b T n T n O F n 1 2 c T nT n O 1 2 d T n O T n 1 2 e none of the ab ove Programs A and B are analyzed and found to have worstcase running times no greater than 2 n log n and n resp ectively Which of the following statements do es the analysis imply a Program A will run faster on average for suciently large n b Program B will run faster on average for small n c Program A is probably simpler to co de than program B d There exists some input for which program B takes longer than program A e none of the ab ove An algorithm takes seconds for an input size of If the algorithm is quadratic approx imately how long do es it take to solve a problem of size a seconds b seconds c seconds d seconds e none of the ab ove An algorithm takes seconds for an input of size If the algorithm is quadratic how large a problem can b e solved in two minutes a b c d e none of the ab ove An algorithm takes seconds to solve a problem of size and ten minutes to solve a problem of size What is the likely running time of the algorithm a constant b linear c quadratic d cubic e none of the ab ove Which of a to d is false ab out the binary search a the input array must b e sorted b successful searches take logarithmic time on average c unsuccessful searches take logarithmic time on average d the worst case for any search is logarithmic e all of the ab ove are true Which of the following can b e done in O log n arithmetic op erations a Raising a number to the nth p ower b Computing the greatest common divisor of some integer and n c Adding two ndigit numbers d Two of the ab ove e All of a b and c A recursive algorithm works by solving two halfsized problems recursively with an additional lineartime overhead The total running time is most accurately given by a O log n b O n c O n log n 2 d O n e none of the ab ove The solution to T n T bnc with T is most accurately given by a O log n b O n c O n log n 2 d O n e none of the ab ove Approximately how many random numbers are using in the p ermutation generation algorithm in Exercise c a b log n c n d n log n e none of the ab ove What is the running time of the following routine Check if N is prime function IsPrime N Integer return Boolean is I Integer begin if N or else N then return TRUE end if if N MOD then return FALSE end if while i i N loop if N MOD i then return FALSE else I I end if end loop return TRUE end IsPrime a constant time b O log N c O N p d O N e none of the ab ove Answers B B C D A A E C A C E D C A C D Chapter Which of the following op erations is not eciently supp orted by a singlylinked list a accessing the element in the current p osition b insertion after the current p osition c insertion b efore the current p osition d moving to the p osition immediately following the current p osition e all of the ab ove are eciently supp orted Which statement placed in the list package implementation inserts an item X after p osition Current a Current new Node X Current b Current new Node X CurrentNext c CurrentNext new Node X Current d CurrentNext new Node X CurrentNext e none of the ab ove The header no de of a linked list a simplies deletion b simplies insertion c uses only constant extra space d two of the ab ove e all three of a b and c If a header no de is used which of the following indicates a list L with one item a LHeaderNext null b LHeaderNext null c LHeaderNext null and then LHeaderNextNext null d LHeaderNext null and then LHeaderNextNext null e none of the ab ove Insertion of a no de into a doubly linked list requires how many changes to various Next and Prev p ointers a no changes b Next Prev c Next Prev d Next Prev e none of the ab ove What op eration is supp orted in constant time by the doubly linked list but not by the singly linked list a Advance b Backup c First d Retrieve e all of the ab ove are always constant time The UNIX editor vi allows searching in b oth directions with wraparound if necessary If the sequence of lines is stored as a linked list which of the following is most reasonable a singly linked list b doubly linked list c circular singly linked list d circular doubly linked list e none of the ab ove What happ ens when wraparound is implemented for a queue a If Front advances past the last array p osition it is reset to the rst array p osition b If Rear advances past the last array p osition it is reset to the rst array p osition c Both a and b d Neither a nor b Using the text implementation if Front and Rear have identical values what is the size of the queue a b c d the answer cannot b e determined e none of the ab ove For the linked list implementation of the stack where are the pushes and p ops p erformed a Push in front of the rst element p op the rst element b Push after the last element p op the last element c Push after the last element p op the rst element d Push in front of the rst element p op the last element e Push after the rst element p op the rst element For the linked list implementation of the queue where are the enqueue and dequeues p er formed a Enqueue in front of the rst element dequeue the rst element b Enqueue after the last element dequeue the last element c Enqueue after the last element dequeue the rst element d Enqueue in front of the rst element dequeue the last element e Enqueue after the rst element dequeue the rst element For the linked list implementation if the stack is not empty which of the following statements in a main pro cedure can b e used to access the top element in the stack S a SElement b STopOfStack c STopOfStackElement d TopOfStackElement e none of the ab ove Answers C D E D C B D C B A C E Chapter Which of the following traversals requires more than linear time in the worst case a inorder b level order c p ostorder d preorder e all of these traversals are linear time In which of the following traversals is the no de pro cessed b efore the recursive calls to the children complete a inorder b level order c p ostorder d preorder e none of the ab ove What is the maximum number of no des in a binary tree with L leaves a L L b L+1 c d there is no maximum e none of the ab ove Which of the following is true ab out the height of a no de a The height of a no de is one less than the height of its parent b The height of an empty tree is c The height of a leaf is d The height of a tree can b e larger than its depth e all of the ab ove are false The rst child next sibling implementation a allows easy access to the parent b is appropriate for binary trees c uses C p ointers p er no de where C is the number of children d all of the ab ove e none of a b and c Which traversal computes the total size of each directory in the UNIX le system a inorder b level order c p ostorder d preorder e two or more of the ab ove traversals could b e used Let CX b e the number of leaves in a binary tree ro oted at T Assume that IsLeafT returns if T is a leaf Which of the following observations leads to a recursive implementation a CTCTLeftCTRight b CTCTLeftCTRight c CTCTLeftCTRightIsLeafT d CTCTLeftCTRightIsLeafT e none of the ab ove Which traversal do es not use a stack a inorder b level order c p ostorder d preorder