{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cs1713_exam2_sol

# cs1713_exam2_sol - CS 1713 Exam 2 Solutions — Fall 2006...

This preview shows pages 1–2. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 1713 Exam 2 Solutions — Fall 2006 l) (10 points) a)3b)-1c)“Cde"d)"efGH“e)'e' 2) (10 points) public double cloneArray(double array) { double newArray; newﬁrray = new doub1e[array.1ength]; for (int i=0;i<newnrray.1ength;i++) newArray[i] = new doub1e[array[i].1ength]; for (int i=0;i<newArray.1ength;i++) for (int j=0;j<newArray[i].1ength;j++) newArrayIi] [j] = arrayti] [i]; return newArray; 1 3) (20 points) a public int 1inearSearch(String array, String target) ( for (int i=0;i<array.1ength;i++) if (array[i].equals(target) return i; return -1; ) b) public int binarySearch(String array, String target) ( int low = 0; int high = array.1ength - 1; while (low <= high) { int mid = (low + high)/2; if (array[mid].equa1s(target)) return mid; else if (array[mid].compareTo(target) < 0) low = mid + 1; else high = mid - 1; } return -1; } 1 4) (5 points) a) 20 seconds b) 40 seconds 0) a little more than 10 seconds. 5) (15 points) public static int findMinPosition(double list, int start) { int min = start; for (int scan = start + 1; scan < 1ist.1ength; scan++) if (1ist[min] 9 1ist[scan])) min = scan; return min; y V 6) (20 points) z_7—5- 7) (20 points) Selection Sort "abc def" list[0] [11st11] list[2] 1. -37 24 13 11 Insertion Sort L13 7 24 7 11 7 11 l_13 7 13 7 11 13 ‘4 —f— 7 11 13 7 list[0] f list[l] 1151;12] 11st13] list[4] list[5] list[6] ,_ 37 24 __ 13 19 11 17 24 I 37 13 19 7 8311 17 13 24 T 37 19 8311 1 17 13 19 24 37 7 8311 17 7 13 19 24 I 37 83 11 17 7 13 19 24 37 83 11 17 7 11 13 19 24 P 37 83 17 7 11 13 17 19 24 37 83 ...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern