Tradeoffs Between Branch Mispredictions and Comparisons for Sorting Algorithms

  • Gerth Stølting Brodal
  • Gabriel Moruz
Part of the Lecture Notes in Computer Science book series (LNCS, volume 3608)


Branch mispredictions is an important factor affecting the running time in practice. In this paper we consider tradeoffs between the number of branch mispredictions and the number of comparisons for sorting algorithms in the comparison model. We prove that a sorting algorithm using O(dn log n) comparisons performs Ω(n log d n) branch mispredictions. We show that Multiway MergeSort achieves this tradeoff by adopting a multiway merger with a low number of branch mispredictions. For adaptive sorting algorithms we similarly obtain that an algorithm performing O(dn(1 + log(1 + Inv/n))) comparisons must perform Ω(n log d (1 + Inv/n)) branch mispredictions, where Inv is the number of inversions in the input. This tradeoff can be achieved by GenericSort by Estivill-Castro and Wood by adopting a multiway division protocol and a multiway merging algorithm with a low number of branch mispredictions.


Input Sequence Prediction Scheme Sorting Algorithm Conditional Branch Branch Prediction 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Brodal, G.S., Fagerberg, R., Moruz, G.: Cache-aware and cache-oblivious adaptive sorting. In: Proc. 32nd International Colloquium on Automata, Languages, and Programming. LNCS, Springer, Heidelberg (2005)Google Scholar
  2. 2.
    Brodal, G.S., Fagerberg, R., Moruz, G.: On the adaptiveness of quicksort. In: Proc. 7th Workshop on Algorithm Engineering and Experiments. SIAM, Philadelphia (2005)Google Scholar
  3. 3.
    Colin, A., Puaut, I.: Worst case execution time for a processor with branch prediction. Real-Time Systems, Special issue on worst-case execution time analysis 18(2), 249–274 (2000)Google Scholar
  4. 4.
    Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein, C.: Introduction to Algorithms, 2nd edn. MIT Press, Cambridge (2001)zbMATHGoogle Scholar
  5. 5.
    Estivill-Castro, V., Wood, D.: Practical adaptive sorting. In: Dehne, F., Fiala, F., Koczkodaj, W.W. (eds.) ICCI 1991. LNCS, vol. 497, pp. 47–54. Springer, Heidelberg (1991)Google Scholar
  6. 6.
    Estivill-Castro, V., Wood, D.: A survey of adaptive sorting algorithms. ACM Computing Surverys 24(4), 441–475 (1992)CrossRefGoogle Scholar
  7. 7.
    Floyd, R.W.: Algorithm 245: Treesort3. Communications of the ACM 7(12), 701 (1964)CrossRefGoogle Scholar
  8. 8.
    Guibas, L.J., McCreight, E.M., Plass, M.F., Roberts, J.R.: A new representation of linear lists. In: Proc. 9th Ann. ACM Symposium on Theory of Computing, pp. 49–60 (1977)Google Scholar
  9. 9.
    Hennesy, J.L., Patterson, D.A.: Computer Architecture: A Quantitative Approach. Morgan Kaufmann, San Francisco (1996)Google Scholar
  10. 10.
    Levcopoulos, C., Petersson, O.: Splitsort – an adaptive sorting algorithm. Information Processing Letters 39(1), 205–211 (1991)zbMATHCrossRefMathSciNetGoogle Scholar
  11. 11.
    Li, X., Mitra, T., Roychoudhury, A.: Modeling control speculation for timing analysis. Real-Time Systems Journal 29(1) (January 2005)Google Scholar
  12. 12.
    Manilla, H.: Measures of presortedness and optimal sorting algorithms. IEEE Trans. Comput. 34, 318–325 (1985)CrossRefMathSciNetGoogle Scholar
  13. 13.
    McFarling, S.: Combining branch predictors. Technical report, Western Research Laboratory (1993)Google Scholar
  14. 14.
    Mehlhorn, K.: Data structures and algorithms. Sorting and searching, vol. 1. Springer, Heidelberg (1984)Google Scholar
  15. 15.
    Sanders, P., Winkel, S.: Super scalar sample sort. In: Albers, S., Radzik, T. (eds.) ESA 2004. LNCS, vol. 3221, pp. 784–796. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  16. 16.
    Williams, J.W.J.: Algorithm 232: Heapsort. Communications of the ACM 7(6), 347–348 (1964)Google Scholar
  17. 17.
    Yeh, Y.-Y., Patt, Y.N.: Alternative implementations of two-level adaptive branch prediction. In: ACM International Symposium on Computer Architecture, ISCA (1992)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2005

Authors and Affiliations

  • Gerth Stølting Brodal
    • 1
  • Gabriel Moruz
    • 1
  1. 1.BRICS, Department of Computer ScienceUniversity of AarhusÅrhus NDenmark

Personalised recommendations