Branch prediction is an optimization technique which predicts the path a code will take before it is known for sure. We have explained the concept with a C++ example of branch prediction where a condition statement runs slower in case of unsorted data compared to sorted data.