• Register
2 votes

Problem :

Currently I am preparing for interview and I am stuck with one doubt related to binary tree as below

“The time required in best case for search operation in binary tree is”

Can somebody solve my doubt related to binary tree?

8 5 2
3,230 points

Please log in or register to answer this question.

1 Answer

2 votes

Solution :

I was going through the long list of questions and after reading your question I came to know that you are preparing for some interview so I am trying to answer it for you.

The time taken by balanced binary tree search tree for worst case, best case and average case is as below:

For Worst case lookup the time taken is O(log n).

For Best case lookup the time taken is O(1).

For Average case lookup the time taken is O(log n).

The worst case look up in the binary tree is the most exciting and also it is very easily observed by recognizing its first level of the binary tree which has just one node and the second has only two nodes and the third one has only four nodes and so on like this. So we can say that the number of nodes in the binary tree for depth n is exactly 2^n - 1.

8 4
5,680 points

Related questions

0 votes
1 answer 17 views
Problem: How do you delete a node in a binary tree in Java? How do you delete a node in a binary search tree? How many cases does it take to remove a node from a binary search tree? What is binary search tree insertion and deletion in BST? We have discussed BST search and insert operations. In this post, delete operation is discussed. When we delete a node, three possibilities arise.
asked Dec 5, 2020 Mashhoodch 9.3k points
0 votes
1 answer 10 views
Problem Hey, i have created a binary search tree and added some random values. I want to implement a function to delete the node. But due to some reason it is not working. When i am trying to delete a node . its showing a connection problem saying that parent of the deleted node and ... \nThe tree is empty."; else { Node* temp = root; while(temp->left != NULL) temp = temp->left; return temp; } }
asked Dec 23, 2020 chris jordan 2.4k points
1 vote
1 answer 13 views
Problem: I was studying the data structure and ended up here in (BST) Binary Search Tree. I do understand how the search tree works. Now I want to write a python program that reflects the BST and its operation. Could you please help me to write such a program? I would recognize your help. Thanks.
asked Jun 26, 2020 adamSw 11.3k points
0 votes
1 answer 12 views
Problem: My question is, how to implement the insert and delete implementation of an element in a maximum heap. (For the structure of it it would be as follows) [Header file] #ifndef HEAP_H_ #define HEAP_H_ #include "node.h" class heap {// Implementation of a max heap (maximum heap), through ... : empty () {// Check if the heap is empty. if (root == NULL) { return true; } else { return false; } }
asked Jan 24 sasha 13.2k points
0 votes
1 answer 9 views
Problem: The problem is that you can only add nodes to level 1 of the tree BinarySearchTree: tree class root: node type pointer (the root of the tree) TreeNode: node class left: pointer left right: pointers to the right both part of the TreeNode class temp: temporary pointer used to ... { if(temp->left == nullptr) temp->left = new TreeNode(value); else { temp->right = new TreeNode(value); } } }
asked Dec 4, 2020 sasha 13.2k points
0 votes
1 answer 28 views
Probelm How many distinct binary search trees can be created out of 4 distinct keys
asked Feb 9 charles mathews 3.8k points
0 votes
1 answer 81 views
Problem Hey, I just want to know about red black tree. Please answer me with an example.
asked Dec 8, 2020 chris jordan 2.4k points
1 vote
1 answer 122 views
Problem: I am very new to Java and all its concepts. I want to know what is the need of build-time dependency’s presence when any application is run ? I am struggling to get this information but I am unable to find much details about this concept. Please help me in getting all the details of the concept.
asked May 18, 2020 Martin K 6.6k points
0 votes
1 answer 124 views
I want to know how to trace the count of 1 in the binary representation.
asked Sep 17, 2020 Daniel Anderson 4k points