The implementation is based on the following two instance variables: int count;
ID: 3906966 • Letter: T
Question
The implementation is based on the following two instance variables:
int count;
Stack_entry entry[maxstack];
It is easy to see that methods push, pop, top and empty have a time complexity of O(1). Assume that we now want to implement the same stack using the linked implementation given in “Linked List” under Lecture 1 in D2L. The implementation is based on the following two instance variables:
int count;
Node<List_entry> *head;
Can we achieve the same level of time complexity for each of the four methods in the linked stack? Briefly explain your answer
Explanation / Answer
we can achive all the four operations using the O(1)
Push :
push() we can insert the element in the in starting so we can achive this using the O(1) and
POP:
we can remove the elements at starting which can be done by O(1)
Empty:
and isEmpty() by checking the head==null this also can be done O(1)
Top:
Top we can return startig element
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.