View the step-by-step solution to:

Question

Need help with 1and 2 please!

alt="71769613_2206860139611024_1691249544391557120_n.jpg" /> please!71491891_691858011318956_3724563087534063616_n.jpg

71491891_691858011318956_3724563087534063616_n.jpg

1. (6 points) State the worst case and average case running times of the methods below. For full
credit provide brief explanations.
(a) public ArrayList<Integer> populateList (int n) {
ArrayList<Integer> list = new ArrayList<Integer>() ;
for (int 1=0; 1< n; it+)
list . add (i) ;
return list;
(b) public ArrayList<Integer> populateList (int n) {
ArrayList<Integer> list = new ArrayList<Integer>() ;
for (int i=0; i< n; it+)
list . add (0, i) ;
return list ;
(c) public int getLargerValue (ArrayList<Integer> list, int i, int j) {
int ans -
if (list . get (i) > list.get (j) )
ans= list. get (i ) ;
else
ans - list . get (i ) ;
return ans;
2 . (8 pts) In the following code, assume that head is the head of a linked list and it is an object
of type Node.
Node prev - head;
Node cur = prev. next;
while ( cur ! =null) <
Node temp - cur . next;
cur . next - prev;
prev = cur;
cur = temp;
head. next - null;
tail - head;
head - prev;
MacBook Pro

71769613_2206860139611024_1691249544391557120_n.jpg

(a) [4 points] Suppose the linked list looks like this initially: A > B > c> D->E. What will
it look like after the code above executes?
(b) [2 points] The code above will produce a null pointer exception if the list is empty. Which
line of the code will produce this error and why it is produced.
(c) [2 points] What is the Big-O running time of the code above assuming that the list has n
items?
For each of the following problems, make sure your implementation works when the list is
empty, has one element and multiple elements.
3. [8 points]
(a) (6 pts) Complete the contains method on page 917 of your textbook. You may assume
that the elements of your list have a equals method.
(b) (2 pts) What is the running time of your method in Big-O terms. Give a brief reason.
4. [8 points]
(a) Complete the method removeFront below which takes the head of a linked list and an
int num and removes the first num elements from the list. Your method cannot use any
calls to remove.
public void removeFront (Node head, int num) {
(a) (2 pts) What is the running time of your method in Big-O terms. Give a brief reason.

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes