Which data structure should I use to have fast deletion/insertion and max (or min) search?

sebas

I am looking for a data structure that could ensure at least Log(n) complexity for deletion and insertion of a node and something close to O(1) or amortized Log(n) to search the maximum (or minimum) value.

I was thinking to use a self-balanced BST (which one?) modified to sort of remember the maximum (or minimum) value inserted.

Any suggestion?

Sorry I have to edit the question...of course a self-balanced BST can allow to search max and min in log(n), but I was thinking about something more toward O(1).

Bernhard Barker

You can use just about any self-balancing BST (e.g. red-black, AVL).

If you keep track of the minimum and maximum, the queries to get them will take O(1).

Since the minimum and maximum can only change on insertions and deletions, you can essentially just redetermine it (in O(log n)) when doing those operations (the running time of them will still be O(log n)).

Though it's probably a better idea to just redetermine the minimum or maximum when you receive a query for it and there was an insert or delete since the last query.

It's also possible to be more intelligent about it - if you've only gone left thus far, you're at the minimum, if you've only gone right, you're at the maximum. When inserting, just replace the minimum / maximum if appropriate. When deleting, just look around in the tree from the deleted node to find the new minimum / maximum.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Which data structure should I use to search a string from CSV?

From Dev

Which data structure should I use in Java?

From Dev

Which data structure to use for fast search? (C#)

From Dev

Which data structure to use for fast search? (C#)

From Dev

Which data structure should I use to handle multi value data?

From Dev

Which data structure should I use for maintaining this information?

From Dev

Which should I use in MATLAB: max(A(:)) or max(max(A))?

From Dev

Which database to use to build an analytics app with PHP: what should have I to search for to find an answer

From Dev

Which data structure should I use for having sorted data, where the key can be used on multiple entries

From Dev

To save memory and run fast in java, which way should i use

From Dev

Which data structure should I use to support key-value mappings, reverse iteration and insertion ordering?

From Dev

Performing the fastest search - which collection should i use?

From Dev

Which data structure in Java or Python should I use when I am trying to test requests to PHP-based server which expects array with String indexes?

From Dev

What data structure should I use to mimic "order by counter" in Cassandra?

From Dev

What data structure should I use for sentiment analysis?

From Dev

What data structure should I use for a music play queue?

From Dev

What data structure should I use to represent this board?

From Dev

What data structure should I use for sentiment analysis?

From Dev

What data structure should I use to mimic "order by counter" in Cassandra?

From Dev

What data structure I should use for my dictionary?

From Dev

Displaying and manipulating data in a windows form, Which control should I use?

From Dev

which library should I use for big data project

From Dev

which class should I use to collect and store different data types?

From Dev

Which method should I use to send data to Apple Watch and back?

From Dev

which class should I use to collect and store different data types?

From Dev

Which method should I use to send data to Apple Watch and back?

From Dev

Which clustering algorithm should I use for frequency data?

From Dev

Which data type should i use to store YouTube video durations?

From Dev

When to use which Data Structure?

Related Related

  1. 1

    Which data structure should I use to search a string from CSV?

  2. 2

    Which data structure should I use in Java?

  3. 3

    Which data structure to use for fast search? (C#)

  4. 4

    Which data structure to use for fast search? (C#)

  5. 5

    Which data structure should I use to handle multi value data?

  6. 6

    Which data structure should I use for maintaining this information?

  7. 7

    Which should I use in MATLAB: max(A(:)) or max(max(A))?

  8. 8

    Which database to use to build an analytics app with PHP: what should have I to search for to find an answer

  9. 9

    Which data structure should I use for having sorted data, where the key can be used on multiple entries

  10. 10

    To save memory and run fast in java, which way should i use

  11. 11

    Which data structure should I use to support key-value mappings, reverse iteration and insertion ordering?

  12. 12

    Performing the fastest search - which collection should i use?

  13. 13

    Which data structure in Java or Python should I use when I am trying to test requests to PHP-based server which expects array with String indexes?

  14. 14

    What data structure should I use to mimic "order by counter" in Cassandra?

  15. 15

    What data structure should I use for sentiment analysis?

  16. 16

    What data structure should I use for a music play queue?

  17. 17

    What data structure should I use to represent this board?

  18. 18

    What data structure should I use for sentiment analysis?

  19. 19

    What data structure should I use to mimic "order by counter" in Cassandra?

  20. 20

    What data structure I should use for my dictionary?

  21. 21

    Displaying and manipulating data in a windows form, Which control should I use?

  22. 22

    which library should I use for big data project

  23. 23

    which class should I use to collect and store different data types?

  24. 24

    Which method should I use to send data to Apple Watch and back?

  25. 25

    which class should I use to collect and store different data types?

  26. 26

    Which method should I use to send data to Apple Watch and back?

  27. 27

    Which clustering algorithm should I use for frequency data?

  28. 28

    Which data type should i use to store YouTube video durations?

  29. 29

    When to use which Data Structure?

HotTag

Archive