+ 2
How do i know the time and space complexity of my Algolithm
for example i tried to create what is called bubble sort by my own in Javascript so can i say my time complexity O(N) and O(N^2) for best and worst respectively? let arr = [9,8,7,6,5,4,3,2,1]; ;(function MyBubbleSort(nums) { for (var i = 0; i < nums.length; i++) { if (i > 0 && nums[i] < nums[i-1]) { let temp = nums[i-1] nums[i-1] = nums[i] nums[i]= temp i=-1 }else continue; } return nums }(arr));
2 odpowiedzi
+ 2
Dagota ,
here is a link to some useful information about your requested items that may help:
https://www.geeksforgeeks.org/time-complexity-and-space-complexity/
+ 1
You can measure the duration and thus judge which algorithm would be better where.