What is the difference between bagging of decision trees and random forest




Random forests and bagging both ensemble trees,but sometimes bagging gives a better result than random forests and some times it is the reverse.
Both are creating ensembles of trees,so what is the difference in the ways that these two techniques work.
Can someone please guide me on this!!


Bagging - Bagging has a single parameter, which is the number of trees. All trees are fully grown a binary tree (unpruned) and at each node in the tree one searches over all features to find the feature that best splits the data at that node.

Random Forest -

Random forests has 2 parameters:
1-The first parameter is the same as bagging (the number of trees)
2-The second parameter (unique to random forests) is mtry which is how many features to search over to find the best feature. this parameter is usually 1/3*D for regression and sqrt(D) for classification. thus during tree creation randomly a mtry number of features are chosen from all available features and the best feature that splits the data is chosen.

Hope this helps!