Beruflich Dokumente
Kultur Dokumente
Introduction
For this assignment I used NSMutableArray, NSMutableDictionary, and NSMutableSet to
compare their respective runtime complexities with Insert, Indexing, Searching, and Deleting.
These data structures are part of Apples Foundation Framework used with the Objective-C
2.0 programming language. NS stands for NextStep, which Apple bought when Steve Jobs
got hired back as Apples CEO. The Mutable part means what it sounds like, you can add
and remove items from them. I am an Apple guy and I would very much like to get a job
programming iOS or Mac OSX programs. I feel that doing these data structure assignments
in Objective-C will help me further my understanding of the language and hopefully will aid
me in getting a job one day.
Inserting Tests
2500
2000
1500
Time in milliseconds
1000
500
NSMutableArray
NSMutableDictionary
NSMutableSet
After Inserting 1,000,000 items we clearly see that NSMutableArray takes the win with the
fastest inserting, followed by NSMutableSet, then NSMutableDictionary. One thing to note is
that NSMutableDictionary is inserting a key and a value. However, NSMutableArray took a
messily 52 milliseconds and NSMutableDictionary took 1930! Again, when you look at the
big picture less than two seconds to enter 1,000,000 keys and values isnt all that bad but is
something to consider when choosing a data structure to use when you will be inserting a lot
of items.
Indexing Tests
Indexing through 1,000,000 items didnt take any of these data structures very long at all.
NSMutableArray at 4, NSMutableSet at 9, and NSMutableDictionary at 16. For 1,000,000
items that is such a small number I really cant say one has a significant advantage over
16
12
Time in milliseconds
8
NSMutableArray
NSMutableDictionary
NSMutableSet
Searching Tests
When it comes to searching, NSMutableDictionary and NSMutableSet tied, followed by
NSMutableArray. The only time the search for NSMutableDictionary was actually
measurable was when the item I was searching for wasnt in the dictionary to begin with.
NSMutableSet was in a similar boat but I was able to record one millisecond when searching
for the very last item in the set. NSMutableArray lost this battle big time com
60
45
30
Test 1 in milliseconds
Test 2 in milliseconds
Test 3 in milliseconds
Test 4 in milliseconds
15
NSMutableArray
NSMutableDictionary
NSMutableSet
pared to the other two data structures. 55 milliseconds to find the very last, and a number not
in the array. The thing to note from this test is, is that no matter the size of the dictionary or
set, searching is instant! The array has to index through itself and then checks if the current
index is equal to the item being searched. If you had an array with billions of items, then your
searching could take significantly longer.
Deleting Tests
70
52.5
35
All items
One item
17.5
NSMutableArray
NSMutableDictionary
NSMutableSet