.My O(n) for the program was rougly o(N^2)though. |
So Bachmann-Landau can be either O(N) or O(N^2) (or any other complexity), you can't have both, though I think you may want to say that your worst time complexity is O(N^2). You can't have the same the same code with 2 different complexities.
Now, it depends on what is your program supposed to do, maybe O(N^2) may be actually a good complexity for the task you are trying to accomplish, or maybe it's the worst scenario. It's hard to say without knowing what you are trying to do.
As for lists, if you are retrieving elements from from a known position in the list, which are taking O(n) on a list, those would take O(1) on an array or hash table, that would indeed increase your time complexity by quite an amount. Consider you have to access the nth element from a list m lists. This would have the worst time O(n*m) if you are using lists, while it would take only O(n) from an array. If you are doing lots of searches inside an array or list, you'd get O(n) for linear, but in arrays you can improve this time by doing binary search ( O(log n)) or interpolation search (O(log log n)), but consider if a one time O(n log n) sorting would be worth it time-wise (if you are doing a search only 1 time per array, then you're better off using linear search). Depending on what you want to do, you could use a hash table for O(1) time for searching/retrieving elements, but then you'd have to deal with collisions and it's gonna have problems if you add a lot of elements.
Now for space complexity (as you don't specify which complexity you got O(N^2) ), keep in mind that lists will take more memory than arrays, as lists aren't sequential in memory and you gotta allocate one more pointer for element in the list. Using lists isn't a bad practice by any means, it's a bad practice to use lists where you don't need them and there are way better alternatives.