Abstract
It was reported in a study by Brodal and Moruz that, due to branch mispredictions, skewed search trees may perform better than perfectly balanced search trees. In this paper we take the search procedures under microscopic examination, and show that perfectly balanced search trees—when programmed carefully—are better than skewed search trees. As in the previous study, we only focus on the static case. We demonstrate that, by decoupling element comparisons from conditional branches and by writing branchless code in general, harmful effects caused by branch mispredictions can be avoided. Being able to store perfectly balanced search trees implicitly, such trees get a further advantage over skewed search trees following an improved cache behaviour.
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsPreview
Unable to display preview. Download preview PDF.
References
Andersson, A.: A note on searching in a binary search tree. Software Pract. Exper. 21(10), 1125–1128 (1991)
Bender, M.A., Demaine, E.D., Farach-Colton, M.: Efficient tree layout in a multilevel memory hierarchy. In: Möhring, R.H., Raman, R. (eds.) ESA 2002. LNCS, vol. 2461, pp. 165–173. Springer, Heidelberg (2002)
Bentley, J.: Programming Pearls, 2nd edn. Addison-Wesley, Reading (2000)
Brodal, G.S., Moruz, G.: Skewed binary search trees. In: Azar, Y., Erlebach, T. (eds.) ESA 2006. LNCS, vol. 4168, pp. 708–719. Springer, Heidelberg (2006)
Chen, S., Gibbons, P.B., Mowry, T.C., Valentin, G.: Fractal prefetching B + -trees: Optimizing both cache and disk performance. In: SIGMOD 2002, pp. 157–168. ACM, New York (2002)
Elmasry, A., Katajainen, J.: Lean programs, branch mispredictions, and sorting. In: Kranakis, E., Krizanc, D., Luccio, F. (eds.) FUN 2012. LNCS, vol. 7288, pp. 119–130. Springer, Heidelberg (2012)
Elmasry, A., Katajainen, J., Stenmark, M.: Branch mispredictions don’t affect mergesort. In: Klasing, R. (ed.) SEA 2012. LNCS, vol. 7276, pp. 160–171. Springer, Heidelberg (2012)
Guibas, L.J., Sedgewick, R.: A dichromatic framework for balanced trees. In: FOCS 1978, pp. 8–21. IEEE Computer Society, Los Alamitos (1978)
Jensen, C., Katajainen, J., Vitale, F.: Experimental evaluation of local heaps. CPH STL Report 2006-1, Department of Computer Science, University of Copenhagen, Copenhagen (2006)
Johnson, D.B.: Priority queues with update and finding minimum spanning trees. Inform. Process. Lett. 4(3), 53–57 (1975)
Kaligosi, K., Sanders, P.: How branch mispredictions affect quicksort. In: Azar, Y., Erlebach, T. (eds.) ESA 2006. LNCS, vol. 4168, pp. 780–791. Springer, Heidelberg (2006)
Katajainen, J.: Branchless search programs: Electronic appendix. CPH STL Report 2012-1, Department of Computer Science, University of Copenhagen, Copenhagen (2012)
Knuth, D.E.: Sorting and Searching, The Art of Computer Programming, 2nd edn., vol. 3. Addison-Wesley, Reading (1998)
Oksanen, K., Malmi, L.: Memory reference locality and periodic relocation in main memory search trees. In: 5th Hellenic Conference on Informatics, pp. 679–687. Greek Computer Society, Athens (1995)
Patterson, D.A., Hennessy, J.L.: Computer Organization and Design: The Hardware/Software Interface, revised 4th edn. Morgan Kaufmann, Waltham (2012)
Prokop, H.: Cache-oblivious algorithms. Master’s Thesis, Department of Electrical Engineering and Computer Science, Massachusetts Institute of Technology, Cambridge (1999)
Rahman, N., Cole, R., Raman, R.: Optimised predecessor data structures for internal memory. In: Brodal, G.S., Frigioni, D., Marchetti-Spaccamela, A. (eds.) WAE 2001. LNCS, vol. 2141, pp. 67–78. Springer, Heidelberg (2001)
Saikkonen, R., Soisalon-Soininen, E.: Cache-sensitive memory layout for binary trees. In: Ausiello, G., Karhumäki, J., Mauri, G., Ong, L. (eds.) IFIP TCS 2008. IFIP, vol. 273, pp. 241–255. Springer, Boston (2008)
Williams, J.W.J.: Algorithm 232: Heapsort. Commun. ACM 7(6), 347–348 (1964)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2013 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Elmasry, A., Katajainen, J. (2013). Branchless Search Programs. In: Bonifaci, V., Demetrescu, C., Marchetti-Spaccamela, A. (eds) Experimental Algorithms. SEA 2013. Lecture Notes in Computer Science, vol 7933. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-38527-8_13
Download citation
DOI: https://doi.org/10.1007/978-3-642-38527-8_13
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-642-38526-1
Online ISBN: 978-3-642-38527-8
eBook Packages: Computer ScienceComputer Science (R0)