Data Structures and Algorithms with Object-Oriented Design Patterns in Python
next up previous index

Performance Comparison: SortedListAsArray vs. SortedListAsList

The running times calculated for the various methods of the two sorted list implementations, SortedListAsArray and SortedListAsLinkedList, are summarized below in Table gif. With the exception of two methods, the running times of the two implementations are asymptotically identical.

 

 

sorted list implementation

SortedList- SortedList-
method AsArray AsLinkedList
__contains__ O(n) O(n)
find tex2html_wrap_inline59347 tex2html_wrap_inline61127 O(n)
findPosition tex2html_wrap_inline59347 tex2html_wrap_inline61127 O(n)
__getitem__ O(1) tex2html_wrap_inline61127 O(n)
insert O(n) O(n)
withdraw O(n) O(n)
Cursor.datum O(1) O(1)
Cursor.withdraw O(n) O(n)
Table: Running times of operations on sorted lists.

Neither the SortedListAsArray nor SortedListAsLinkedList implementations required any additional instance attributes beyond those inherited from their respective base classes, OrderedListAsArray and OrderedListAsLinkedList. Consequently, the space requirements analysis of the sorted list implementations is identical to that of the ordered list implementations given in Section gif.


next up previous index

Bruno Copyright © 2003, 2004 by Bruno R. Preiss, P.Eng. All rights reserved.