What is big-oh running time for an arraylist and linkedlist

Assignment Help Data Structure & Algorithms
Reference no: EM131662127

Question: The RandomAccess interface contains no methods but is intended to serve as a marker: a List class implements the interface only if its get and set methods are very efficient. Accordingly, ArrayList implements the RandomAccess interface. Implement static method removeEveryOtherItem, described in Exercise. If list implements RandomAccess (use an instanceof test), then use get and set to reposition items at the front half of the list. Otherwise, use an iterator that is efficient for linked lists.

Exercise: Static method removeHalf removes the first half of a List (if there are an odd number of items, then slightly less than one-half of the list is removed). One possible implementation of removeHalf is shown below:

public static void removeHalf( List<?> lst )

{

    int size = lst.size();

    for( int i = 0; i < size/2; i++ )

           lst.remove( 0 );

}

a. Why can't we use lst.size( )/2 as the test in the for loop?

b. What is the Big-Oh running time if lst is an ArrayList.

c. What is the Big-Oh running time if lst is a LinkedList.

d. Suppose we have two computers, Machine A and Machine B. Machine B is twice as fast as Machine A. How would the running time for removeHalf on Machine B compare to Machine A if Machine B is given an ArrayList that is twice as large as the ArrayList given to Machine A?

e. Does the one line implementation:

public static void removeHalf( List<?> ist )

{

     ist.subList( 0, lst.size( ) / 2 ).clear();

}

work, and if so, what is the Big-Oh running time for both an ArrayList and a LinkedList?

Reference no: EM131662127

Questions Cloud

Restatement of the law of contracts : What is the Restatement of the Law of Contracts, and why was it necessary?
What readers might not agree with wildes arguments : Gwen Wilde's Why the Pledge of Allegiance Should be Revised. What readers might not agree with Wilde's arguments? What values do they hold?
Discuss how would you assess the patients learning needs : Then consider the adult population, and imagine you are beginning to develop a teaching plan to address the needs of a specific individual
Coming month from marketing department : A producer of felt-tip pens has received a forecast of demand of 31,000 pens for the coming month from its marketing department.
What is big-oh running time for an arraylist and linkedlist : The RandomAccess interface contains no methods but is intended to serve as a marker: a List class implements the interface only if its get and set methods.
How are the stakeholders valuable to the organization : Post a brief description of a human services organization in your community. Then, describe two potential stakeholders related to the organization.
Discuss what is the function of the g-suit : What is the importance of the Stoll curve as it applies to acceleration physiology
What communication strategies can professional nurses use : What communication strategies can professional nurses use to specifically promote collaboration with other healthcare disciplines
Discuss priority populations : Review the Agency for Healthcare Research and Quality (AHRQ) report Priority Populations

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Implement an open hash table

In this programming assignment you will implement an open hash table and compare the performance of four hash functions using various prime table sizes.

  Use a search tree to find the solution

Explain how will use a search tree to find the solution.

  How to access virtualised applications through unicore

How to access virtualised applications through UNICORE

  Recursive tree algorithms

Write a recursive function to determine if a binary tree is a binary search tree.

  Determine the mean salary as well as the number of salaries

Determine the mean salary as well as the number of salaries.

  Currency conversion development

Currency Conversion Development

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Design a gui and implement tic tac toe game in java

Design a GUI and implement Tic Tac Toe game in java

  Recursive implementation of euclids algorithm

Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (GCD) of two integers

  Data structures for a single algorithm

Data structures for a single algorithm

  Write the selection sort algorithm

Write the selection sort algorithm

  Design of sample and hold amplifiers for 100 msps by using n

The report is divided into four main parts. The introduction about sample, hold amplifier and design, bootstrap switch design followed by simulation results.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd