Question

6. In an array-based chain implementation of a Stack ADT, what is the performance of the...

6. In an array-based chain implementation of a Stack ADT, what is the performance of the ensureCapacity method when the array is full?

  1. O(1)
  2. O(n)
  3. O(n log n)
  4. O(n2)
  5. Undefined


7. In an array-based chain implementation of a Stack ADT, what is the performance of the ensureCapacity method when the array is not full?

  1. O(1)
  2. O(n)
  3. O(n log n)
  4. O(n2)
  5. Undefined


8. The efficiency for recursively traversing a chain of linked nodes is

  1. O(1)
  2. O(n)
  3. O(n2)
  4. it cannot be proven


9.

What is the output of the following program when the method is called with 3?


void unknown(int n)

   {

System.out.print("?");

if (n > 0)

   unknown(n-1);

   }


  1. ???
  2. ????
  3. ?????
  4. none of the above


10.


How many recursive calls will be made if the following method is called with 6?


void greeting(int n)

   {

if (n > 0)

{

   System.out.println("Hello!");

   greeting(n+1);

}

   }


  1. infinitely
  2. 7
  3. 6
  4. 5
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the solution to above problem

6) In a linked list based stack , the last nod represents the top node of the stack in ensure capcity method if the stack is full the size of stack is increased by creating a new array linked list of more capacity and old list is copied into the new list

Hence if the array is full we willl need to create a copy of old linked list hence it will take O(n) time to do so.

7) If the array is not full the ensure capcity method will do nothing as the number of element in array based linked list are still under capacity hence it will take only O(1) time to check the capacity

8) The efficiency of travelling a linked list recursively cannot be proven, as we can only find the time complexity of an algorithm but cannot measure its efficiency, as efficiency can be based on many factors both hardware and software

9) The output of above problem is ????

explanation

when n =3

we will get 1 "?"

then for n=2

we will get total 2 " ??"

then for n=1

we will get total 1 "???"

when for n=0

the program will print one more "?" so in total 4 "????" then when it sees n is not greater than 0 it will terminate

10) Infinitely number of recursive calls will be made since there is no base condition to stop the loop and always the value of n is increasing hence it will never stop executing

Add a comment
Know the answer?
Add Answer to:
6. In an array-based chain implementation of a Stack ADT, what is the performance of the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 4. In an array-based implementation of the ADT list, what is the best case performance of...

    4. In an array-based implementation of the ADT list, what is the best case performance of the contains method? a. O(1) b. O(log n) C. O(n) d. O(nº) 5. In an array-based implementation of the ADT list, what is the worst case performance of the contains method? a. O(n) b. O(n) C. O(log n) d. 0(1) 6. In an array-based implementation of the ADT list, what is the performance of the contains method when the entry is not in the...

  • Name: Each question is worth 1 point. 20 1. In a linked-chain implementation of a Stack...

    Name: Each question is worth 1 point. 20 1. In a linked-chain implementation of a Stack ADT, the performance of pushing an entry onto the stack is a. 0(2) b. О(n) С. 0(r) Answer: What is the entry returned by the peek method after the following stack operations. push(A), push(R), pop0. push(D), popO, push(L), pop0, pushJ), push(S), pop). pop 2. b.S c. L d. D Answer: n an efficient array-based chain implementation of a Stack ADT, the entry peek returns...

  • JAVA 3 LECTURE REVIEW PLEASE NEED ANSWERS ASAP. DUE IN AN HOUR!!! Question 12 points The...

    JAVA 3 LECTURE REVIEW PLEASE NEED ANSWERS ASAP. DUE IN AN HOUR!!! Question 12 points The best-case performance for a shell sort is: --- O(1) O(n2)   O(n) O(n log n)   Signaler cette question Question 22 points The best-case performance for an array of n items using insertion sort is: --- O(n2)   O(n) O(1) there is no best-case Signaler cette question Question 3 2 points A recursive method that processes a chain of linked nodes --- uses the first node in...

  • Java - data structures Suppose that in the array-based stack, the array doubles in size after...

    Java - data structures Suppose that in the array-based stack, the array doubles in size after multiple push operations. But later on, fewer than half of the array’s locations might actually be used by the stack due to pop operations. Revise the implementation so that its array also can shrink in size as objects are removed from the stack. Accomplishing this task will require two new private methods, as follows: The first new method checks whether we should reduce the...

  • QUESTION: ADT stack: resizable array-based implementation    for Ch4 programming problem 4 "maintain the stacks's top...

    QUESTION: ADT stack: resizable array-based implementation    for Ch4 programming problem 4 "maintain the stacks's top entry at the end of the array" at array index N-1 where the array is currently allocated to hold up to N entries. MAKE SURE YOU IMPLEMENT the functions:  bool isEmpty() const; bool push(const ItemType& newEntry); bool pop(); in ArrayStackP4.cpp //FILE StackInterface.h #ifndef STACK_INTERFACE_ #define STACK_INTERFACE_ template<class ItemType> class StackInterface { public:    /** Sees whether this stack is empty.    @return True if the...

  • c program Here we see a Stack ADT implemented using array. We would like the stack...

    c program Here we see a Stack ADT implemented using array. We would like the stack to be usable for different max sizes though, so we need to use dynamic memory allocation for our array as well. #include <stdio.h> #include <stdlib.h> typedef struct { int *data;   // stack data, we assume integer for simplicity int top;     // top of the stack int maxSize; // max size of the stack } Stack; void StackInit(Stack* stack, int size) {     // this...

  • - implement the Stack ADT using array – based approach. Use C++ program language #include "StackArray.h"...

    - implement the Stack ADT using array – based approach. Use C++ program language #include "StackArray.h" template <typename DataType> StackArray<DataType>::StackArray(int maxNumber) { } template <typename DataType> StackArray<DataType>::StackArray(const StackArray& other) { } template <typename DataType> StackArray<DataType>& StackArray<DataType>::operator=(const StackArray& other) { } template <typename DataType> StackArray<DataType>::~StackArray() { } template <typename DataType> void StackArray<DataType>::push(const DataType& newDataItem) throw (logic_error) { } template <typename DataType> DataType StackArray<DataType>::pop() throw (logic_error) { } template <typename DataType> void StackArray<DataType>::clear() { } template <typename DataType> bool StackArray<DataType>::isEmpty() const {...

  • Please help me on all the questions !!!!!!!! Really need help! Will give a thumb up...

    Please help me on all the questions !!!!!!!! Really need help! Will give a thumb up for helping. True/False (13) Chapter 14 - A List Implementation that Links Data Adding a node to an empty chain is the same as adding a node to the beginning of a chain. Adding a node at the end of a chain of n nodes is the same as adding a node at position n. You need a temporary variable to reference nodes as...

  • Create an array-based implementation of a stack. Each element of the stack should store a string....

    Create an array-based implementation of a stack. Each element of the stack should store a string. The stack class should include 3 private member variables (maximum stack size, top of the stack index, and a pointer to the array that holds the stack elements). Public member methods should include a constructor (with an argument of stack maximum size that is used to create a dynamic array), a destructor (that deletes the dynamic array), a push method (argument is a string),...

  • I need to implement a stack array but the top of the stack has to be...

    I need to implement a stack array but the top of the stack has to be Initialize as the index of the last location in the array.    //Array implementation of stacks.    import java.util.Arrays;       public class ArrayStack implements Stack {        //Declare a class constant called DEFAULT_STACK_SIZE with the value 10.           private static final int DEFAULT_STACK_SIZE = 10;           /* Declare two instance variables:            1. An integer called...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT