Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started