assignment 3.doc - Chapter 3 10 points 1 Why is inserting...

This preview shows page 1 - 2 out of 3 pages.

We have textbook solutions for you!
The document you are viewing contains questions related to this textbook.
Java Programming
The document you are viewing contains questions related to this textbook.
Chapter 9 / Exercise 18
Java Programming
Farrell
Expert Verified
Chapter 310 points1. Why is inserting into an array considered slow compared to insertinginto a linked list?
15 points2. What is the Big-O running time of the following code fragment?Assume lst1 has N items, and lst2 and lst3 are initially empty.public static void add( List<Integer> lst1, List<Integer> lst2, List<Integer> lst3){for ( Integer x : lst1 ){lst2.add(0, x); // add to frontlst3.add(x); // add to end}}a. If an ArrayList is passed for lst1 and lst2. Explain your answer.b. If a LinkedList is passed for lst1 and lst2. Explain your answer.
b) Linked List : Adding an element in the front of a linked list is O(1). Thereforetotal time complexity is O(N).
We have textbook solutions for you!
The document you are viewing contains questions related to this textbook.
Java Programming
The document you are viewing contains questions related to this textbook.
Chapter 9 / Exercise 18
Java Programming
Farrell
Expert Verified

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture