Binary Search Tree order of insert when we have an estimate ahead of time
I am currently reading "Algorithms Fourth Edition" by Robert Sedgewick and Kevin Wayne. I have question about:
3.2.5 Suppose that we have an estimate ahead of time of how often search keys are to be accessed in a BST, and the freedom to insert items in any order that we desire. Should the keys be inserted into the tree in increasing order, decreasing order of likely frequency of access, or some other order? Explain your answer.
Obviously, the perfect situation is to have at root the item that is most accessed, then at its direct ancestors, the next items in terms of frequency of access and so on and so on.
However, this is BST and as such we have to insert them according to its specifics.
Shall I consider in this task all the combinations?
For example, if we have items 1 (accessed 1000 times), 2 (999 times) and 3 (999). The tree with root 2 and ancestors 1 and 3 is the best solution I think.
Its sounds logical to me, to strive to have balanced tree. However this again depends on the input. If we have smallest item accessed 10 000 times and next 10 items accessed only once, then the smallest shall be root and the tree will not
be perfectly balanced.
I will also appreciate guidance, not direct answers.
algorithm search binary-search-tree
add a comment |
I am currently reading "Algorithms Fourth Edition" by Robert Sedgewick and Kevin Wayne. I have question about:
3.2.5 Suppose that we have an estimate ahead of time of how often search keys are to be accessed in a BST, and the freedom to insert items in any order that we desire. Should the keys be inserted into the tree in increasing order, decreasing order of likely frequency of access, or some other order? Explain your answer.
Obviously, the perfect situation is to have at root the item that is most accessed, then at its direct ancestors, the next items in terms of frequency of access and so on and so on.
However, this is BST and as such we have to insert them according to its specifics.
Shall I consider in this task all the combinations?
For example, if we have items 1 (accessed 1000 times), 2 (999 times) and 3 (999). The tree with root 2 and ancestors 1 and 3 is the best solution I think.
Its sounds logical to me, to strive to have balanced tree. However this again depends on the input. If we have smallest item accessed 10 000 times and next 10 items accessed only once, then the smallest shall be root and the tree will not
be perfectly balanced.
I will also appreciate guidance, not direct answers.
algorithm search binary-search-tree
2
probably related to static optimal binary search tree
– juvian
Nov 24 '18 at 21:20
Thanks @juvian, optimal BST is exactly what I was searching for.
– John
Dec 5 '18 at 20:14
add a comment |
I am currently reading "Algorithms Fourth Edition" by Robert Sedgewick and Kevin Wayne. I have question about:
3.2.5 Suppose that we have an estimate ahead of time of how often search keys are to be accessed in a BST, and the freedom to insert items in any order that we desire. Should the keys be inserted into the tree in increasing order, decreasing order of likely frequency of access, or some other order? Explain your answer.
Obviously, the perfect situation is to have at root the item that is most accessed, then at its direct ancestors, the next items in terms of frequency of access and so on and so on.
However, this is BST and as such we have to insert them according to its specifics.
Shall I consider in this task all the combinations?
For example, if we have items 1 (accessed 1000 times), 2 (999 times) and 3 (999). The tree with root 2 and ancestors 1 and 3 is the best solution I think.
Its sounds logical to me, to strive to have balanced tree. However this again depends on the input. If we have smallest item accessed 10 000 times and next 10 items accessed only once, then the smallest shall be root and the tree will not
be perfectly balanced.
I will also appreciate guidance, not direct answers.
algorithm search binary-search-tree
I am currently reading "Algorithms Fourth Edition" by Robert Sedgewick and Kevin Wayne. I have question about:
3.2.5 Suppose that we have an estimate ahead of time of how often search keys are to be accessed in a BST, and the freedom to insert items in any order that we desire. Should the keys be inserted into the tree in increasing order, decreasing order of likely frequency of access, or some other order? Explain your answer.
Obviously, the perfect situation is to have at root the item that is most accessed, then at its direct ancestors, the next items in terms of frequency of access and so on and so on.
However, this is BST and as such we have to insert them according to its specifics.
Shall I consider in this task all the combinations?
For example, if we have items 1 (accessed 1000 times), 2 (999 times) and 3 (999). The tree with root 2 and ancestors 1 and 3 is the best solution I think.
Its sounds logical to me, to strive to have balanced tree. However this again depends on the input. If we have smallest item accessed 10 000 times and next 10 items accessed only once, then the smallest shall be root and the tree will not
be perfectly balanced.
I will also appreciate guidance, not direct answers.
algorithm search binary-search-tree
algorithm search binary-search-tree
edited Nov 24 '18 at 20:47
user2864740
43.7k670148
43.7k670148
asked Nov 24 '18 at 20:41
JohnJohn
515
515
2
probably related to static optimal binary search tree
– juvian
Nov 24 '18 at 21:20
Thanks @juvian, optimal BST is exactly what I was searching for.
– John
Dec 5 '18 at 20:14
add a comment |
2
probably related to static optimal binary search tree
– juvian
Nov 24 '18 at 21:20
Thanks @juvian, optimal BST is exactly what I was searching for.
– John
Dec 5 '18 at 20:14
2
2
probably related to static optimal binary search tree
– juvian
Nov 24 '18 at 21:20
probably related to static optimal binary search tree
– juvian
Nov 24 '18 at 21:20
Thanks @juvian, optimal BST is exactly what I was searching for.
– John
Dec 5 '18 at 20:14
Thanks @juvian, optimal BST is exactly what I was searching for.
– John
Dec 5 '18 at 20:14
add a comment |
1 Answer
1
active
oldest
votes
Check out this article:
Data structures and their algorithms
It goes in depth on this exact thought.
Thanks for the provided material. It seems optimal BST is what I was searching for.
– John
Dec 5 '18 at 20:13
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462185%2fbinary-search-tree-order-of-insert-when-we-have-an-estimate-ahead-of-time%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Check out this article:
Data structures and their algorithms
It goes in depth on this exact thought.
Thanks for the provided material. It seems optimal BST is what I was searching for.
– John
Dec 5 '18 at 20:13
add a comment |
Check out this article:
Data structures and their algorithms
It goes in depth on this exact thought.
Thanks for the provided material. It seems optimal BST is what I was searching for.
– John
Dec 5 '18 at 20:13
add a comment |
Check out this article:
Data structures and their algorithms
It goes in depth on this exact thought.
Check out this article:
Data structures and their algorithms
It goes in depth on this exact thought.
answered Nov 26 '18 at 18:52
Ben TildenBen Tilden
496
496
Thanks for the provided material. It seems optimal BST is what I was searching for.
– John
Dec 5 '18 at 20:13
add a comment |
Thanks for the provided material. It seems optimal BST is what I was searching for.
– John
Dec 5 '18 at 20:13
Thanks for the provided material. It seems optimal BST is what I was searching for.
– John
Dec 5 '18 at 20:13
Thanks for the provided material. It seems optimal BST is what I was searching for.
– John
Dec 5 '18 at 20:13
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462185%2fbinary-search-tree-order-of-insert-when-we-have-an-estimate-ahead-of-time%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
probably related to static optimal binary search tree
– juvian
Nov 24 '18 at 21:20
Thanks @juvian, optimal BST is exactly what I was searching for.
– John
Dec 5 '18 at 20:14