So I have a problem that is pretty simple. I have a list of numbers 1-N (iterating by 1) and one number in the list is missing. I'm trying to determine which of my two solutions is faster in terms of Big-Oh.
First algorithm: Sort the list, then iterate over the list one number at a time until you find a number that is more than 1 number larger than the last number. The number that is missing has been found at that point.
Second algorithm: I keep the list as is. I make another array that is all the numbers 1-N already sorted. I iterate over each number in this new list and compare it to the numbers in the original list. Once I find the number in the original list, I remove that number from the list (and decrement the size of that list while doing so, let's say this is a dynamic data structure). I do this for every number. If a number goes through the entirety of the list and the list is the same size, that is the missing number.
I would think that algorithm 2 would be faster, just because it's decrementing the size of the list and only doing at most 1 full pass and at best it should be O(1) (if you hit the number your searching for right off the bat).
The first algorithm would be O(nlogn) since you're doing a sort and then iterating over the list again.
Or maybe they are both O(nlogn)? This has been bugging me since last night since this seems like it'd be pretty simple.