Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I know that Stack Linked List is O(1) constant time and Stack Array is O(n) but I don't understand stand why its showing the Stack

I know that Stack Linked List is O(1) constant time and Stack Array is O(n) but I don't understand stand why its showing the Stack Array is quicker in nanoseconds than the Stack Linked List. Am I understanding this wrong or did I make a mistake ? Please give me detailed explanation.

StackLinkedList stacklink = new StackLinkedList();

long startTime1 = System.nanoTime();

stacklink.push(5);

stacklink.push(3);

stacklink.push(7);

stacklink.push(8);

stacklink.push(23);

stacklink.push(19);

long estimatedTime1 = System.nanoTime() - startTime1;

System.out.println("Stack Linked List Implementation took: " + estimatedTime1 + " nanoseconds");

stacklink.displayStack();

Output:

Stack Linked List Implementation took: 369282 nanoseconds

Stack st = new Stack();

long startTime1 = System.nanoTime();

st.push(5);

st.push(3);

st.push(7);

st.push(8);

st.push(23);

st.push(19);

long estimatedTime1 = System.nanoTime() - startTime1;

System.out.println("Stack Array Implementation took: " + estimatedTime1 + " nanoseconds");

19

23

8

7

3

5

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

More Books

Students also viewed these Databases questions

Question

3 How the market system answers four fundamental questions.

Answered: 1 week ago

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago