Closed MimiOlayeye closed 3 years ago
Also for a mostly sorted row.. does that imply only 2 elements are swapped (ie. 1 4 3 2 5) or can more than two elements be in the incorrect position?
Hello Mimi it all depends on what you want to consider for mostly ascending sorted, mostly descending sorted, and randomed. You could measure the amount of swaps done to determine each, then go from there.
If you were to traverse each row once to check if it is ascending, descending, or random, it would be O(n) and wouldn't significantly add to the runtime complexity.
Yeah, thank you guys for your answers!
How would you recommend we determine a row in the 2d array in mostly sorted opposed to randomly distributed?
I don't want to waste runtime by comparing each element in a row, but I want to be able to keep track of rows that follow the properties given to us in the assignment.