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

  Function will remove the last element from the list.

This function will remove the last element from the list. If the list currently empty then the program will display some sort of error message e.g., "Unable to remove student because class is currently empty."

  Explaining use of encryption-virus and vpn

Write down the suitable example of best use of Encryption, Virus, VPN, Firewall securities, when and explain why?

  Definiteness is one of the properties of an algorithm

Using suitable word or phrase fill up the blanks in the following sentences.

  Build a dynamic and functional model

Write 2 to 3 page paper that explains the difference in steps used to build a dynamic and functional model as each relates to object-oriented modeling

  Finding page faults for lru replacement algorithms

How many page faults would happen for the given replacement algorithms, assuming one, two, three, and four frames?

  Does a deterministic algorithm exist for the given case

Does a deterministic algorithm exist for this case? Give a randomized algorithm that is partially correct, process-term­ inates with probability one.

  Infinite number of optimal dynamic-priority scheduling algo

Show that there exist an infinite number of optimal dynamic-priority scheduling algorithms. (Hint: Use the fact that both EDF and LLF are optimal).

  Write the parametric form of the unit circle

Write the parametric form of the unit circle. Given an arbitrary positive integer n, write an algorithm that generates n evenly spaced points that are sampled along the unit circle

  Give a recursive definition of a singly linked list

Give a C++ code fragment that, given an×n matrix M of type float, replaces M with its transpose. Try to do this without the use of a temporary matrix.

  An embedded system is a computer system performing

an embedded system is a computer system performing dedicated functions within a larger mechanical or electrical system.

  Show that the vertex of largest degree in bk is the root

Show that the vertex of largest degree in Bk is the root. A rooted tree T is called an Sk-tree if it satisfies this recursive definition.

  Data is an array of objects.

jQuery App1. The data is an array of objects. It's easier to make this a global variable. a. You should have three items in the list when the page loads.

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