Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How will you rebuild a given BST into AVL which contains exactly the same keys?
The algorithm running time should be O(n) and its allowed to use O(n) additional space. Any ideas?
The whole pseudo-code is not necessary, any idea or suggestion would be appreciated!
Thanks!
Extract all keys to sorted array (O(n) space) with suitable traversal method (O(n) time)
Build perfectly balanced tree from sorted array (O(n) time) (simultaneously filling AVL balance factors for all nodes)
I 've omitted the details for your own research
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I need to design a voting system on a high level that associates voters with their decision in sorted order by name.
I understand that I should implement a sorted map, and it seems like we need a map that performs best with random insertions. So I was wondering which of the above data structures would work best.
If you are sorting the objects based purely by name, I would say that a Binary Search Tree would work well.
If you are particularly worried about search time complexity, you can implement a balanced tree, such as an AVL tree or a splay tree. Doing this would get your search time complexity towards logarithmic, which is what you're after!
A heap or a BST. Trie linked list and array would have a higher search complexity.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have an unsorted array with n*n order. How to get the largest element from each row with complexity O(n logn).
You can not possibly do this. You have an input of size O(n * n) and each element of this input is a possible answer. You can not get better than O(n * n).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am looking for an efficient algorithm for finding if at least 'X' number of MST exist in a graph. Any pointers?
This doesn't flesh out a full algorithm, but the accepted answer to An algorithm to see if there are exactly two MSTs in a graph? (by #j_random_hacker) brings up a point that will probably help you a lot. Taken from his answer:
Furthermore, every MST can be produced by choosing some particular way
to order every set of equal-weight edges, and then running the Kruskal
algorithm.
You could probably write up an algorithm that takes advantage of this to get the number of MSTs. Well, just straight using this fact and nothing else probably doesn't get to "efficient algorithm" territory, though I imagine that any efficient algorithm is going to be taking advantage of a couple of similar facts. I'll add more results if I find any.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am a mechanical student and I have changed my field to Computers. Need to get through the algorithms class. This question is one of the exercise questions
If the max heap algorithm's running time is O(klogn) then is there any algorithm which has better running time than this?
Print and remove the root k times;
O(k log n);
Yes.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I want to know the difference between these three i know that in Divide and conquer and Dynamic algos the difference between these two is that both divides the broblem in small part but in D&Q the the small parts of the problem are dependent on each other whereas not the case with dynamic. but what about greedy ?
a simplified view outlining the gist of both schemes:
greedy algorithms neither postpone nor revise their decisions (ie. no backtracking).
d&q algorithms merge the results of the very same algo applied to subsets of the data
examples:
greedy: kruskal's minimal spanning tree
select an edge from a sorted list, check, decide, never visit it again.
d&q: merge sort
split the data set into 2 halves,
merge sort them,
combine the results by skimming through both partial results in parallel, stopping, choosing or advancing as appropriate.