Using Data Structures and Algorithms Efficiently

It has repeatedly been stated that algorithmic choice is the biggest single factor concerning performance, before asynchronous and concurrent programming issues, and memory allocation and memory access overheads.

Bad programmers worry about the code. Good programmers worry about data structures and their relationships.

                                                                                                                                                        – Linus Torvalds

As we all want to be good programmers, we have to know about data structures and, consequently, their associated algorithms. In this chapter, we will first have a look at data structures and algorithms in general, then we will discuss the specifics of Qt-provided data structures, and at the end we will deliberate about ways to improve performance using algorithms and data structures.

This chapter will thus cover the following topics: 

  • Algorithms, data structures, and performance: General overview
  • Using Qt containers: Because there are some peculiarities
  • Qt algorithms, iterators, and gotchas: Because there will be gotchas
  • Working with strings: How to optimize it
  • Optimizing with algorithms and data structures: General algorithmic advice