fa08FinalCrit - 2. public double balanceFactor()cfw_ return...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
public double balanceFactor(){ return 1.0 * otherHeightHelper(root) / minPossibleHeight(slowSizeHelper(root)); } private int slowSizeHelper(BSTNode<AnyType> n) { if( n == null ) return 0; else return 1 + slowSizeHelper(n.getLeft()) + slowSizeHelper(n.getRight()); } private int otherHeightHelper(BSTNode<AnyType> n) { if(n == null) return -1; else return Math.max(otherHeightHelper(n.getLeft()) + 1, otherHeightHelper(n.getRight()) + 1); } public int minPossibleHeight(int currentSize){ int result = -1; while(currentSize > 0){ currentSize /= 2; result++; } return result; } Criteria: calc height: 6 points, 2 attempt, 4 correct calc size: 6 points, 2 attempt, 4 correct calc min possible height: 6 points, 2 attempt, 4 correct calculation: 1 point return 1 point 3. public void insert(E obj, int pos){ listSize++; if(head == null){ if(!obj.equals(defaultValue)){ head = new Node<E>(obj, null, pos); } } else if(pos <= head.getPosition()){ if(!obj.equals(defaultValue)){ head = new Node<E>(obj, head, pos);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

fa08FinalCrit - 2. public double balanceFactor()cfw_ return...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online