Compare two instances of a complex data structure

Consider a scenario where you have a complex data structure like a n-dimensional array or maybe a dictionary and you are asked to check whether they are equal or not.

Well! the most obvious answer is breaking down that data structure into single simple elements and then compare each of them with their corresponding counterparts. Isn’t it. Good luck doing that and impressing anyone!

Let me suggest a technique, comment if you like it…

We have to keep in mind whatever we are doing we have a constraint on our computation time and resources and hence there’s a need to find an optimal solution.

Okay, cutting to the chase, convert those complex data structures into hashes, and then the problem breaks down to just string matching.

Now, choice of hash function is also important. I suggest and find MD5 best for this situation. Using this, it’ll be a 32 length string you have to compare and you’re good to go.

Isn’t this interesting?

Like, share, comment.