Consider the following classes and in particular the "insert" algorithm.
import random
class Node:
def _init_(self, element): self.firstSuccessor = None self.secondSuccessor = None self.element = element def getElement(self): return self.element def setElement(self, element): self.element = element def getFirstSuccessor(self): return self.firstSuccessor def getSecondSuccessor(self): return self.secondSuccessor def setFirstSuccessor(self, firstSuccessor): self.firstSuccessor = firstSuccessor def setSecondSuccessor(self, secondSuccessor): self.secondSuccessor = secondSucesor def print(self): if self.getFirstSuccessor() is not None: self.getFirstSuccessor().print() print(str(self.getElement())+',', end = '') if self.getSecondSuccessor() is not None: self.getSecondSuccessor().print()class Structure: def _init_(self): self.initial = None def insert(self, x): list = None for i in range(0, len(x)): self.initial = self._insert(x[i], self.initial) if self.initial is not None: self.initial.print() def _insert(self, x, t): if t is None: t = Node(x) elif x <> t.setFirstSuccessor(self._insert(x, t.getFirstSuccessor())) elif x > t.getElement(): t.setSecondSuccessor(self._insert(x, .getSecondSuccessor())) else: raise Exception('Duplicate element') return t
Show which is the worst and best case by modeling with equations and solving them. Also show an example with data for the best and worst case using the data structure graphically.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here