Algorithms and Data Structures · Middle · Question 67 of 75

What is the complexity of checking whether two strings of length n are equal?

Explanation

Characters are compared until a difference is found, so equal or nearly equal strings cost O(n). This matters when strings are used as keys: hashing a key also reads the whole string.

Further reading

Problem with a question

Algorithms and Data Structures · Middle · question 67

Test yourself

Take the Algorithms and Data Structures · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz