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
  • 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...

  • 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++....

  • 1. State and explain the definition of big-O. 2. Explain why we use big-O to compare...

    1. State and explain the definition of big-O. 2. Explain why we use big-O to compare algorithms. 3. Explain why binary search runs in O(log n) time. 4. Under what conditions is it possible to sort a list in less than O(nlog n) time? 5. List and explain the worst-case and average-case running times for each Vector method below: (a) insert(iterator here, Object item) (b) insertAtHead (c) insertAtTail (aka push back) (d) get(iterator here) (e) get(index i) (f) remove(iterator here)...

  • JAVA 3 LECTURE REVIEW PLEASE NEED ANSWERS ASAP. DUE IN AN HOUR!!! Question 12 points The...

    JAVA 3 LECTURE REVIEW PLEASE NEED ANSWERS ASAP. DUE IN AN HOUR!!! Question 12 points The best-case performance for a shell sort is: --- O(1) O(n2)   O(n) O(n log n)   Signaler cette question Question 22 points The best-case performance for an array of n items using insertion sort is: --- O(n2)   O(n) O(1) there is no best-case Signaler cette question Question 3 2 points A recursive method that processes a chain of linked nodes --- uses the first node in...

  • JAVA 3 PLEASE ANSWER AS MANY QUESTIONS AS POSSIBLE! ONLY 2 QUESTIONS LEFT THIS MONTH!!! Question...

    JAVA 3 PLEASE ANSWER AS MANY QUESTIONS AS POSSIBLE! ONLY 2 QUESTIONS LEFT THIS MONTH!!! Question 12 pts Which is a valid constructor for Thread? Thread ( Runnable r, int priority ); Thread ( Runnable r, String name ); Thread ( int priority ); Thread ( Runnable r, ThreadGroup g ); Flag this Question Question 22 pts What method in the Thread class is responsible for pausing a thread for a specific amount of milliseconds? pause(). sleep(). hang(). kill(). Flag...

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
ADVERTISEMENT