Brute force searching a sorted list is grossly inefficient, as the earlier answerers explained, but that's not the source of the humor in the scene for the characters, the actors or the viewers.
Without asking the actors, we can't really know if they even thought it was funny per se, though they probably understood that the humor in the scene comes from the characters' behavior rather than the technical aspect of Richard's mistake.
It's funny to Aristotle Athari's character, Gabe, because brute force searching a sorted list is the kind of amateurish mistake Gabe thinks himself incapable of making. But it could've been any other amateurish mistake.
It's funny to some viewers because Ethan is disrespecting Richard, and Richard is letting him. The other white men laugh at Richard, too. Dinesh feels empathy for Richard but is too cowardly to stand up for his friend. The amateurish mistake itself doesn't matter too much for the humor. You can laugh without knowing about binary search or any other algorithm that would be faster than brute force search.
However, the demonstration of Richard's mistake is confusing and unconvincing, distracting viewers such as yourself who have real knowledge of algorithms in practice but are not so quick to judge others for silly mistakes.
The writers could have explained Richard's folly better by using some little, inexpensive prop, like a brand-new deck of playing cards. Surely even after the budget needed for RussFest they could have afforded a little thing that you can get at some store for less than $10.
A better demonstration wouldn't have taken any more time than the confusing demonstration. For example, Ethan (George Basil) could've given Gabe the new deck of cards and asked him to pick out a card like the Ten of Diamonds or the Three of Clubs.
Then Gabe, pretending to be Richard, would look at the Ace of Spades, the Two of Spades, the Three of Spades, and so on and so forth through each of the spade cards, and then say something like "That's you, Richard." Of course if the deck is shuffled even just once, the requested card could be at any position in the deck.
Having Ethan, Gabe and the others laugh at Richard for a silly mistake he made years ago shows the characters are not just immature, but also lacking in technical knowledge.
Brute force searching a sorted list might be valid in an early step of test-driven development (TDD), when the test requires searching in a small sorted list. A later test might have a timeout for searching in a much larger sorted list, e.g., if it takes more than half a second to find the requested item in the larger sorted list, the test fails.
There's also the question of why was Richard even writing that index of function in the first place. How did he know the list was sorted? Was it because the list was an instance of SortedList
? And wouldn't that class already provide an indexOf()
function? In which case Richard's mistake of an inefficient algorithm would be compounded by his effort to reinvent that wheel.
However, it is entirely realistic that the characters in that scene would laugh at Richard. They might not make that kind of basic mistake, but they probably also wouldn't revolutionize compression like Richard has either. So Richard's the bigger man, at least until he tries to punch Ethan.