Relays were used in the earliest equipment: electronic accounting machines, and early computers made in the 1930's and early 1940's at Bell Labs and by Zuse in Germany. Relays are mechanical and hence relatively slow --- their response time is measured in milliseconds.
Vacuum tubes were dominant about 1945 to 1960 ('first generation of computers'). The first general purpose computer was the ENIAC (1946): 18,000 tubes, 20 10-digit accumulators, 100 kHz clock, 200 microsecond add time, 200 KW power. Tubes were much faster than relays (because they had no mechanical moving parts), but they were bulky, required high power, and had a relatively short life (crucial because of the large number of components).
Discrete transistors ('second generation computers') were used in computers starting around 1960. They took less power , were smaller, and had a longer lifetime than vacuum tubes.
Integrated circuits ('third generation computers') were created by fabricating several transistors on a single chip, allowing computers to be made smaller. IC's were introduced in the late 1960's, and gradually increased their level of integration (number of transistors on a chip).
Very large scale integration ('fourth generation computers') represented the ability to put more and more transistors on a chip, until an entire processor (a microprocessor) could be fabricated on a single chip. Initially VLSI was used to make personal computers (Apple II - 1977; IBM PC - 1981); now all computers are made from VLSI.
gates are basic combinational circuits: AND gate, OR gate, inverter (complement), etc.
realization of gates from switches: