What is the time & complexity of the code below?
function SortFunction (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
I thought the time complexisty could be O(n^2) but there are different answers on the internet for similar situations, so I was confused. And what about the space complexity?
And an extra small question about this topic:
function PrintCol():
colours = { "Red", "Green", "Blue", "Grey" }
foreach colour in colours:
print(colour)
The time complexity here is O(n) since there is only one loop, right? Space complexity?