TimeList

TimeList - Akshay Maheshwari CSE 12 10/19/10 ...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Akshay Maheshwari CSE 12 10/19/10 Time List Summary Array Front 1.4 Seconds 1.2 1 0.8 0.6 0.4 0.2 0 0 10000 20000 30000 40000 50000 Elements Added Although there is some error, the general patterns given by my data agree with what is expected. Adding elements to the front of an array has an O(n) time cost – one would expect a linear graph. This is because an array must push all the other n elements ahead of it to make room to add to the front. My data gives a roughly linear graph. It seems to be tilting slightly upwards, as in an exponential graph, but this may be due to the fact that with fewer elements being added there is less of a chance that extraneous processes generate noise. Array Back 0.0006 Seconds 0.0005 0.0004 0.0003 0.0002 0.0001 0 0 10000 20000 30000 40000 Elements Added 50000 60000 Akshay Maheshwari CSE 12 10/19/10 Time List Summary When adding elements to the back of an array, my data gave consistent results. Other than the few outliers observed in the beginning, which were probably a result of either the garbage collector or other initial processes, my data had a constant O(1) trend. This is because arrays have instant access to the back of an array. As expected, adding to the end of an array is much faster than adding to the beginning. Linked Back 3.5 Seconds 3 2.5 2 1.5 1 0.5 0 0 10000 20000 30000 40000 50000 Elements Added When adding to the back of the list12 singly-linked list, my data followed the expected linear graph. Because adding to the end of a singly-linked list takes O(n) time, it is theoretically linear. It takes O(n) time because to add an element to the end, the linked list must iterate through the entire list until it reaches the end. Although for the lower tests with only a couple of thousand elements being added the graph shows a slight curve, when more elements are added the graph straightens out. It is possible that once more than a certain amount of elements are added noise begins to get generated, boosting up the time taken. Akshay Maheshwari CSE 12 10/19/10 Time List Summary Linked Front 0.004 0.0035 Seconds 0.003 0.0025 0.002 0.0015 0.001 0.0005 0 0 10000 20000 30000 40000 50000 Elements Added Finally, when adding to the front of the list12 singly-linked list, my data showed, although with a couple of outliers, very good results. We saw, as expected, miniscule amounts of time being taken by the entire range of tests. The data clearly shows O(1) time being taken by the linked list. It takes constant time because linked lists begin at the head node. Thus, to add to the front of the linked list, the head node simply has to be linked to the new node and the new node’s next has to be linked to the old first node. It is likely that either the garbage collector or random processes suddenly being executed caused the few outliers in the graph. In order to get good, low-variance data I had to address the biggest uncontrollable process – the garbage collector. In all the tests I made sure to call the garbage collector before the timer started ...
View Full Document

This note was uploaded on 08/11/2011 for the course CHEM 140A taught by Professor Whiteshell during the Spring '04 term at UCSD.

Ask a homework question - tutors are online