Question

1.If a list is implemented as a singly linked stack, give the big-O worst-case time complexity...

1.If a list is implemented as a singly linked stack, give the big-O worst-case time complexity of the following operations (as usual use the smallest standard big-O category that works:

a) push_front, b) push_back, c) lookup, d) read the i'th member

2.Repeat question 3 for a dynamic array (for example, as in the C++ vector class)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.If a list is implemented as a singly linked stack,
give the big-O worst-case time complexity of the following operations
(as usual use the smallest standard big-O category that works:

a) push_front,
    It takes O(1), constant time. We add new node at head of list

b) push_back:
    It takes O(1). constant time. We add at last using "rear" pointer. "rear" pointer points to last node.

c) lookup:
    It takes O(n) time. We have to search from head to end of the list.

d) read the i'th member
   It takes O(i) time, we have to traverse from head to ith node.

2.Repeat question 3 for a dynamic array;

a) push_front,
    It takes O(n) time. We have to first shift elements from 2nd postion element to one by left(make room)


b) push_back:
    It takes O(1). constant time. We add at last.

c) lookup:
    It takes O(n) time. We have to search from head to end of the list.

d) read the i'th member
   It takes O(1) time, We can access array element in constant time using index

Add a comment
Know the answer?
Add Answer to:
1.If a list is implemented as a singly linked stack, give the big-O worst-case time complexity...
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
  • ANSWER IN JAVA ASAP 1.Implement a stack on the singly linked list with the operations of...

    ANSWER IN JAVA ASAP 1.Implement a stack on the singly linked list with the operations of Lab Assignment 1. Hint: Using the same Stack class you implemented, change the array to an object of the singly linked list class. The functionality of push and pop is now based on the methods of the linked list class.

  • Big O SECTION List appropriate Worst Case Big O Notation under the different algorithms or data...

    Big O SECTION List appropriate Worst Case Big O Notation under the different algorithms or data structure operations. Choose from right column and place under left column. Right column can be used more than once or not all. O(1) O(n) O(n ^ 2) O(log n) Time Efficiency A. dequeue() a Node 1,000,000 element Linked List - Queue Implementation B. Traversing a Doubly Linked List from the Tail Node to the Head Node C. Traversing every element in Stack with array...

  • 8.9 Coding lab #5: create a dynamic array ADT and a singly linked list ADT. Honor Code...

    8.9 Coding lab #5: create a dynamic array ADT and a singly linked list ADT. Honor Code Your answers to this homework must be your own work.You are not allowed to share your solutions.You may not engage in any other activities that will dishonestly improve your results or dishonestly improve or damage the results of others. Plagiarism Plagiarism is when you copy words, ideas, or any other materials from another source without giving credit. Plagiarism is unacceptable in any academic environment....

  • Complete the following table by identifying the Big-O complexity of the operation when performed on each...

    Complete the following table by identifying the Big-O complexity of the operation when performed on each data structure as implemented by the C++ Standard Template Library (STL). Select "Not Available" if the STL does not support the operation. This is only for std::list<T> (Doubly Linked List) Operation Description std::array<T> (Fixed Sized Vector) std::vector<T> (Extendable Sized Vector) std::forward_list<T> (Singly Linked List) std::list<T> (Doubly Linked List) default construction create container with no arguments empty checks whether the container is empty size returns...

  • Show your work Count the number of operations and the big-O time complexity in the worst-case...

    Show your work Count the number of operations and the big-O time complexity in the worst-case and best-case for the following code int small for ( i n t i = 0 ; i < n ; i ++) { i f ( a [ i ] < a [ 0 ] ) { small = a [ i ] ; } } Show Work Calculate the Big-O time complexity for the following code and explain your answer by showing...

  • 1)Given a Stack implemented with a Linked List, and an O(1) implementation of push and pop,show...

    1)Given a Stack implemented with a Linked List, and an O(1) implementation of push and pop,show the Linked List after the following commands are executed: Stack myStack = new Stack(); myStack.push(20); myStack.push(40); myStack.pop(); myStack.push(60); myStack.push(80); 2)If the same commands were used but the Stack was implemented with an Array with maximum size of 10, show what the array would look like after all these commands are executed. Assume O(1) implementation of push and pop here as well. 3)Given a Queue...

  • Java's LinkedList class represents a doubly-linked list. What is the Big-O behavior of its addFirstmethod for...

    Java's LinkedList class represents a doubly-linked list. What is the Big-O behavior of its addFirstmethod for a list of size N? Group of answer choices O(1) O(log N) O(N) O(N log N) Flag this Question Question 21 pts Java's ArrayList class represents a basic array. As a convenience for the user, when the capacity of the backing array is exceeded, the class handles creating a new larger array and copying over the existing items. Its add(int index, E element) method...

  • Which big-O expression best characterizes the worst case time complexity of the following code? public static...

    Which big-O expression best characterizes the worst case time complexity of the following code? public static int foo(int N) ( int count = 0; int i1; while (i <N) C for (int j = 1; j < N; j=j+2) { count++ i=i+2; return count; A. O(log log N) B. O(log N2) C. O(N log N) D. O(N2)

  • Derive a class called Stack from the linked list described in Assignment 2 (list of Dates)....

    Derive a class called Stack from the linked list described in Assignment 2 (list of Dates). This means the Stack class will inherit all the properties (data and functions) of the linked list. But, since a stack only allows pushing and popping at the front of the list only, you will need to prevent the operations at the back. To do this, derive the Stack class in such a way that the base class (LinkedList) functions become private in the...

  • Please give little explanation, I'm trying to understand why. 2. List appropriate Worst Case Big O...

    Please give little explanation, I'm trying to understand why. 2. List appropriate Worst Case Big O Notation under the different algorithms or data structure operations. O(1) O(n) O(n ^ 2) O(log n) A. Directly Accessing value in a 2-dimensional by [row][column] B. Selection Sort then Binary Search on a 1,000,000 element array C. Binary Search D. Highest element algorithm for 10,000 element array. E. Traversal of 6 character string O(n) 3. Give examples of Implicit declarations for Python and C++....

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