Cognitive diagnostic assessment has drawn more attention in recent years, which attempts to evaluate whether an examinee has mastered those cognitive skills or attributes being measured in an assessment. To achieve this objective, a variety of cognitive diagnosis models have been developed. The core element of these models is the Q-matrix, which is a binary matrix that establishes item-to-attribute mapping in an exam. Traditionally, the Q-matrix is fixed and designed by domain experts. However, there are concerns that some domain experts might neglect certain attributes, and that different experts could have different opinions. It is therefore of practical importance to develop an automated method for estimating the attribute-to-item mapping, and the purpose of this study is to develop a Markov Chain Monte Carlo (MCMC) algorithm to estimate the Q-matrix in a Bayesian framework.