I'm an economics student with some interest in trading, and there is one concept pertaining to stock markets I can't quite figure out and I am unable to find an answer for it on the internet.

How are stock (and other derivatives) trading transactions able to occur instantaneously? In conventional, non-electronic trading, a buyer must be connected to a seller for a trade to occur, but in the world of electronic trading, as I have learned through trading simulators, this is not necessarily the case.