Periodic structures, called diffraction gratings, play an important role in optical lithography. The diffraction of the incident field in multiple diffraction orders provides a way to accurately determine a position on a wafer on one hand and on the other hand it provides a test method to determine the quality of the photolithographic process. For both applications it is crucial to be able to find the actual shape of the structure to correct for damages or imperfections. When besides the incident field also the shape of a diffraction grating is known, we can compute the diffracted field by using the rigorous coupled-wave analysis (RCWA) or the C method. These methods solve Maxwell’s equations for time-harmonic fields directly, which is required because such a grating typically has a period smaller than the wavelength of the incident field. The basic idea of both methods is that they transform Maxwell’s equations into algebraic eigensystems, which have to be solved in order to obtain the diffracted field. The reconstruction of the grating shape is carried out by first making an initial guess of its shape. Next the computed diffracted field is compared to actual measurements and the difference between them determines how the shape parameters should be adjusted. For the reconstruction we make use of standard optimization techniques such as quasi-Newton methods to find local optima. We assume that the initial guess of the grating shape is close enough to its actual shape such that the optimum that is found is the actual shape and take more angles of incidence to make the optimization more robust. The focus of this thesis is finding the first-order derivative information of the diffracted field with respect to the shape parameters. This is possible using finite differences where the diffracted field is computed again for a neighbouring value of the shape parameter under consideration. However, straightforward differentiation of the relations within RCWA or the C method gives a more accurate, but also faster way to find this derivative information. When straightforward differentiation is used, we also have to find eigenvalue and eigenvector derivatives, but to determine these derivatives no additional eigenvalue systems have to be solved. This implies that the reconstruction process can be performed faster and more accurate. Besides the speed-up of the reconstruction, we also provide a firm mathematical basis to this sensitivity theory. The sensitivity of RCWA is tested for some specific grating structures, such as the binary grating, the trapezoidal grating and more advanced structures as the coated trapezoid and a stacked grating of multiple trapezoids. The simulations show that for the most simple structure, the binary grating, we have the derivatives with respect to shape parameters up to twice as fast as obtained with finite differences, depending on the truncation number of the Fourier series. When the number of physical shape parameters increases, the analytical method becomes increasingly faster than finite differences. For the stacked trapezoids, the analytical method is more than 10 times faster than finite differences. In practice, the grating shapes will be more and more complex and therefore, the analytical approach offers a more and more significant speed increase in the computations of the derivatives without loss of accuracy