0

I'd like to think this is true, but I'm not too confident in that answer. Is there an algorithm that has an equal running time in the both the average and worst case. I'm not sure if the answer would be true then.

blutuu
  • 191
  • 2
  • 12
  • If the `avg` and `worst` case times where equal, then the `best` case time would have to be equal to them both either, making your algorithm basically constant time. Otherwise you'd have an `avg` between the `best/worst` boundaries. – Regexident Apr 04 '13 at 23:21
  • The average case is never worse than the worst case. It can be the same or better. – Alexey Frunze Apr 04 '13 at 23:26
  • @wildplasser I feel that if it is false even once then the overall answer would be false. – blutuu Apr 04 '13 at 23:33

2 Answers2

4

Calculating 1+1=2 is O(1) in best, average, and worst case.

A slightly less trivial example: determining the length of a linked list of length n is takes n steps in all cases, so it's O(n) in all cases.

Joni
  • 108,737
  • 14
  • 143
  • 193
1

False. for example: BinarySearch, ShellSort, HeapSort and so on.

richselian
  • 731
  • 4
  • 18