Multilist Bernadus Anggo Seno Aji 2 Contoh Student
Multilist Bernadus Anggo Seno Aji
2 Contoh : Student - Course Misal kita ingin menyimpan data siswa dan hubungannya dengan mata kuliah yang diambil Relasi apa yang dihasilkan? Relasi N to M (banyak ke banyak) 2/19/2021
3 Contoh : Student - Course Student Bagaimana menggambarkan relasi antar data? Course 2/19/2021
4 Contoh : Student - Course Type infotype_student < id : string name : string > Type infotype_course < course_id : string course_name : string credit : integer > Type adr_student : pointer to elm_student Type adr_course : pointer to elm_course Type elm_student < info : infotype_student next : adr_student > Type list_student < first : adr_student > Type elm_course < info : infotype_course next : adr_course > Type list_course < first : adr_course > L 1 : list_student L 2 : list_course 2/19/2021
Variation 1 (M-N) 5 2/19/2021
Contoh : Student - Course 6 n-to-n relation L 1 A B / / Y X Y / D / Y Z / / / X Z L 2 X / C / Dalam kasus ini, masukkan list mata kuliah ke dalam setiap siswa (elm _student) untuk menggambarkan mata kuliah yang diambil siswa tersebut 2/19/2021
7 Contoh : Student - Course Type infotype_student < id : string name : string > Type infotype_course < course_id : string course_name : string credit : integer > Type adr_student : pointer to elm_student Type adr_course : pointer to elm_course Type elm_student < info : infotype_student next : adr_student course : list_course > Type elm_course < info : infotype_course next : adr_course > Type list_student < first : adr_student > Type list_course < first : adr_course > L 1 : list_student L 2 : list_course 2/19/2021
8 Operasi Insert Student dan Insert Course Tidak ada perubahan Search Student dan Search Class Tidak ada perubahan Add course ke satu student Delete course dari satu student Delete satu course 2/19/2021
Procedure add Course 9 Procedure add_course(i/o: L 1: list_student, i: L 2 : list_course, id : string, course_id : string) Dictionary P : adr_student Q, R : adr_course Algorithm … if ( P ≠ Nil and Q ≠ Nil ) then P search_student(L 1, id) Allocate(R) Q search_course(L 2, id_course) info(R) info(Q) //duplicate Q … insert. Last. Course(course, R) 2/19/2021
10 Procedure Delete Course Student Procedure del_course_student(i/o: L 1: list_student, i: id : string, course_id : string) Dictionary P : adr_student Q : adr_course Algorithm P search_student(L 1, id) if ( P ≠ Nil ) then Q search_course(course, course_id) delete. Course(course, Q) 2/19/2021
11 Procedure Delete Course Procedure del_course(i/o: L 1: list_student, i: L 2: list_course, id_course : string) Dictionary P : adr_student Q : adr_course L 3 : list_course Algorithm P first(L 1) while ( P ≠ Nil ) do Q search_course(course, course_id) delete. Course(course, Q) delete. Course(L 2, course_id) 2/19/2021
12 Procedure Delete Student Procedure del_student(i/o: L 1: list_student, i: id : string) Dictionary P : adr_student L 3 : list_course Algorithm P search_student(L 1, id) if ( P ≠ Nil ) then first(course(P)) = NULL delete. Student(L 1, P) 2/19/2021
13 Variasi Multi List Bergantung pada kasusnya, List L 2 mungkin tidak dibutuhkan Ketika list anak tidak terlampu penting untuk digabung menjadi sebuah list tersendiri Ketika list anak terlalu bervariasi Contoh : List karyawan dan list anak-anak mereka 2/19/2021
Procedure add Course 14 Procedure add_course(i/o: L 1: list_student, i: L 2 : list_course, id : string) Dictionary P : adr_student R : adr_course Algorithm P search_student(L 1, id) … … if ( P ≠ Nil ) then Allocate(R) input(info(R)) //input new data for child insert. Last. Course(course, R) 2/19/2021
15 Masalah dan Solusi diatas memiliki permasalahan: Dengan adanya duplikasi node anak, ukuran list suatu saatt bisa jadi terlalu besar Sulit menjaga konsistensi data apabila ingin memodifikasi node anak Solusi : Membuat elemen pada list anak menjadi berisi pointer yang menunjuk ke elemen pada list kedua 2/19/2021
- Slides: 15