It is always the best five cards that make a five card poker hand that determines the winner loser or split. Holdem is played with seven cards, and the two cards that are not part of the best five card hand count for absolutely nothing in determining if a pot is won lost or split.
There is no one algorithm. The game is a combination of luck and skill. It also has factors such as the number of players in a hand, and where your seating position is relative to the dealer.