retagged by
972 views
7 votes
7 votes
You are given a complete binary tree (each level must be full except the last) on $n$ vertices. Each vertex $v$ is labeled by an integer value $x_v$. Say that a vertex is a local minimum if its label is less than the labels of each of its neighbors (neighbors include the parent and the children). Assuming that all the labels are distinct, what is the worst-case time complexity of the most efficient algorithm to find a local minimum in the tree?
  1. $\theta(n)$
  2. $\theta(\sqrt{n})$
  3. $\theta(\log n)$
  4. $\theta(n \log n)$
retagged by

3 Answers

4 votes
4 votes

The algorithm is as follows:

  1. Let $v$ be the root.
  2. If $v$ is a local minimum, output $v$.
  3. Otherwise, update $v$ to be a child that has a smaller value, and go to step (b).

Since, the algorithm moves to a child in each step, the running time is at most the depth of the tree, which is $O(\log n)$.

edited by
1 votes
1 votes
$Answer : O(logn)$

Hint : A leaf node is considered as local minimum if its value is less than its parent node.
0 votes
0 votes

Please find the explanation below.

Hope, this helps.

Answer:

Related questions

490
views
1 answers
3 votes
GO Classes asked Jan 28
490 views
Let $\mathrm{T}$ be the smallest AVL tree of height $h$. How many nodes does it have, if the smallest AVL tree of height $h-2$ has $m$ nodes and the smallest AVL tree of height $h-3$ has $k$ nodes?$m+k+2$m+2 k$2 m+k$2 m+k+2$
572
views
2 answers
4 votes
GO Classes asked Jan 28
572 views
Consider the null-terminated linked list of four integers $\textsf{1->2->3->4->NULL},$ and the variable 'list' points to the head of the linked list. Upon running the ... ->next->next>next = list->next>next; LINE Y: list = list->next->next;
570
views
1 answers
6 votes
GO Classes asked Jan 28
570 views
Suppose we constructed the binary search tree shown by starting with an empty tree and inserting one element at a time from an input sequence, without any rotations or other ... $3$ came before $14$ and $16$ came before $28.$
628
views
1 answers
3 votes
GO Classes asked Jan 28
628 views
Suppose that a binary min-heap stores six elements with priorities $10,20,30,40,50$, and $60$ in its array $\text{A}.$ What is the largest of these items that could be stored in $\text{A}[2]?$ (indexing starts from zero)