Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A. (3 points) Consider the methods get (index), add (element), and remove (index) from the java.util.List API. For each of these methods, is there ever

image text in transcribed

A. (3 points) Consider the methods get (index), add (element), and remove (index) from the java.util.List API. For each of these methods, is there ever a situation where the method will run faster for an ArrayList than for a LinkedList? Briefly explain Assume the LinkedList is implemented a head pointer and no other instance variables (no size!);that is, it is a singly linked list, and that the ArrayList's backing array is large enough to hold the new element (no enlarge() needed). Also assume each of the following operations takes the same amount of time: array lookups, setting elements of arrays, creating new nodes, traversing a single link in a linked list, and assigning a reference (ex, calling setNext on a node). B. (2 points) Write a public List mergeLists (List s1, List s2) method that correctly merges two List lists s1 and s2 together. To correctly merge two lists, the method must make a third list that alternates the values from s1 and s2. The lists might not be the same length, so you must check to see all values are included from the longer list. Assume both lists are non-null, though one or both may be empty Example 1: Inputs: Returns: { "a", "b", "c", "d", "e", "f",, "h", "1", "j " } Example 2: Inputs: Returns: "p","r", "o,"d,"a","w","j

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions