Question

I need to derive the big-O notation of this validation program. Its job is to accept product entries of this type: 'jacket,8,12,18,16,6', validates it, sort the sizes, sort the entry into a list by alphabetical order and print the new list after each entry.

The Big-O notation is based on the worst-case scenario, which is when a program takes the longest time to execute for a particular input. Taking ‘parseData’ method, the worst-case is when the input is fully valid, therefore none of the exceptions are passed and all the method is executed. The product name has 15 characters and 5 sizes are entered. In this scenario, this method and the other smaller validation methods below will always take the same period to execute this worst case event. This gives them O(1) complexity as indicated in the comments.

In the main, there is; - validation - O(n) - sorting - O(nlogn) - printing - O(n^2)

Would this boil down to O(n^2)? Or does it depend on the number of entries considered?

Était-ce utile?

La solution

for asymptotic analysis it would boil down to O(n^2), as it grows much faster than O(n logn) and O(n). but be aware that this is just an asymptotic upper bound, that means it might be not really tight, also as you say, its worst case and not average or expected case.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top