Download presentation
Presentation is loading. Please wait.
Published byGervase Lynch Modified over 6 years ago
1
15-111 Advanced Programming
Mid Term Review 15-111 Advanced Programming Ananda Gunawardena 8/2/2018
2
Midterm Topics Lists – Arrays and Linked Lists Basic Java Constructs
Singly, doubly, circular, Multilinked Lists Complexity of Algorithms Interfaces Strings Recursion 8/2/2018
3
What to Bring to test One page of Notes – both sides ok
No computers or PDA’s Pencil and Eraser You can access Java API Some memory 8/2/2018
4
Arrays Using ArrayList API methods complete the following method that returns true if there are duplicates in the array A of Comparables public boolean duplicates(ArrayList A) } 8/2/2018
5
Complexity Determine the complexity of the following algorithms using O(1), O(n), O(log n) and O(n2). Justify your answer in each case. Printing a linked list of size n Printing a singly linked list of size n in reverse Finding the largest entry on a sorted list Making a non-circular linked list circular Reversing a linked list 8/2/2018
6
Linked Lists Suppose L is a linked list of size at least 2, the references to two adjacent nodes are given by N and M. Write one (or may be two) lines of code to accomplish the following. Assume Node class has two public fields, data (Comparable) and next(Node) Insert a new Node O between N and M Insert a new Node O after M Delete the nodes N and M Move the node M to the beginning of the list 8/2/2018
7
Recursion What is the output given by following recursive function if foo(4) is called? Public void foo(int n) { if (n>0){ foo(n-1); System.out.println(n); } 8/2/2018
8
Debugging public int sum(int n){ int i=0; while (i<=n){ int sum=0;
What is wrong with the following code? (if any). The method is supposed to find the sum = 1+2+…+n public int sum(int n){ int i=0; while (i<=n){ int sum=0; sum += ++I; } return sum; 8/2/2018
9
Doubly Linked Lists Assume M is a node in a doubly linked list. Assume we have next and prev references. Write the code to Swap M and its successor (assume M has a non-null successor) Insert M to the beginning of the list 8/2/2018
10
ArrayLists Suppose A is an ArrayList of comparables. Write the code to find the max of A 8/2/2018
11
Arrays vs Linked Lists List two advantages of Arrays over Linked Lists
8/2/2018
12
Arrays vs Linked Lists List two advantages of Linked Lists over Arrays
8/2/2018
13
Strings Using String API methods, reverse a String S 8/2/2018
14
Recursion Write a recursive definition that returns the number of 1s in the binary representation of N. Use the fact that this number equals the number of 1s in the representation of N/2, plus 1, if N is odd. 8/2/2018
15
Complexity What are the time complexities of the following loops?
(a) for (i=0;i<n;i++) for (j=0; j<n; j \= 2) { something} (b) for (i=0; i<n; i++) swap(A[i],A[n-i-1]) 8/2/2018
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.