




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
The questions and answers for exam 1 of the advanced programming/practicum course, focusing on java programming. It includes multiple-choice questions covering java basics such as programming language features, classes, arrays, and algorithms. Part ii and iii of the exam deal with the complexity of algorithms and linked lists, respectively.
Typology: Exams
1 / 8
This page cannot be seen from the preview
Don't miss anything!
15-200/111 Advanced Programming/Practicum Exam 1 (100 points) 80 minutes
Name: _________________________________ Section: _____________ This is a closed book exam. However, you are allowed one page of notes.
a. B is an exact copy of A b. B and A refer to the same array c. B is an illegal declaration d. none of the above
for (int i=0; i < n ; i += 2) for (int j = 0 ; j < n/2; j++) Statement1;
How many times statement1 will be executed? Give the answer in Big O.
a. Finding maximum element in an unsorted array
b. Finding an element in a sorted array using binary search
c. Reversing an array of integers
(2) The following function is supposed to return the length of a singly linked list. The code may or may not have errors. Identify errors(if any) and fixโem. Rewrite the method in the box provided.
public int length(Node Head) { int size = 1; Node cur; while(cur != NULL){ size++; cur = cur.next; } }
(3) Write a method insertNextTo(Node N, Node M) that inserts Node N next to Node M. You may assume the following node class. class Node { public int data; public Node next; } For example if the current list is 2 4 3 5 null after calling insertNextTo(seven, three) we have the list: 2 4 3 7 5 null
public void insertNextTo(Node N, Node M) {
protected static final int n ; // width of the grid protected static final int m ; // width of the grid protected int[][] g =new int[m][n]; // actual board g contains either 1โs (if the sum of the indices is odd) or 0โs(if the sum of the indices is even). For example g[0][1]=1 and g[0][0]=0 etc. 0 is considered even.
Public String toString( ) {
}
try { BufferedReader is = new BufferedReader(new InputStreamReader(System.in)); String inputLine; while ((inputLine = is.readLine()) != null) { System.out.println(inputLine); } is.close(); } catch (IOException e) { System.out.println("IOException: " + e); }
Write a method equivalent( MyLinkedList L) that returns true if this list is similar to list L. Two lists are equivalent if one is a permutation of the other. You may assume both lists have distinct elements. You can also use compareTo see if two nodes are equal. For example: 1 2 3 4 null and 4 2 1 3 are equivalent lists. You must consider all special cases. No partial credit for this problem.
public boolean equivalent(MyLinkedList L) {