About 6,600,000 results
Open links in new tab
  1. Time complexity of reversing a stack with recursion

    Apr 22, 2021 · If insertion at the bottom takes O(n) time, then the reverse function takes O(n 2) time, because it performs a linear-time operation on the stack for each element. The recurrence relation for reverse() would look a bit different though. In each step, you do three things: Call itself on n-1; An O(n) time operation (insert_at_bottom()) Some ...

  2. Time and Space Complexity analysis of Stack operations

    Sep 14, 2023 · Complexity Analysis: Time Complexity: O(1), It checks if the pointer of the top pointer is Null or not. This operation takes constant time. Auxiliary Space: O(1), No extra space is required. 5) size(): This operation returns the current size of the stack.

  3. c++ - Why does std::list::reverse have O (n) complexity ... - Stack ...

    Feb 25, 2016 · If you used an XOR-linked-list, reversing would become constant time. An iterator would be bigger though, and incrementing/decrementing it would be slightly more computationally expensive. That might be dwarfed by the unavoidable memory-accesses though for …

  4. How to Reverse a Stack using Recursion - GeeksforGeeks

    Apr 9, 2025 · Call reverse (), which will pop all the elements from the stack and pass the popped element to function insertAtBottom (). Whenever insertAtBottom () is called it will insert the passed element at the bottom of the stack. Time Complexity: O (n2).

  5. Reverse a stack without using extra space in O (n)

    Jan 10, 2023 · We can reverse a stack in O(1) time if we internally represent the stack as a linked list. Reverse a stack would require a reversing of a linked list which can be done with O(n) time and O(1) extra space.

  6. Program To Reverse A Linked List Using Stack

    Aug 17, 2021 · The time complexity of reversing a linked list using a stack is O(N), where N is the number of elements (nodes) in the linked list. Here’s a high-level explanation of why the time complexity is O (N):

  7. Reverse a Word using Stack Questions and Answers - Sanfoundry

    What is the time complexity of reversing a word using stack algorithm? Explanation: The time complexity of reversing a stack is mathematically found to be O (N) where N is the input. 5. What will be the word obtained if the word “abbcabb” is reversed using a stack? Explanation: The string “abbcabb” is pushed on to the stack.

  8. c - Space complexity analysis of a function for ... - Stack Overflow

    Oct 22, 2019 · Given a node with the following struct: void* data; size_t size; //size of data not list. struct listElementStruct* next; void (*print_func)(void*); //pointer to one of the custom print functions. Does this function have a constant memory O (1) or linear O (n) space complexity? listElement* current = start; int size_of_list=0;

  9. Reverse a stack using recursion - Techie Delight

    Nov 20, 2021 · Given a stack, recursively reverse it only using its abstract data type (ADT) standard operations, i.e., push(item), pop(), peek(), isEmpty(), size(), etc. The idea is to hold all items in a call stack until the stack becomes empty.

  10. C Program to Reverse a Stack using Recursion - GeeksforGeeks

    Oct 26, 2022 · Follow the steps mentioned below to implement the idea: Create a stack and push all the elements in it. Whenever insert_at_bottom () is called it will insert the passed element at the bottom of the stack. Below is the implementation of the above approach: Time Complexity: O …

  11. Some results have been removed
Refresh