Question: (a) Write a method in Java to sort a stack of n integer numbers, s, in increasing order static Stack sort(Stack s) To implement this



(a) Write a method in Java to sort a stack of n integer numbers, s, in increasing order static Stack sort(Stack s) To implement this method you must use one more auxiliary stack and you should not make any assumptions about how the stack is implemented. The following are the only functions that should be used to write this program: push, pop, peek, and isEmpty (b) What is the running time complexity of your method? Justify Important Notes You must add the main method in your program to test your implementation There are no data errors that need to be checked as all the data will be assumed correct. Your program MUST be submitted only in source code form (.java file) A program that does not compile or does not run loses all correctness points . A MyList is a data structure consisting of a list of items, on which the following operations are possible myPush(x): Insert item x on the front end of the MyList. myPop): Remove the front item from the MyList and return it myInject(x): Insert item x on the rear end of the MyList. Using the LinkedList class, write a class in Java to implement the MyList data structure and that take O(1) time per operation The MyList class signature is: public class MyList MyList)t. . .1 void myPush(AnyType x) f. . -) AnyType myPop() . . -> void myInject (AnyType x) f. . .> Important Notes . For this problem, the implementation of the methods myPush(x), myPop, and myInject(x) It is not required that you implement the main method Continue on next page In this problem, you will write some Java code for simple operations on binary search trees where keys are integers. Assume you already have the following code and assume that the method bodies, even though not shown, are correct and implement the operations as we defined them in class. public class BinarySearchTreeNode public int key; public BinarySearchTreeNode left; public BinarySearchTreeNode right; public class BinarySearchTree private BinarySearchTreeNode root; public void insert(int key) f... > public void delete(int key) { } public boolean find(int key) f... 1 (a) Add a method public int positiveeySum() to the BinarySearchTree class that returns the sum of all non-negative keys in the tree. You will need an assistant/helper method. (b) Add method public void deleteMax() to the BinarySearchTree class that deletes the maximum element in the tree (or does nothing if the tree has no elements) c) Add method public void printTree) to the BinarySearchTree class that iterates over the nodes to print then in decreasing order. So the tree... Produces the output "5 4 3 21" Note: You will need an assistant/helper method d) Add method public void printPostorder) to the BinarySearchTree class that prints out the nodes of the tree according to a "postorder" traversal. So the tree... Produces the output "1 3 2 54" Note: You will need an assistant/helper method Continue on next page e) You have a binary search tree. Consider a leave I. B is the set of keys in the path p of I including the leave I and the root of the tree. A is the set of keys to the left of the path p. C is the set of keys to the right of the path p. Is the following statement true or false? Given any element a in A; b in B; c in C; a SbS c. Justify your answer. Important Notes for problem #3 For this problem, you only need to submit the implementation of four methods in Java (positiveKeySum, deleteMin, printTree, and printPostorder). In the part e), you don't need to submit any implementation in Java and just you must answer the question. a) Show the result of every step of inserting the following sequence of elements into an initially empty AVL-tree: 10, 20, 15, 25, 30, 16, 18, 19. b) Show the resulting AVL-tree, after physical deletion (NOT a lazy deletion) of the record with the key 30 from the AVL tree that you got in the previous item, 4 a) c) Show the result of every step when an initially empty AVL-tree has keys 1 through 7 inserted in order, (1,2,3,4,5,6,7) d) Draw an AVL-tree of height 4 that contains the minimum possible number of nodes. e) The following items are inserted into an AVL tree: 1, 2, 3, 8, 6. How many and what type of Important Notes: . For problem #3, you don't need to submit any implementation in Java. Forall parts of this problem,you must draw the AVL-trees using the appropriate araphics