+ 8

How to add time Complexity work?

Here is the code: https://code.sololearn.com/WAxgYfP5cdbN/?ref=app

24th Jun 2020, 12:18 PM
Coder
Coder - avatar
7 Antworten
+ 8
ODLNT why jump search take more time than linear and binary search?
25th Jun 2020, 1:23 AM
Coder
Coder - avatar
+ 7
Idk but if this is what you're trying to do https://code.sololearn.com/W1I0O4xozGBi/?ref=app I guess you're calling that Date().getMili function before executing the actual function.
24th Jun 2020, 12:38 PM
Raj Chhatrala
Raj Chhatrala - avatar
+ 2
🔫 Rick Grimes nice answer but it not work perfectly ... If I use it Already ......Sometimes binary search take much time then linear search which is not possible.....
24th Jun 2020, 1:29 PM
Coder
Coder - avatar
24th Jun 2020, 9:12 PM
ODLNT
ODLNT - avatar
+ 2
Coder It appears the step in the jump search algorithm has to be an integer. I added Math.floor to Math.sqrt and now times are in line with the time complexity. -or-(edit) It may have something to do with the size of the array. In the second code, I posted I change the array length to 1000.
25th Jun 2020, 2:06 AM
ODLNT
ODLNT - avatar
0
On an unsorted array Binary Search is almost twice as slow as Linear Search with worst Time Complexity of O(n²) and that is not even considering unbalanced trees. In case of a sorted array, Binary Search is faster but the caveat here is also on how arrays are treated by the Language Translator. You have to keep in mind, running code on this app is not a real world situation as this app uses a Server Machine on the other end and results can significantly differ from a real world test.
24th Jun 2020, 5:27 PM
Anubhav Mattoo
Anubhav Mattoo - avatar
0
Where did you learn all this awesome coding..???
16th Oct 2020, 6:25 AM
Tarun Mehta
Tarun Mehta - avatar