The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
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.