ternary-search

Binary Search vs Ternary Search

跟風遠走 提交于 2019-12-11 03:24:48
问题 In terms of time and space complexity, is binary search better than ternary search ? 回答1: Both have constant space, but big O time for Ternary Search is Log_3 N instead of Binary Search's Log_2 N which both come out to log(N) since log_b(N) = log_x(N)/log_x(b) . In practice Ternary Search isn't used because you have to do an extra comparison at each step, which in the general case leads to more comparisons overall. 2 * Log_3(N) comparisons vs Log_2(N) comparisons. 回答2: It probably depends on