Lung cancer is identified by the uncontrolled proliferation of cells in lung tissues. The timely detection of malignant cells in the lungs, crucial for processes such as oxygen provision and carbon dioxide elimination in the human body, is imperative. The application of deep learning for discerning lymph node involvement in CT scans and histopathological images has garnered widespread attention due to its potential impact on patient diagnosis and treatment. This paper suggests employing DenseNet for lung cancer detection, leveraging its ability to transmit learned features backward through each layer continuously. This characteristic not only reduces model parameters but also enhances the learning of local features, facilitating a better comprehension of the structural complexity and uneven distribution in CT scans and histopathological cancer images. Furthermore, DenseNet accompanied by an attention mechanism (ATT-DenseNet) allows the model to focus on specific parts of an image, giving more weight to relevant regions. Compared to existing algorithms, the ATT-DenseNet demonstrates a remarkable enhancement in accuracy, precision, recall, and the F1-Score. It achieves an average improvement of 20% in accuracy, 19.66% in precision, 24.33% in recall, and 22.33% in the F1-Score across these metrics. The motivation behind the research is to leverage deep learning technologies to enhance the precision and reliability of lung cancer diagnostics, thus addressing the gap in early detection and treatment. This pursuit is driven by the potential of deep learning models, like DenseNet, to provide significant improvements in analyzing complex medical images for better clinical outcomes.