
Considering this simple example of programming code
A=XY+XZ ===> this coding requires 3 computational steps (2 multiplications and 1 addition)
alternatively,
A=X(Y+Z) ===> this coding requires only 2 computational steps (1 addition and 1 multiplication)
บางครั้งการเปลี่ยนแปลงโค๊ดเล็กๆน้อยๆก็ช่วยขั้นตอนในการคำนวณได้
ตัวอย่างข้างบน อันแรกคอมฯต้องคำนวณ 3 ที (คูณสองทีบวกที่นึง)
ส่วนอันที่สอง คำนวณแค่ 2 ที (บวกทีกับคูณที)
ลดขั้นตอนไปได้ 1/3
เรื่องง่ายๆแต่ว่าบางทีเราก็ละเลยไป ถ้าจุดประสงค์คือต้องการลดเวลาในการคำนวณล่ะก็ต้องไม่ลืมข้อนี้
้
No comments:
Post a Comment