Online Computer Science Algorithm Complexity Analyzer

Online Algorithm Complexity Analyzer

${data.description}

Example Implementation

${data.code}
`; elements.resultsContainer.innerHTML = html; // Re-attach listener for the new button document.getElementById('btn-download-pdf').addEventListener('click', downloadPdf); } function downloadPdf() { const algoKey = elements.algoSelect.value; const data = algoData[algoKey]; if (!data) return; const { jsPDF } = window.jspdf; const doc = new jsPDF(); doc.setFont('helvetica', 'bold'); doc.setFontSize(18); doc.text('Algorithm Complexity Report', doc.internal.pageSize.getWidth() / 2, 20, { align: 'center' }); doc.setFontSize(16); doc.text(data.name, 14, 35); doc.autoTable({ startY: 45, head: [['Complexity Type', 'Best', 'Average', 'Worst']], body: [ ['Time', data.time.best, data.time.average, data.time.worst], ], theme: 'grid', headStyles: { fillColor: [79, 70, 229] } }); doc.autoTable({ startY: doc.autoTable.previous.finalY + 2, head: [['Space Complexity', 'Value']], body: [['Space', data.space]], theme: 'grid', headStyles: { fillColor: [79, 70, 229] } }); doc.setFont('helvetica', 'bold'); doc.setFontSize(12); doc.text('Explanation', 14, doc.autoTable.previous.finalY + 15); doc.setFont('helvetica', 'normal'); doc.setFontSize(10); const splitDescription = doc.splitTextToSize(data.description, 180); doc.text(splitDescription, 14, doc.autoTable.previous.finalY + 22); doc.save(`${algoKey}-complexity-report.pdf`); } // --- Event Listeners --- elements.tabButtons.forEach(btn => btn.addEventListener('click', () => switchTab(btn.dataset.tab))); elements.algoSelect.addEventListener('change', (e) => displayAlgorithmInfo(e.target.value)); // --- Initial Load --- displayAlgorithmInfo(elements.algoSelect.value); });
Scroll to Top