So O(n2) would indicate that you are doing a set of operations on a set of operations- this commonly happens when you perform a for loop within a for loop. For example, if you have a 2D array with 5 rows and 5 columns and you use two for loops to scan through them to find a certain element, the number of operations you perform in the worst case is O(n2). n in this case is the length of the rows and columns so 5, and you go through each row 5 times and each column 5 times leading to a total of 25 checks which is n2 since 52=25.
Help Understanding Big O
I'm asking more about what this means to my code. I understand the concepts mathematically, I just have a hard time wrapping my head around what they mean conceptually. For example, if one were to perform an O(1) operation on a data structure, I understand that the amount of operations it has to perform won't grow because there are more items. And an O(n) operation would mean that you would perform a set of operations on each element. Could somebody fill in the blanks here? Like what exactly would an O(n^2) operation do? -And what the heck does it mean if an operation is O(n log(n))?
Follow
1
Add comment
More
Report
1 Expert Answer
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.