Don't really need help, already know how to do what I need to do..Was just wondering if anyone knew off the top of their head the average case time complexity of
It the list is sorted, binary search on average will always take O(lgN) because the best and worst time complexity is O(lgN).
For linear time it should be O(N/2) on average
For selection sort, best case is still O(N2) because no matter if the set of items is already sorted, selection sort still needs to iterate through the entire list to verify this. So the average time complexity is still O(N2).
You are basicallly looking for big Theta. Google it
Smac89, so would the average time complexity of Binary Search then be Logn / 2 ?
Also, can you verify that my insertion sort formula is correct?
For Selection sort I have obtained this:
Selection Sort: [ (n(n+1)) / 2 ] - 1
Is this correct?
In addition, as easy as you make it sound, it's not that simple. I tried googling for hours, but I keep getting the BEST and WORST case time complexities, and what I need is the AVERAGE time complexities of these. Don't believe me? Try to Google it yourself lol. There are seriously no results giving me what I need.
Thank you for your time, hopefully you can verify if what I've submitted is correct.
I'm also wondering if I can just take the best and worst TC's and add them up and then divide by 2 to get the average case? Would that be plausible?
I mentioned in my last post that what you want to find is big theta notation. This is different from notations such as Big O, Big Omega, etc. Where Big O measures the upper bound cost, and Big Omega measures lower bound cost; Big theta will lie somewhere between Big O and Big Omega
The stackoverflow link will explains it in more detail.
You average case for selection sort looks about correct because in the worst case and best case, the algorithm will do:
N - 1 + N - 2 + N - 3 + ... + N - (N - 1) comparisons to determine if the list is sorted
= 1 + 2 + 3 + 4 + ... + N - 1
= (N - 1)(N) * 1/2
= 1/2 * N2 - N
I will try to upload a lecture video (or 2) that I found that can explain this to you
These videos are by Robert Sedgewick, provided in his free online course at coursera.org: https://class.coursera.org/algs4partI-004
I suggest signing up for future offerings of this class