COSI 12b Lecture Notes - Lecture 11: Time Complexity

71 views2 pages

Document Summary

Shifting elements, via adding or removing, can significantly slow the program. Arraylists internally store data in an array it is very good at reading a specific element at a specified position. Reading and replacing elements has constant time o(1). The program will run at the same speed regardless of the number of elements. Adding an element or removing an element from a specific index that causes shifting runs on linear time o(n). In linear time the number of elements affects speed. Linkedlist internally stores data as a sequence of nodes. It adds elements to the front of a list faster than arraylist by not shifting the elements (each of which is an object in a linkedlist). However, it is slower than arraylist when adding/removing in the middle of the list. Additionally, it is slower at looping through elements because it will start from index 0 every time. Iterators can be used to solve this problem.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents