  To maximize the received power at a user equipment, the problem of optimizing
a reconfigurable intelligent surface (RIS) with a limited phase range R <
2{\pi} and nonuniform discrete phase shifts with adjustable gains is addressed.
Necessary and sufficient conditions to achieve this maximization are given.
These conditions are employed in two algorithms to achieve the global optimum
in linear time for R {\ge} {\pi} and R < {\pi}, where R is the limited RIS
phase range. With a total number of N(2K + 1) complex vector additions, it is
shown for R {\ge} {\pi} and R < {\pi} that the global optimality is achieved in
NK or fewer and N(K + 1) or fewer steps, respectively, where N is the number of
RIS elements and K is the number of discrete phase shifts which may be placed
nonuniformly over the limited phase range R. In addition, we define two
quantization algorithms that we call nonuniform polar quantization (NPQ)
algorithm and extended nonuniform polar quantization (ENPQ) algorithm, where
the latter is a novel quantization algorithm for RISs with a significant phase
range restriction, i.e., R < {\pi}. With NPQ, we provide a closed-form solution
for the approximation ratio with which an arbitrary set of nonuniform discrete
phase shifts can approximate the continuous solution. We also show that with a
phase range limitation, equal separation among the nonuniform discrete phase
shifts maximizes the normalized performance. Furthermore, we show that the gain
of using K {\ge} 3 with R < {\pi}/2 and K {\ge} 4 with R < {\pi} is only
marginal. Finally, we prove that when R < 2{\pi}/3, ON/OFF selection for the
RIS elements brings significant performance compared to the case when the RIS
elements are strictly ON.
