function ID3Algorithm(examples, targetAttribute, attributes): create a new node if all examples belong to the same class: return the node labeled with the class elseif attributes is empty: return the node labeled with the majority class else: calculate the information gain for each attribute bestAttribute = attribute with the maximum information gain set the node attribute to bestAttribute split examples into subsets using bestAttribute for each value v of bestAttribute: create a new branch below the node subsetExamples = subset of examples where example.attribute equals v if subsetExamples is empty: add a leaf node labeled with the majority class below the current branch else: newAttributes = attributes - {bestAttribute} add a subtree ID3Algorithm(subsetExamples, targetAttribute, newAttributes) below the current branch return the node