I am struggling to wrap my head around Big O notation and saw the following problem online. I must answer determining whether the following code is O(n), O(n²), O(logn), O(nlogn)
I have watched several videos but am still failing to understand Big O. Can someone please advise to the answer and their methodology for getting there?
function sortSmallestToLargest(entries):
sorted_entries = {};
while entries is not empty:
smallest_entry = entries[0]
foreach entry in entries:
if (entry < smallest_entry):
smallest_entry = entry
sorted_entries.add(smallest_entry)
entries.remove(smallest_entry)
return sorted_entries
sorted_entries.add(smallest_entry)inside the for loop, or perhaps the if? We can't tell.