Pages

Tuesday, February 22, 2011

use hash to improve the performance

two arrays, too loops, usually the complex will be O(n*n).
but if we use a hash dict to store one array, then we can go through every item in the array filter by the hash dict directly, that will be very fast, and the complex only be O(n+n).


so never forget to use hash dict if we can.
that's why I love python. it is really easy to use dict.

No comments:

Post a Comment