Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the growth rate of each algorithm: _____ Reading a value from index 0 of a

ID: 3863969 • Letter: W

Question

Write the growth rate of each algorithm: _____ Reading a value from index 0 of an array, doubling it, and assigning it to index 1 _____ Calling the contains method on an ArrayList _____ Inserting at a specified position (0, 1, 2, ...) of an array _____ Popping a stack implemented as an array Check off situations that could use a stack for data storage (LIFO). ____ Maintain a waiting list for students trying to register for a closed course on MaineStreet. _____ Determine if a program contains a balanced number off and {} and [] pairs. ____ Process email by the most recent one read first. ____ Process people in a checkout line in a grocery store. Using the ArrayStack class developed in lecture, list the output of each line. Array Stack s = new ArrayStack (); s.push(20); s.push(4); s.push(50); System.out.println(s.size()); ______ System.out.println(s.peek()); ______ s.push(80); s.push(30); s.pop(); s.push(); while(!s.empty()) {System.out.print(s.peek() + " "); s.pop();} ______ An Interface class can be implemented by multiple classes.

Explanation / Answer

2. Several algorithms works well with stacks data structure. stacks are used for remembering those tasks which are partially completed and undoing (backtracing from) an action.
Stack is used in the below usecases:
Process email by the most recent ones read first.
Determine if a program contains balanced number of {} and [] pairs.
Other two use cases may involve queue

4. An Interface class can be implemented by multiple classes - True

Interfaces are more flexible. Also a class can implement multiple interfaces so the implements keyword is followed by a comma-separated list of the interfaces implemented by the class.To be precise, An interface is not extended by a class; it is implemented by a class. An interface can extend into multiple interfaces. Java doesnot support multiple inheritance, using abstract classes prevents your users from using any other class hierarchy. Interfaces are preferrred when there are no default implementations or state.