ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 24 May 2017 My Price 8.00

Code fragment 1

Code fragment 1:

for (int k = list1.size() - 1; k >= 0; k--) {
    list2.add(list1.remove(k));
}

Code fragment 2:

while (!list1.isEmpty()) {
    list2.add(list1.remove(0));
}

In this question you will be asked to analyze the worst-case time complexity of each of the code fragments given different implementations of the List ADT. For each analysis, you should assume that list1 starts out with N items and list2 starts out empty. You may further assume that each implementation includes a numItems data member that is updated and used appropriately.

Express your complexities using "Big-O" notation and briefly justify your answers.

  1. Assume that list1 and list2 are ArrayLists where both arrays have enough unused space so that they never need to be resized during the operations performed by either of the code fragments.
    1. What is the worst-case time complexity of code fragment 1?
    2. What is the worst-case time complexity of code fragment 2?
  2. Assume that list1 and list2 are LinkedLists where the LinkedList class has been implemented as a circular, singly-linked chain of nodes with a reference to the tail.
    1. What is the worst-case time complexity of code fragment 1?
    2. What is the worst-case time complexity of code fragment 2?
  3. Assume that list1 and list2 are LinkedLists where the LinkedList class has been implemented as a doubly-linked chain of nodes with references to the head and to the tail.
    1. What is the worst-case time complexity of code fragment 1?
    2. What is the worst-case time complexity of code fragment 2?

Answers

(11)
Status NEW Posted 24 May 2017 08:05 AM My Price 8.00

-----------

Not Rated(0)