Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

how we achieve O(1) time complexity for these operations:

Sumit Rawal answered on May 21, 2023 Popularity 3/10 Helpfulness 1/10

Contents


More Related Answers

  • time complexity of sum of even number
  • algorithms and their time and space complexity
  • what is time complexity of insertion sort
  • time complexity O(1)
  • time complexity definition
  • time complexity
  • time complexity practice problems
  • algorithm complexity
  • what is the time space complexity of the following code
  • what is the time space complexity of the following code
  • Use efficient I/O operations:
  • Complexity measures#

  • how we achieve O(1) time complexity for these operations:

    0

    Placing a new order means adding a new Order to the tail of the PriceLevel. This is O(1) time complexity for a doubly-linked list.

    Matching an order means deleting an Order from the head of the PriceLevel. This is O(1) time complexity for a doubly-linked list.

    Canceling an order means deleting an Order from the OrderBook. We leverage the helper data structure Map orderMap in the OrderBook to find the Order to cancel in O(1) time. Once the order is found, if the “orders“ list was a singly-linked list, the code would have to traverse the entire list to locate the previous pointer in order to delete the order. That would have taken O(n) time. Since the list is now doubly-linked, the order itself has a pointer to the previous order, which allows the code to delete the order without traversing the entire order list. 

    Popularity 3/10 Helpfulness 1/10 Language whatever
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on May 21 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.