The main issue is to obtain a reliable estimate of performance. It's important to take into account that both stages (the selection of the algorithm and the hyper-parameter tuning) are training stages themselves, therefore the resulting model (after selection, and only this model) should be evaluated on a fresh test set. Otherwise there's a risk of overestimating the performance, in case the selected method happens to be better by chance on the test set.
The simplest way would be to consider that this is all a single stage of parameter tuning (i.e. considering the algorithm as a parameter). In this case you should separate the data into 3 sets A,B,C:
- All the algorithms with all their combinations of parameters are trained on A, then evaluated on B.
- The best system is selected. Then this selected algorithm+parameters is retrained on A+B. Finally the model is evaluated on C.
Step 1 can be replaced by cross-validation. In this case there's only two sets: CV on A, then selection and evaluation on B.
Keeping the two stages separate normally requires one more level, i.e. 4 sets A,B,C,D:
- Train all the algorithms on A, evaluate them on B.
- Pick the best algorithm. Try all the combinations of parameters for this algorithm by training on A+B then testing on C.
- Pick the best parameters and re-train on A+B+C, then evaluate on D.
Again CV can be used, either in step 1 or 2 or both. In this case this would be nested cross-validation, it's a bit more complex but the same principle.