DOC PREVIEW
UT CS 307 - Exam Guide

This preview shows page 1-2-3-4-5-6 out of 17 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 307 – Midterm 2 – Spring 2010 1 Exam Number: Points off 1 2 3 4 5 Total off Net Score CS 307 – Midterm 2 – Spring 2010 Name__________________________________________ UTEID login name _______________________________ TA's Name: Guillermo Reza Shyamala (Circle One) Instructions: 1. Please turn off your cell phones and other electronic devices. 2. There are 5 questions on this test. 3. You have 2 hours to complete the test. 4. You may not use a calculator on the test. 5. When code is required, write Java code. 6. When writing methods, assume the preconditions of the method are met. Do not write code to check the preconditions. 7. On coding question you may add helper methods if you wish. 8. After completing the test please turn it in to one of the test proctors and show them your UTID. 1. (2 points each, 30 points total) Short answer. Place you answers on the attached answer sheet. • If the code contains a syntax error or other compile error, answer “compile error”. • If the code would result in a runtime error / exception answer “Runtime error”. • If the code results in an infinite loop answer “Infinite loop”. Recall that when asked for Big O your answer should be the most restrictive correct Big O function. For example Selection Sort has an average case Big O of O(N2), but per the formal definition of Big O it is correct to say Selection Sort also has a Big O of O(N3) or O(N4). I want the most restrictive correct Big O function. (Closest without going under.) A. Allen Rabinovich of Yahoo was a guest speaker in our class. What did Allen recommend about commenting code and programs you write for your own use? What was the basis of his recommendation? B. Allen is the Senior Architect for the Yahoo User Interface (YUI), a library of utilities and controls for building interactive web applications. The library is open source, meaning the source code is available for all programmers to use and extend in any way they wish. Allen made the claim that making YUI open source was actually a selfish thing for Yahoo to do. Explain, according to Allen, why making YUI open source is actually a selfish thing to do.CS 307 – Midterm 2 – Spring 2010 2 C. What is returned by method c(5)? public int c(int x){ if(x <= 0) return 3; else return x + c(x - 2); } D. What is output by the method call d("leakey")? Recall the substring method: public String substring(int beginIndex) Returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string. public void d(String s){ if(s.length() <= 2) System.out.print(s); else{ System.out.print(s.charAt(0)); d(s.substring(2)); System.out.print(s.charAt(s.length() - 1)); } } E. What is returned by the method call e(6); public int e(int x){ if(x <= 3) return x; else return 2 * x + e(x - 1) + e(x - 3); } F. What is the Big O of method f? N = list.length. public int f(int[] list){ int total = 0; for(int i = 0; i < list.length; i++) total += list[i]; for(int i = 0; i < list.length; i += 3) total += list[i]; return total; }CS 307 – Midterm 2 – Spring 2010 3 G. What is the worst case Big O of method g? N = list.length. public int g(int[] list){ int total = 0; int limit = list.length - 1; for(int i = 0; i < limit; i++) if(list[i] == list[i + 1]) for(int j = i + 1; j < list.length; j++) total += list[j] * i; return total; } H. What is the Big O of method h? public int[][] h(int N){ int[][] result = new int[N][N]; return result; } I. What is the best case Big O of method i? N = data.length. public double i(double[] data){ double result = 0; for(int i = 0; i < data.length; i++) for(int j = 1; j < data.length; j *= 2) if( data[j] == data[i] ) result += data[j]; return result; } J. What is the Big O of method j? N = org.length. The ArrayList constructor is O(1). public ArrayList<Double> j(double[] org){ ArrayList<Double> result = new ArrayList<Double>(); for(int i = 0; i < org.length; i++) result.add(0, org[i]); // 0 is the position to insert in the list return result; } K. What is the Big O of method showAll? N = list.size(). Assume the print method is O(1). public void showAll(LinkedList<Integer> list){ for(int i = 0; i < list.size(); i++) System.out.print( list.get(i) ); }CS 307 – Midterm 2 – Spring 2010 4 L. A sorting method uses the insertion sort algorithm. It takes 7 seconds for the method to sort 50,000 distinct ints in random order. What is the expected time for the method to sort 150,000 distinct integers? M. A method is O(Nlog2N). It takes 10 seconds for the method to run when N = 500,000. What is the expected run time when N = 2,000,000. Recall log2 1,000,000 ~= 20 N. A method is O(N). When N = 50,000 the method takes 20 seconds to complete. Given 5 seconds how many pieces of data can the method process? O. You have a 1,000,000 pieces of data that are unsorted. You expect to do 50,000 searches on the data before it changes. Should you sort the data with merge sort and then perform the 50,000 binary searches or just do 50,000 linear searches without sorting? Justify your answer mathematically.CS 307 – Midterm 2 – Spring 2010 5CS 307 – Midterm 2 – Spring 2010 6 2. (Array based lists, 20 points) Write a method for the GenericList class we developed in lecture that adds a given element after every occurrence of a target element. • The GenericList is generic based on Java's inheritance requirement and polymorphism, not the Java generic syntax. • GenericList's internal storage is a native array of Objects. There may be extra capacity in the array. • The array variable named elements will never equal null. • The elements of the list use 0 based indexing. The position of an element in the list is equal to its index in the array. • You may not use any other methods from the GenericList class unless you implement them yourself in this question. • You may not use any other Java classes except native arrays and the equals method from Object. Complete the following method in the GenericList class: /* pre: newValue != null, tgt != null, !newValue.equals(tgt) post: insert newValue into this GenericList after every


View Full Document

UT CS 307 - Exam Guide

Documents in this Course
Midterm 2

Midterm 2

15 pages

Midterm 1

Midterm 1

15 pages

Syllabus

Syllabus

24 pages

s

s

8 pages

Midterm 1

Midterm 1

14 pages

Midterm 2

Midterm 2

14 pages

Recursion

Recursion

14 pages

Midterm 1

Midterm 1

16 pages

Load more
Download Exam Guide
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Exam Guide and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Exam Guide 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?