The Unreal engine does optimize the shaders for you when you apply them.
Each material consist of small shaders doing something simple, these small shaders combined to form a large shader for a material, this is why the unreal will build multiple shaders when you add a new kind of material.
This way you can have two materials that share a single part of a shader, lets say Wood and Metal, thy share a vertex shader but each has a unique pixel shader. Now instead of using four shaders you use three.
Now if you have a red chair and you copy it's material to make a green chair, thy will share most of there shaders. However this doesn't change the fact that you added more materials.
If you wan't to make say a large swarm of a hundred aliens who very in color, you will need hundreds of materials and this will cause a large performance hit.
Luckily Unreal has a simple and effective solution, material instancing: https://docs.unrealengine.com/latest/INT/Engine/Rendering/Materials/MaterialInstances/index.html
If you are familiar with animation or mesh instancing this works the same.
A over simplified explanation is that you render the same thing with slight changes.