The Knuth-Morris-Pratt algorithm improves upon the brute force string matching approach by utilizing a prefix function to avoid re-checking characters. It runs in O(m+n) time and O(m) space, where m is the pattern length and n is the string length. The prefix function encapsulates how the pattern matches shifts of itself, enabling the algorithm to avoid redundant comparisons when a mismatch occurs.