1) Linear insertion sort has just correctly position x[60] in the following array x;
x= 20 40 60 30 10 50 show x after each of x[30] and x[10] is correctly positioned
2) In what situation will linear insertion sort make the fewest interchanges?
answer :
1) when x[30] correcctly positioned x= 20 30 40 60 10 50
when x[10] correcctly positioned x= 10 20 30 40 60 50
2) when it is already sorted
Write a recursive java function that copies a binary tree. (Use java only , and please describe your code)
answer:
public BinarySearchTree<E> rcopy(){
BinarySearchTree<E> newTree = new BinarySearchTree<E>();
newTree.root = rcopy(root);
newTree.size=newTree.nodes();
return newTree;
}
private Entry <E> rcopy(Entry <E> current){
Entry <E> b=new Entry<E>();
if(current!=null){
if(current.left!=null)b.left=rcopy(current.left);
if(current.right!=null)b.right=rcopy(current.right);
b.element = current.element;
b.parent = successor(current);
}
return b;
}
1. A Boolean expression is one that is either:a. true or falseb.x or yc.Positive or negatived.None of theseanswer: a
No comments:
Post a Comment