งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

รายวิชา ง40206 โครงสร้างข้อมูลและขั้นตอนวิธี

งานนำเสนอที่คล้ายกัน


งานนำเสนอเรื่อง: "รายวิชา ง40206 โครงสร้างข้อมูลและขั้นตอนวิธี"— ใบสำเนางานนำเสนอ:

1 รายวิชา ง40206 โครงสร้างข้อมูลและขั้นตอนวิธี
โรงเรียนมหิดลวิทยานุสรณ์

2 ความรู้เบื้องต้นของโครงสร้างข้อมูลและขั้นตอนวิธี

3 ความหมาย “โครงสร้างข้อมูล”
ความสัมพันธ์ระหว่างข้อมูลที่อยู่ในโครงสร้างซึ่งจะถูกกำหนดให้มีรูปแบบที่เหมาะสม เพื่อการนำมาประยุกต์ใช้ในโปรแกรม

4 รูปแบบของโครงสร้างข้อมูล
ด้านกายภาพ Primitive Data Type เช่น char, int, float Structure Data Type เช่น array, struct ด้านตรรกกะ - Linear Data Structure - Nonlinear Data Structure 5 A C K S 3 8 -1 3 4 5 8 12 -1 4 12

5 วัตถุประสงค์ของการศึกษาโครงสร้างข้อมูลและขั้นตอนวิธี
โปรแกรมทำงานได้อย่างรวดเร็ว ใช้เนื้อที่หน่วยความจำน้อยที่สุด

6 การออกแบบโปรแกรม/ขั้นตอนวิธี
วางแผนการเขียนโปรแกรม ออกแบบโปรแกรม เอกสารประกอบโปรแกรม และเทคนิคการเขียนโปรแกรม เขียนโปรแกรม แก้ไขโปรแกรม จัดทำเอกสารคู่มือผู้ใช้ บำรุงรักษา

7 ขั้นตอนวิธีหรืออัลกอริทึม (Algorithm)
อัลกอริทึมเป็นขั้นตอนการแก้ปัญหา การเขียนอัลกอริทึมถือว่าเป็นเรื่องที่สำคัญ ในการเขียนโปรแกรม อัลกอริทึมที่ดีต้องประกอบด้วย แต่ละขั้นในอัลกอริทึมต้องชัดเจนและถูกต้อง ลำดับการเขียนคำสั่งต้องเป็นไปตามลำดับที่ถูกต้อง ชัดเจน เพื่อนำไปสู่คำตอบที่ถูกต้อง อัลกอริทึมต้องมีจุดสิ้นสุดเสมอ ใช้เวลาในการประมวลผลน้อย แก้ไขดัดแปลงได้ง่าย

8 ตัวอย่างโจทย์ Let's say that you have a friend arriving at the airport, and your friend needs to get from the airport to your house. Here are four different algorithms that you might give your friend for getting to your home:

9 ตัวอย่างอัลกอริทึม The taxi algorithm: Go to the taxi stand.
Get in a taxi. Give the driver my address. The call-me algorithm: When your plane arrives, call my cell phone. Meet me outside baggage claim.

10 ตัวอย่างอัลกอริทึม The rent-a-car algorithm:
Take the shuttle to the rental car place. Rent a car. Follow the directions to get to my house. The bus algorithm: Outside baggage claim, catch bus number 70. Transfer to bus 14 on Main Street. Get off on Elm street. Walk two blocks north to my house.

11 เทคนิคที่ช่วยในการออกแบบ
ผังงาน (Flowchart) ผังงานระบบ (System Flowchart) ผังงานโปรแกรม (Program Flowchart) รหัสเทียม (Pseudocode) ไม่ขึ้นกับภาษาคอมพิวเตอร์ภาษาใดภาษาหนึ่ง อาจเป็นภาษาไทยหรือภาษาอื่นก็ได้ แต่การใช้ภาษาอังกฤษจะสะดวกที่สุด

12 Pseudocode เป็นคำสั่งที่มีลักษณะการเขียนใกล้เคียงกับภาษาอังกฤษ แต่มีโครงสร้างเกือบจะเป็นภาษาโปรแกรม เช่น เริ่มต้นอาจให้มีคำว่า BEGIN จบลงให้ใช้ END อ่าน เขียนข้อมูลอาจใช้ READ และ PRINT การทดสอบเงื่อนไขอาจใช้ IF , ELSE , ELSEIF การทำซ้ำอาจใช้ WHILE , DO ENDWHILE เป็นต้น

13 ตัวอย่าง Pseudocode BEGIN READ A, B SUM = A+B IF SUM > 10 THEN
PRINT SUM ELSE PRINT A-B END

14 ตัวอย่าง Pseudocode Algorithm arrayMax(A,n)
Input: An array A storing n integers. Output: The maximum element in A. currentMax < A[0] for I <- 1 to n-1 do if currentMax < A[i] then currentMax <- A[i] return currentMax

15 ลักษณะโปรแกรมแบบมีโครงสร้างที่ดี
ง่ายต่อการทำความเข้าใจและการอ่าน ใช้โครงสร้างควบคุมที่ชัดเจนและรัดกุม พยายามใช้คำสั่งแบบ goto ให้น้อยที่สุด Good Programs run correctly run efficiently be easy to read and understand be easy to debug and be easy to modify.

16 การจัดเก็บข้อมูลในหน่วยความจำหลัก
Static memory allocation เช่น การประกาศตัวแปร int a, b; char s[10], c; static float f; Dynamic memory allocation เช่น การใช้ pointer และมีการจองเนื้อที่ในหน่วยความจำด้วยคำสั่ง malloc(); int *p; p = malloc(sizeof(int)*2);

17 การวัดประสิทธิภาพของโปรแกรม
Space : โปรแกรมนั้นใช้เนื้อที่ความจำมากน้อยแค่ไหน Time : โปรแกรมนั้นใช้อักกอริทึม (Algorithm) ที่เร็วเพียงใด

18 Running time analysis Most algorithms have running time proportional to one of the following function: 1 most programs are executed once or at most only a few times. Its running time is constant. N When running time is linear, it is the case that a small amount of processing is done on each input element. N log N algorithms that solve a problem by breaking it up into smaller subprogram, solving them independently, and then combining the solutions.

19 Running time analysis N2 When running time is quadratic, it is for use only on relatively small problems. They arise in algorithms that process all pairs of data items (perhaps in a double nested loop) 2N Few algorithms with exponential running time are likely to be in appropriate for practical use, such algorithms arise as “brute-force” solutions to problems.

20 การวิเคราะห์ความเร็วของ Algorithm
ช้า

21 n2 n log n n log n n3 2n

22 Running time calculations
A simple Example Int sum(int n) { int i, partialSum; partialSum = 0; //1 for(i=1;i<=N;i++) //2 partialSum += i*i*i; //3 return partialSum; } -> Count for 1 unit per time executed -> Count for 2N+1 units -> 4N units The total is 6N+2 This function is O(N)

23 Running time calculations
A simple Example Int factorial(int n) { int fac if((n==0)||(n=1)) fac = 1; else fac = n*factorial(n-1); } -> Running time = 1 -> เรียกตัวเอง N ครั้ง This function is O(N)


ดาวน์โหลด ppt รายวิชา ง40206 โครงสร้างข้อมูลและขั้นตอนวิธี

งานนำเสนอที่คล้ายกัน


Ads by Google