Patrick Y.3,052 Points
Trying to understand the Code Challenge : Changing Course
I have a hard time understanding why we need to create a map first.
So in the upcoming code challenge, it asks us to create a map with video names as key, and the actual video as the value, and then use it to find a video and change its name.
Why cant we just go thru the course videos one by one to find the video with the desired title, and then change its name? Making a map seems like an extra step.
Appreciate any explanations. Thank you.
Kristian Gausel14,646 Points
So, this question is all about datastructures. The reason is that the lookup time in a hashmap is O(1) (big-o-notation: https://en.wikipedia.org/wiki/Big_O_notation) and looping through an array and checking the name one by one is O(n). This results in a much worse performance for large collections. Note that the lookup time for hashmaps is only good if you actually know the "key" for the item you want.
To understand this properly you need to take a course in datastructures, or maybe treehouse has some courses covering this topic (?)