Synthesizing antenna arrays for fifth-generation communication technology is the most significant issue in the electromagnetic industry and academia. This paper focused on a comprehensive algorithm to design an antenna array used as a 5G base station antenna. The proposed algorithm's goal has an array antenna with high gain, continuous wide scan angle without grating lobe, compact size, minimum cost, and simplicity of construction, particularly in the array feeding network's system. For this purpose, several factors, such as subarray topology, complex weighting function, the minimum number of RF elements, and the optimum number of microstrip layers will be intended. The desired topology is specified with the grating lobe's minimum level by comparing the array factor of different subarray combinations. We consider some limitations in our algorithm that improve the specification than before research and reduce the runtime algorithm. Moreover, the number of phase shifters is decreased to more than 53%, substantially improved than previous works. The GAPSO technique is then used to determine the excitation coefficients' optimal value to control SLL and beam scanning. Amplitude accuracy and phase are considered 0.1 and 1 degree, respectively, to avoid tolerance construction. The proposed method is also applied to design a linear array antenna using a 5G base station antenna in 28 GH. This aperiodic linear array's electromagnetic parameter consists of HPBW of 2.8◦, a gain of 20 dB, scanning up to ±50◦ in one direction, and SLL is below -15 dB.