Both have a lack of structure, in that realistically they are without parents. They both have a penchant for bucking the system, i.e. rules, manners, and the like. They recognize in each other a kindred spirit, in that they are both outsiders of the normal family structure.
Tom is mischievous and wants to lead an exciting life, and Huck Finn provides excitement and adventure for Tom. Tom has been told to stay away from Huck, but he admires Huck's way of life because he lives by his own rules. Neither boy is bad, and Huck really hasn't been given much of a chance in life with a father who is the town drunk. Huck likes Tom's imagination and sense of adventure, and the two become great friends.