edited by
6,284 views
43 votes
43 votes

Let $P_1, P_2,\dots , P_n $be $n$ points in the $xy$-plane such that no three of them are collinear. For every pair of points $P_i$ and $P_j$, let $L_{ij}$ be the line passing through them. Let $L_{ab}$ be the line with the steepest gradient among all $n(n -1)/2$ lines.

The time complexity of the best algorithm for finding $P_a$ and $P_b$ is

  1. $\Theta\left(n\right)$
  2. $\Theta\left(n\log n\right)$
  3. $\Theta\left(n\log^2 n\right)$
  4. $\Theta\left(n^2\right)$
edited by

6 Answers

1 votes
1 votes

As here we have  $P1,P2,.,……,Pn$  points in the $X-Y$ $plane$  and among them no three are collinear .

and for the steepest slope as we know  $slope=tanӨ= (y2-y1)/(x2-x1)$   

so the for the steepest slope $(i.e$   $90°)$ because for the other slopes (whether it be greater than 90° or not will not be the steepest) .

now lets , maintain an array for all the points that we have in the $X-Y$ plane .in sorted order $[Ө(nlogn) ]$

P1 P2 P3 P4. P5 P6        .    . ………………………….. Pn  

now lets ,

fix one point $(start$ $with$ $P1)$

selecting $P1$ will take constant time now in the array from ($P2$ $to$ $Pn$) perform $binary$ $search$ and for every point that we will get we have to calculate the slope between that point and $P1$ so this process will take ( $Ө(logn) + c$)  constant time for just performing the computations for the slope.

similarly do it for all the points till $Pn$ (in the worst case).

so for selecting $constant$ $time$ is required and we are selecting all the points and performing binary search on rest of the points in the array.

so TC will be 

$TC = Ө(1)*Ө(n)$ [for selecting all points once]  *  $Ө(logn)$[for binary search everytime]  + $Ө(nlogn)$ [for sorting the array]

so,   $TC$  =  $Ө(nlogn)$ + $Ө(nlogn)$  = $Ө(nlogn)$

$OPTION$ $B$ $IS$ $CORRECT!$

edited by
Answer:

Related questions

51 votes
51 votes
3 answers
1