If we construct sorted set based on RB Tree and Heap. Do insertion() and deleteMax() for n times.

(1). What's the Big-O ?

My idea: For both RB tree and heap , deleteMax() and insertion() will all take nlog(n), so does it mean the time complexity will be O(nlog(n) + nlog(n)) = O(2nlog(n)) ?

(2). How about the difference of their constant factors.

Assume you are talking about binary heap. For each insertion/maxDeletion, the time complexity is `O(log(n))`

for both RB and binary heap, where `n`

is the number of existing elements in the RB/heap. Fibonacci heap has better theoretical time complexity. You should read the wiki.

As to the constant, binary heap is better than RB. It is also much easier to implement and takes less space. You should use heap when you only want to keep track of the min/max without requiring to know the complete ordering of all elements.

Similar Questions

What is the difference between running ruby app.rb and rackup? When running rackup, what script is actually running?

We're using GWT and We're required to create two drag and drop tree grids. Each tree contains parents and children (max two level for now). Here's what we need to be able to do: Use cases Drag a pare

What's the best way to get the sum of SCORES in a Redis sorted set?

Using ExtJS 4, a tree panel and a drag drop.. I'm trying set the newly dragged node to be selected... something like: viewConfig: { listeners : { drop: function (node, data, view, ddel, item) { this.g

I'm wondering, is there any difference between performance of those, provided binary search is used for sorted linked list insertion, search. And in which situations they perform differently or maybe

A heap is a tree data structure where higher levels of the tree always contain greater (or lesser, if it's set up that way) values than lower levels. The heap is a bunch of free RAM that a program h

I need to calculate how much memory a Redis SortedSet takes assuming my average element of the Sorted Set is X bytes.

I get a segmentation fault when iterating over a set. The stack trace points to std::_Rb_tree_const_iterator<Type>::operator++ std::_Rb_tree_increment() but I get nothing more informative. The

According to doc for List def sorted[B >: A](implicit ord: math.Ordering[B]): List[A] Sorts this list according to an Ordering. def sortBy[B](f: (A) ⇒ B)(implicit ord: math.Ordering[B]): List[A] So

I have a multi site project that changes from one to another by changing two variables, one is inside routes.rb and the other in application_controller.rb. Is it possible to pass variables between the

I have an array of numbers. I want to sort them and remove duplicates. This answer suggest to use set and sort for that kind of operation. The order of operations shouldn't change the results, so I me

var seq = Seq[String]() seq = seq :+ hello var set = Set[String]() set += hello what's the difference between Seq and Set?

I'm using a Redis sorted set as a queue to maintain a list of users and I need to pop the first item in the list and use it, but I'm having issues. Here's my attempt... keys = [] $redis.multi do # Get

In output of explain command I found two terms 'Seq Scan' and 'Bitmap heap Scan'. Can somebody tell me what is the difference between these two types of scan? (I am using PostgreSql)

Java docs says that a TreeSet keeps its elements ordered internally. Here what does ordering mean? Does it mean sorted? If so, then what is the difference between sorting and ordering?

I was trying to adjust initial heap size of a tomcat 7 (CentOS, java -version: 1.6.0_25-b06) instance by adding the following line to catalina.sh: export CATALINA_OPTS=-Xms=512M -Xmx=1024M Starting

Someone who understands how rails caching works can really help me out here. Here's the code, nested inside of the Rails::Initializer.run block: config.after_initialize do SomeClass.const_set 'SOME_CO

I have next structures code in C for my binary tree: struct student { int studentID; char lastName[MAX_LENGTH]; char firstName[MAX_LENGTH]; float amount; }; struct node { struct student* record; struc

In clojure[script], how to write a function nearest that receives two sorted vectors a, b and returns for each element of a the nearest element of b? As an example, (nearest [1 2 3 101 102 103] [0 10

I have a trouble building a tree structure from materialized path using ruby. Assuming I have a sorted result set (from couchdb): [ { :key => [], :value => Home }, { :key => [about], :val

I am using PrimeFaces JSF library, and I have a tree where each node is a checkbox: <p:tree selectionMode=checkbox...> This tree represents some files, and it is dynamicaly refreshed (polled)

The definition of heap given in wikipedia (http://en.wikipedia.org/wiki/Heap_(data_structure)) is In computer science, a heap is a specialized tree-based data structure that satisfies the heap proper

When is using a std::set more efficient (w.r.t. time) than using a std::vector along with make_heap/push_/pop_ for the priority queue in an A* operation? My guess is that if the vertices in the open l

I am trying to choose a Java data structure with the following properties Key: Long Value: Set Is there a structure that I can index into and add values to the Set? For example say I have the object &

So I am working on some homework and I have to complete a size balanced binary tree heap implementation, and I'm having some trouble with my enqueue function. We were given some code to start with and

T (1) = c T (n) = T (n/2) + dn How would I determine BigO of this quickly?

We are given an array of 2m - 1 distinct, comparable elements, indexed starting from 1. We can view the array as a complete binary tree: Node is placed at index i. Left child is placed at 2i. Right ch

What is difference between 'Shared Object Memory' and 'Heap Memory' in Java. Is it like 'Shared Object Memory' is superset of 'Heap Memory'? The source of this question is documentation of jmap. It pr

This question already has an answer here: How do I sort a Set to a List in Java? 8 answers HashMultimap return a set of values for a given key.how do i convert this java set to a sorted array?

I am refreshing on algorithm theory (from Cormen). There is an exercise in the chapter for binary tries that asks: Can the min-heap property be used to print out the keys of an n-node tree in sorted

If I run rails new _4.1.0.beta1_ rails4.1app --skip-test-unit I find this code in config/application.rb # Pick the frameworks you want: require active_model/railtie require active_record/railtie

What's the difference between DECLARE and SET using SQL (or more specifically MySQL)? Both can set variables it seems. I have read the MySQL docs and I did not understand the difference between the tw

I have all my environment variables in config/initializers/app_environment_variables.rb and this setup has been working so far, except now I need to use the variables in config/environments.rb and con

I am wondering if a table or particularly a heap file with a clustered index created on one of the attributes is sorted on that attribute.Is there a difference between a sorted heap file and a heap fi

i want select tree from id | parent_id | path | order --------------------------------------- 1 | 0 | /1/ | 1 2 | 1 | /1/2/ | 1 3 | 2 | /1/2/3/ | 1 4 | 1 | /1/4/ | 2 5 | 4 | /1/4/5/ | 2 6 | 4 | /1/4

Can anyone tell the differences between set and setRepeat methods of AlarmManager class ?

Hi this is an example in my data structure book and for this exercise was written that this is not a max heap,but it doesn't say its reason would you please help me that why it is not a max heap thank

I need an algorithm for computation convex hulls for sorted set of points in 3 and higher dimensions. Also I need in lower part of a convex hull and it is not necessary to construct a whole convex hul

I have a staging and production environment for my Rails application (running on Heroku). At the moment, there is a lot of stuff in staging.rb and production.rb that I'm having to define separately in

I have this sentence: My dog also likes eating sausage. And I get the following parse tree: (ROOT (S (NP (PRP$ My) (NN dog)) (ADVP (RB also)) (VP (VBZ likes) (S (VP (VBG eating) (NP (NN sausage))))) (

Given the following sorted integers: 1 2 3 4 5 6 7 8. How would you construct a balanced search tree? I would really appreciate if somebody could explain with without giving code examples. It is not

I have two confusions about sorted set, if we don't provide an Ordering to the elements, and the element has no default ordering such as integer or strings do, then how is the underlying sorted set

In Python, given a set of comparable, hashable elements s, is it better to hash frozenset(s) or tuple(sorted(s)).

How do you set up your .NET development tree? I use a structure like this: -projectname --config (where I put the configuration files) --doc (where I put all the document concerning the project: e-mai

This is one of the interview questions I recently came across. Given the root address of a complete or almost complete binary tree, we have to write a function to convert the tree to a max-heap. The

I'm trying to create some rank tree based on AVL tree with special requirements, lets assume that I have AVL tree with nodes, each node has 2 fields: id, priority my AVL tree is sorted by id, also I

Is there any difference between statements ALTER TABLE xxx DEFAULT CHARACTER SET utf8 and ALTER TABLE xxx CHARACTER SET utf8 ? MySQL documentation keeps silence about functionality of DEFAULT keyword.

Hi Im little confused with the difference between the depth and the diameter of a tree.Sorry if Its already asked but I couldn't find it.

I'm wonder if a max heap, or min heap tree is allowed to have duplicate values? Haven't been able to find the answer anywhere. Thanks guys!

When I try to add a sorted ASC index on the field MyId the oracle sql developer tool says: Index MyIdSortedIndex is defined identically to constraint PK_MyTable CREATE TABLE MyTable ( MyId NVARCHAR2