Final Exam - University of Texas at Austin



Exam 2EE 422C - University of Texas at Austin - Spring 2015Name ___________________________ EID __________________ Lab day/time_____________Test taking instructions. No calculators, laptops or other assisting devices are allowed. Write your answers on these sheets. Wherever code is required, write JAVA statements in the blank areas provided, or by modifying the given code in place. You are not required to follow the coding style guidelines when writing code on the exam, but be as neat as possible. If you are unsure of the meaning of a specific test question, then write down your assumptions and proceed to answer the question on that basis. If you see a typo or syntax error, fix it, circle it, and if you are right you will get a bonus point for each one fixed. In your programming solutions on this test you may use any of the classes/methods that you know from the library, or JCF. Questions about the exam questions will not be answered during the test.For the binary tree related questions on this exam you may assume that this generic class has been defined for your use and is included. When the term Btnode is used on the exam it is referring to this generic class (e.g. in Question 5).class Btnode<T>{ /* this generic class models a node of a binary tree */ /* here are the private data members of the binary tree node */ private T element; private Btnode<T> left; private Btnode<T> right; private Btnode<T> parent; /* the constructor given an element,left child,right child & parent */ Btnode(T theElement, Btnode<T> lt, Btnode<T> rt, Btnode<T> pt ) { element = theElement; left = lt; right = rt; parent = pt; } /* here are the public get/set methods for the data members */ public T getElement( ){ return element;} public Btnode<T> getLeft( ) {return left;} public Btnode<T> getRight( ){return right;} public Btnode<T> getParent( ){return parent;} public void setElement( T x ){element = x;} public void setLeft( Btnode<T> t ) {left = t;} public void setRight( Btnode<T> t ){right = t;} public void setParent( Btnode<T> t ){parent = t;} }Question 1. Terminology. [22 pts.] Answer each of the following questions by choosing the best answer from the list below. ____A search algorithm that is O(log log n) for an ordered array ____A data structure used to convert an infix expression to postfix notation ____A sorting technique that requires NO comparisons ____A systematic approach to trial and error solution searching ____A data structure that has the same data structure as a component ____A collection of nodes with each one linked to its parent, and a single root on top ____A binary tree that represents variable length character codes for compression ____The average case search time in a Binary Search Tree (BST) ____The BST traversal that produces an ordered sequence ____A BST is best when inserts are at the leaves and there are not too many internal of these operations. ____On average log n + .25 comparisons are needed to insert into this type of BST. ____A data structure developed to store indexes into databases on disk ____A best sorting method in terms of worst case number of comparisons and minimum space utilization ____A control abstraction that splits a process into multiple parallel processes ____The synchronization problem that occurs when 2 threads want to use 2 resources, but each thread has 1 resource locked and needs the other resource ____A synchronized data structure that implements a queue that will wait if needed to perform enqueue and dequeue operations ____A directed graph that contains no cycles ____The inventor of the shortest path algorithm for a weighted digraph ____The inventor of the minimum spanning tree algorithm for a weighted graph____ Where the classes for drawing basic graphical shapes are found____ For GUI’s the screen and various windows are made up of these individual elements____ The language used to render web pages within a browser window ArrayListArrayBlockingQueueAVLAWTbacktrackingB-TreeDAGdeadlockdeletesdequeDijkstraduplicatesexpression treeforkhashing functionheapsortHTMLHuffmaninfinite loopinorderinterpolationLinkedListLISPListload factormakeHeapmergesortNewtonO(log n)O(n)pixelsPriority QueuePrimputrace conditionradixrecursiveStacktopological sorttreeTreeSetQuestion 2 - Multiple Choice. [2 pts. each - 8 pts total] For each of the following subparts, circle the best or all correct answers as indicated.A. Which of the following sorting algorithms have a average-case performance that is better than O(n2)?Selection sortBubble sortShell sortMerge sortHeap sortQuick sortRadix (bin) sort B. Given three arrays with L, M and N elements respectively, estimate the running time for the following algorithm in terms of the number of times that the do something step is executed: repeat the following for items i from 1 to N for array1 repeat the following for items j from 1 to M for array2repeat the following for items k from 1 to L for array3 do somethingend repeat end repeatend repeatO (L+M+N)O ( N 3 ) O ( L * M * N )None of the aboveC. Which of the following statements are true of heaps?It is a binary treeIn terms of its shape, it must be completeIt can be either a maximal or a minimal heapThe value of the root has no relationship to the value of any other nodesIs useful for implementing a stackIs the most efficient representation for a priority queueD. A method uses the selection sort algorithm to sort an array of doubles. The method takes 5 seconds to complete given an array with 10,000 distinct elements in random order. What is the expected time in seconds for the method to complete given an array with 30,000 distinct elements in random order?102510020None of the aboveQuestion 3. Recursion (6 points) A. [4 pts] Write a recursive algorithm (not code) that determines whether a specified target character is present within a string. It should return true if the target is found and false if not. The stopping conditions should be:A string reference to null or a string of length 0, the result is falseThe first character in the string matches the target, the result is trueThe recursive step would involve searching the rest of the string for the target.B. [2 pts] What is returned by the method call a(2) ? _________ public int a(int x) { if(x > 20) return x; else return x + a(x * x + 1);} Question 4 [4 Pts] You have an array with 1,000,000 distinct elements in random order.You have to search the array 100 times to determine if a given element is present or not.What will result in less work? Sorting the array with quicksort and then doing the searches using binary search OR just doing the searches with linear search. (without sorting)Justify your answer with calculations. Tip: log2 (1,000,000) ~= 20 Question 5. Tree questions (10 pts)(2 pts) Draw the binary tree created by the following statements. Btnode is defined on page 1.Btnode<Integer> root, a, b, c, d;d = new Btnode<Integer> (6, NULL, NULL, NULL);c = new Btnode<Integer> (9, NULL, d, NULL);b = new Btnode<Integer> (4, NULL, c, NULL);a = new Btnode<Integer> (12, NULL, NULL, NULL);root = new Btnode<Integer> (10, a, b, NULL); B. (3pts) Fill in the statements in the method below to perform an inorder traversal of a binary tree like the above. Print out the value of the node’s element as it is visited inorder. public static void inorder( Btnode<Integer> tree ){ if (tree == NULL) return; else { }} C. (5 pts) Consider the following binary search tree. Use the original tree below when answering each subpart (a) through (e).(a)If the value 54 is inserted into this tree, which node becomes its parent? __________________(b)If the value 27 is inserted into this tree, which node becomes its parent? ___________________(c)If we delete node 70, which node should be its replacement node? ___________________(d)If we delete node 25, which node should be its replacement node? __________________(e)If we delete the root node 50, which node should be selected as its replacement node so that the fewest number of changes are made to the tree? ______________________Question 6. Heaps and Graphs (16 pts)(3 pts) A heap can be represented by an ArrayList with the values stored in top down, level-by-level, left to right order. Start with the following maximum heap and list the elements after each operation. Execute the operations sequentially, using the result of the previous operation. The initial ArrayList values for this heap are {50, 35, 15, 12, 3, 5}. (a) Insert 17: The values in the ArrayList are now {____________________________________}.(b) Delete (pop) an element from the heap: The values are now {_________________________________}.B.(3 pts) Start with following tree and use the heapify algorithm to convert it into a maximum heap. Draw the resulting tree.C. (2 pts) Show the minimum cost path (and the total cost) from node A to node E in the following digraph G.D.(3 pts) Draw the adjacency list representation for the following digraph G.E. (5 pts) Draw the minimal spanning tree for the following graph G. What is the total cost?Question 7 (4 pts) AVL Treesa. [2 pts] Show that the below tree is indeed an AVL tree by writing in the balance indicators for each node of the tree (hint: balance indicator = hr – hl )1720215107950b. [2 pts] Now insert the word “keen” into the above tree and rebalance the tree as necessary so that it remains an AVL tree. Draw the new tree below.Question 8 (5 Pts) For the graph shown below determine the visit sequence for a breadth-first search beginning at node 3. Show the changing queue contents for partial credit. 1834515115570Visit sequence = _____________________________________________________________________________________Question 9. [5 Pts] Given the Huffman code tree below, what does the given bit stream decode toWCXKDGiven bit stream (spaces added for clarity): 1 1 0 1 0 0 0 0 1 0 0 1 1 0 Question 10 [6 Pts].For the following digraph, use Diykstra’s algorithm to show the minimum cost path from node A to all other nodes. I have provided the initial table for A to all other vertices (v), and the initial d[v] and p[v] pairs. Recall that d[v] is the distance/cost of getting from A to v, and p[v] is the immediate predecessor node of v on the path from A to v. You will then derive the final table of d[v] and p[v] pairs which show the minimum cost paths and the immediate predecessor nodes. Show your intermediate work for getting from the initial table to the final table for partial credit. Initial Tablevd[v]p[v]B10AC∞AD∞AE40AFinal Tablevd[v]p[v]BCDEQuestion 11 [5 pts] Consider the following applet with an embedded thread. Describe the order in which ALL the various methods are executed by the JVM.import java.awt.*;import java.applet.*;/* <applet code="Banner" width=300 height=50> </applet> */public class Banner extends Applet implements Runnable { String msg = " A Moving Banner."; Thread t = null; int state; boolean stopFlag; public void init() { setBackground(Color.cyan); setForeground(Color.red); } public void start() { t = new Thread(this); stopFlag = false; t.start(); } public void run() { // Display banner while (true) { try { repaint(); Thread.sleep(250); if(stopFlag) break; } catch(InterruptedException e) {} } } public void stop() { stopFlag = true; t = null; } public void paint(Graphics g) { char ch; ch = msg.charAt(0); msg = msg.substring(1, msg.length()); msg = msg + ch; g.drawString(msg, 50, 30); }}Question 12 [5 Pts] Consider the following mouse event handling code. Add in the code necessary to draw a small square at the position where the mouse was clicked in the applet window. Also describe in words the purpose of the highlighted code statements.import java.applet.Applet;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.event.MouseListener;import java.awt.geom.*;public class MouseSpyApplet extends Applet{ public MouseSpyApplet() { MouseSpy listener = new MouseSpy(); addMouseListener(listener); } public void paint(Graphics g) { Graphics2D g2 = (Graphics2D)g; // fill in the rest of this method } class MouseSpy implements MouseListener { public void mouseClicked(MouseEvent e) {System.out.println ("Mouse clicked. x=" + e.getX() + " y=" + e.getY()); } // assume empty bodies for other 4 mouse listener methods }} Question 13. Multi-threading basics (4 pts)For the design of your assignment 6 ticket office program, answer the following questions.(2 pts) What constitutes a race condition? How can/did you avoid that in the current assignment?(2 pts) What constitutes a deadlock situation? How can/did you avoid that in the current assignment? ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download