I studied the large O for technical interviews, and then realized that the javascript indexOf method can have O (N) time complexity when it goes through each element of the array and returns the index where it is found.
We also know that the time complexity of O (n ^ 2) (n square) is not a good measure of performance for big data.
Is it okay to use indexOf internal loops? In javascript, its common to view code, where the indexOf method indexOf used inside loops, maybe to measure equality or to prepare some object.
Instead of arrays, we should prefer objects wherever necessary, since they provide a search with constant O (1) time performance.
Any suggestions would be appreciated.
performance javascript algorithm big-o indexof
Vatsal
source share