Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม

ความแตกต่างระหว่าง Algorithm และ Flowchart

ในโพสต์นี้ เราจะทำความเข้าใจความแตกต่างระหว่าง flowchart และ algorithm

Algorithm

  • นิยามว่า sequence of well-defined steps
  • Steps ให้ solution/วิธีแก้ปัญหา
  • Systematic และ logical approach กระบวนการ defined step-wise
  • ให้ solution สำหรับปัญหาเฉพาะ
  • Solution แปลเป็น machine code แล้ว execute ให้ output
  • Simple operations รวมกันเป็น complex operation ที่คอมพิวเตอร์ทำได้ง่าย
  • Algorithms แทนได้ด้วย natural language, flowchart ฯลฯ
  • ยากต่อการเข้าใจ
  • ใช้ plain text
  • Debug ง่าย
  • Construction ยาก
  • ไม่มีกฎบังคับในการสร้าง
  • เข้าใจได้ว่า pseudocode สำหรับโปรแกรม

Algorithm for linear search

  • เริ่มค้นหา element จาก left-most ของ array
  • เปรียบเทียบ element ทุก iteration กับ item_to_be_searched
  • ถ้าไม่เจอ return -1
  • มิฉะนั้น return index ที่ element อยู่

Flowchart

  • Graphical representation ของ algorithm
  • Programmers ใช้เป็น program-planning tool เพื่อแก้ปัญหา
  • ใช้ symbols ที่เชื่อมต่อกัน
  • ช่วยบ่งบอก flow of control, information, และ processing
  • กระบวนการวาด flowchart เรียกว่า "flowcharting"
  • Diagram สร้างด้วยรูปทรงต่างๆ แทน flow of data
  • เข้าใจง่าย
  • Debug ยาก
  • สร้างง่าย
  • มีกฎบางอย่างต้องปฏิบัติ
  • Graphical representation ของ logic

Flowchart for Switch Statement

ความแตกต่างระหว่าง Algorithm และ Flowchart