dimanche 3 juillet 2016

Binary tree search delete a node complexity


I try to calculate the complexity of the binary tree search node deletion.I want to calculate complexity in all 3 cases(worst,average complexity and best) more detalied.How to choose the mathematical formula? T(n) = ? Nod* delete(Nod*& rad, const int& c) { //Nod has:c(information:int),nextSt(left:pointer to Nod),nextDr(right pointer to Nod) Nod* aux; if (rad == NULL) return NULL; else if (c< rad->c && c != rad->c) { rad->nextSt() = delete(rad->nextSt(), c); return rad; } else if (c > rad->c) { rad->nextDr() = delete(rad->nextDr(), c); return rad; } else if (rad->nextSt() != NULL && rad->nextDr() != NULL) { aux = minim(rad->nextDr()); rad->setElem(aux->element()); rad->nextDr() = delete(rad->nextDr(), rad->c); return rad; } else { aux = rad; Nod* repl; if (rad->nextSt() == NULL) repl = rad->nextDr(); else repl = rad->nextSt(); delete rad; return repl; } }

Aucun commentaire:

Enregistrer un commentaire