Question

1.A stack implemented with an array has what performance? Select one: a. O(n3) b. O(n log...

1.A stack implemented with an array has what performance?

Select one:

a.

O(n3)

b.

O(n log n)

c.

O(n)

d.

O(n2)

2.

A stack uses the first in first out insertion and deletion method.

Select one:

True

False

3. Match the following stack operations with their meaning.

object pop();

boolean isEmpty();

push (object);

integer size();

object top();

meanings are:

- returns the number of elements stored

-just removes the last inserted elements

- returns the last inserted elements without removing it

-inserts an element

-indicates whether no elements are stored

-removes snd returns the last inserted element

Homework Answers

Answer #1

Solution 1: Option C is the correct option as the stack could be implemented using an array in O(n) of time.

Solution 2: It is False as the Stack actually uses the Last In First Out mode of operation while a Queue actually uses the First In First Out mode of operation.

Solution 3: Given below is the correct match for each and every stack operation:

  • object pop(): Removes snd returns the last inserted element
  • boolean isEmpty(): Indicates whether no elements are stored
  • push(object): Inserts an element.
  • integer size(): Returns the number of elements stored
  • object top(): Returns the last inserted elements without removing it

Here's the solution to your question and it is absolutely correct, please please please provide it a 100% rating. Thanks for asking and happy learning!!

Know the answer?
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
Similar Questions
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number in A and an O(log n)-time computation for each odd number in A. What is the best-case running time of Algorithm X? What is the worst-case running time of Algorithm X? 2. Given an array, A, of n integers, give an O(n)-time algorithm that finds the longest subarray of A such that all the numbers in that subarray are in sorted order. Your algorithm...
(JAVA) Why is my toString method not printing out the last node? It will not print...
(JAVA) Why is my toString method not printing out the last node? It will not print out "A" which is for Alice. Everything else is working just fine except for this. package driver; import exception.StackException; import stack.*; public class StackDriver { public static void main(String[] args) throws Exception { StackInterface<Painting> painting = new LinkedStack <Painting>(); try { System.out.println("Peeking at top of player stack.\n" + painting.peek()); }catch (StackException e) { System.out.println(e); System.out.println("Let's double check if it's empty: " + painting.isEmpty()); }...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to the method header that will be a boolean variable: public boolean add(T newEntry, boolean sorted) The modification to the add method will makeit possible toadd new entriesto the beginning of the list, as it does now, but also to add new entries in sorted order. The sorted parameter if set to false will result in the existing functionality being executed (it will add the...
Problem Definition: Problem: Given an array of integers find all pairs of integers, a and b,...
Problem Definition: Problem: Given an array of integers find all pairs of integers, a and b, where a – b is equal to a given number. For example, consider the following array and suppose we want to find all pairs of integers a and b where a – b = 3 A = [10, 4, 6, 16, 1, 6, 12, 13] Then your method should return the following pairs: 4, 1 15, 12 13, 10 A poor solution: There are...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT