Send to: MM Irfan Subakti CC to Muhammad Ryanda Nugraha M with the. IF184401_DAA(F)_MID_NRP_Name.

Similar documents
CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

Writeup for first project of CMSC 420: Data Structures Section 0102, Summer Theme: Threaded AVL Trees

COMBINING TABLES. Akademi Audit Negara. CAATs ASAS ACL / 1

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

UNIVERSITI SAINS MALAYSIA. CPT103/ CPM211 Struktur Data & Paradigma Pengaturcaraan

CSE332 Summer 2010: Midterm Exam Sample Solutions

Exam Data structures DAT036/DAT037/DIT960

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

CS2110 Assignment 3 Inheritance and Trees, Summer 2008

Programming Abstractions

6.1 Skip List, Binary Search Tree

Pengenalan Sistem Maklumat Dalam Pendidikan

COMP 250 Midterm #2 March 11 th 2013

ssk 2023 asas komunikasi dan rangkaian TOPIK 4.0 PENGALAMATAN RANGKAIAN Minggu 11

CSE 373 OCTOBER 11 TH TRAVERSALS AND AVL

OPTIMIZE PERCEPTUALITY OF DIGITAL IMAGE FROM ENCRYPTION BASED ON QUADTREE HUSSEIN A. HUSSEIN

Midterm solutions. n f 3 (n) = 3

LISTING PROGRAM 1. Halaman Intro Opening Layer Enter Layer Exit Layer Music 2. Halaman Menu Layer Background Universitas Sumatera Utara

Data Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA === Homework submission instructions ===

Largest Online Community of VU Students

UNIVERSITI SAINS MALAYSIA. CPT111 Principles of Programming [Prinsip Pengaturcaraan]

Midterm Exam 2 CS 455, Spring 2011

Persekitaran Pengaturcaraan Arduino

University of Massachusetts Amherst, Electrical and Computer Engineering

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

CSE 373 APRIL 17 TH TREE BALANCE AND AVL

Programming Project 5: NYPD Motor Vehicle Collisions Analysis

Second Examination Solution

ECE242 Data Structures and Algorithms Fall 2008

CS 315 Data Structures mid-term 2

CS 216 Exam 1 Fall SOLUTION

Major2 Examination Term: 162 Year: 2016/2017

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

CPSC 35 Midterm Exam

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

CS2013 Course Syllabus Spring 2018 Lecture: Mon/Wed 2:00 P.M. 2:50 P.M. SH C259 Lab: Mon/Wed 2:50 P.M. 4:00 P.M. SH C259

Comp Intermediate Programming EXAM #2 March 30, 2005 Rice University - Instructors: Cox & Nguyen

COMP251: Algorithms and Data Structures. Jérôme Waldispühl School of Computer Science McGill University

Comp Intermediate Programming EXAM #2 April 02, 2003 Rice University - Instructors: Cox & Nguyen

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

Visitor Management System

Final Examination Term: 162 Year: 2016/2017 (v2)

Exam Data structures DAT036/DAT037/DIT960

SLANTING EDGE METHOD FOR MODULATION TRANSFER FUNCTION COMPUTATION OF X-RAY SYSTEM FARHANK SABER BRAIM UNIVERSITI TEKNOLOGI MALAYSIA

Comp Intermediate Programming EXAM #1 February 16, 2004 Rice University - Instructors: Cox & Nguyen

Computer Science Foundation Exam. Dec. 19, 2003 COMPUTER SCIENCE I. Section I A. No Calculators! KEY

Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree.

ECE250: Algorithms and Data Structures Midterm Review

Comp Intermediate Programming EXAM #2 April 03, 2002 Rice University - Instructors: Cox & Nguyen

CmpSci 187: Programming with Data Structures Spring 2015

Instructions PLEASE READ (notice bold and underlined phrases)

Week 2. TA Lab Consulting - See schedule (cs400 home pages) Peer Mentoring available - Friday 8am-12pm, 12:15-1:30pm in 1289CS

CS165 Practice Midterm Problems Fall 2018

Q1 Q2 Q3 Q4 Q5 Q6 Total

INSTRUCTION: This section consists of FOUR (4) questions. Answer ALL questions. ARAHAN: Bahagian ini mengandungi EMPAT (4) soalan. Jawab SEMUA soalan.

Prelim 2. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader

Final exam. CS 2110, December 15, 2016, 9:00AM

Data Structures in Java

Programm- & Systemverifikation

Prelim 1. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants

This item is protected by original copyright

SECURE-SPIN WITH HASHING TO SUPPORT MOBILITY AND SECURITY IN WIRELESS SENSOR NETWORK MOHAMMAD HOSSEIN AMRI UNIVERSITI TEKNOLOGI MALAYSIA

Data Structure (CS301)

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid

Midterm Exam 2 CS 455, Fall 2014

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid. Fall 2018

...a- JEE ELEKTRONIK DIGIT II. UNlVERSlTl SAINS MALAYSIA. Peperiksaan Semester Kedua Sidang Akademik FebruarVMac 2003.

(the bubble footer is automatically inserted in this space)

INF2220: algorithms and data structures Series 1

The American University in Cairo Department of Computer Science & Engineeringt CSCI &09 Dr. KHALIL Exam-I Fall 2009

Trees. Reading: Weiss, Chapter 4. Cpt S 223, Fall 2007 Copyright: Washington State University

ENHANCING TIME-STAMPING TECHNIQUE BY IMPLEMENTING MEDIA ACCESS CONTROL ADDRESS PACU PUTRA SUARLI

Analysis of Algorithms

Course Review for. Cpt S 223 Fall Cpt S 223. School of EECS, WSU

COS 226 Algorithms and Data Structures Fall Midterm

CS 223: Data Structures and Programming Techniques. Exam 2

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

CS 216 Fall 2007 Final Exam Page 1 of 10 Name: ID:

DIT960 Datastrukturer

BRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE

9/26/2018 Data Structure & Algorithm. Assignment04: 3 parts Quiz: recursion, insertionsort, trees Basic concept: Linked-List Priority queues Heaps

Chapter 4 Expression & Operators

Announcements. Midterm exam 2, Thursday, May 18. Today s topic: Binary trees (Ch. 8) Next topic: Priority queues and heaps. Break around 11:45am

IMPROVED IMAGE COMPRESSION SCHEME USING HYBRID OF DISCRETE FOURIER, WAVELETS AND COSINE TRANSFORMATION MOH DALI MOUSTAFA ALSAYYH

Data Structures Brett Bernstein

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Instructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII.

1.00/1.001 Introduction to Computers and Engineering Problem Solving. Final Exam

: Advanced Programming Final Exam Summer 2008 June 27, 2008

Data Structures in Java

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully.

Name Section Number. CS210 Exam #3 *** PLEASE TURN OFF ALL CELL PHONES*** Practice

CSE373 Fall 2013, Midterm Examination October 18, 2013

Lecture 12 TREES II CS2110 Spring 2018

Data Structure and Algorithm, Spring 2013 Midterm Examination 120 points Time: 2:20pm-5:20pm (180 minutes), Tuesday, April 16, 2013

CS 315 Data Structures Spring 2012 Final examination Total Points: 80

NAME: c. (true or false) The median is always stored at the root of a binary search tree.

UNIVERSITI SAINS MALAYSIA. CPT103/CPM211 Struktur Data & Paradigma Pengaturcaraan

CREATING USER ID AND PASSWORD : NOTA PENTING NOTA PENTING SEBELUM MEMULAKAN PROSES CREATE USER ID & PASSWORD

Transcription:

IF184401 Design & Analysis of Algorithms (F) Midterm Exam Starting date: 9 March 2019 Deadline: 16 March 2019, 23:59 WIB. Exam type: Open Send to: MM Irfan Subakti <yifana@gmail.com> CC to Muhammad Ryanda Nugraha M <muhammadryandanm@gmail.com> with the subject: IF184401_DAA(F)_MID_NRP_Name File type and format: A full report of the source code, output and analysis; in PDF format. Put this report along with your declaration and all of.java files (or any other programming language s source code) into 1 (one).zip file. Filename format: IF184401_DAA(F)_MID_NRP_Name.ZIP Instruction Please do these steps as in the following. 1. Use these following codes/files as the building blocks for the next steps. You have to implement these codes either in Java or in any other programming language. File: MidtermExam.zip can be downloaded from subakti.com > DAA(F) > Midterm exam: the source code. It uses NetBeans as IDE for Java programming, however, please feel free to use any IDE/programming language that suit you. MidtermExam.zip has 1 folder: MidtermExam. Inside folder MidtermExam, src folder will be found. Inside src folder, there are two folders/packages: pohon and uts. Inside folder/package: uts, there are 3 files: ListKu.java, ListKuFungsi.java and ListKuFungsiTest.java. Inside folder/package: pohon, there are 8 files: Pohon.java, PohonAksi.java, PohonAksiTest.java, PohonAVL.java, DAA1.java, DAA1Test.java, DAA2.java and DAA2Test.java. Your task is to update and continue for writing codes for the file DAA1.java and DAA2.java. You can test your code by running the file DAA1Test.java and DAA2Test.java. P a g e 1

File: Pohon.java P a g e 2

P a g e 3

P a g e 4

File: ListKu.java P a g e 5

P a g e 6

File: ListKuFungsi.java P a g e 7

P a g e 8

File: PohonAksi.java P a g e 9

P a g e 10

P a g e 11

2. Based on Pohon.java and PohonAksi.java above, please create a function, namely adalahbst() which has a recursive function inside this function. It checks whether a tree, i.e., Pohon p, is BST (Binary Search Tree). Hint: it is allowed to use a supported function for adalahbst(). Please update the function adalahbst() in file DAA1.java. [20 points] Function name: public static boolean adalahbst (Pohon p) Supported function name: private static Boolean adalahbst(pohon p, int batasbawah, int batasatas) P a g e 12

Supported function adalahbst() will be used to get a Boolean value whether p is BST or not where its value can be found between the range of batasbawah and batasatas. 3. Please create a recursive function, namely cetakmenurun() which receives an input of a BST p (where p is Pohon and its values are an integer), that be able to print the values of p in descending order. This function has to be created without making a separate list of values from p. Please update the function cetakmenurun() in file DAA1.java. [10 points] Function name: public static void cetakmenurun (Pohon p) 4. Please create an efficient recursive function, namely maks() which receives an input of a BST p (where p is Pohon and its values are an integer), that be able to get the maximum value of the p s values. It is not allowed to traverse and to compare all of the nodes in the tree. However, you should traverse at most one path in the tree from the root. It means this function works in O(log n) time for BST. Hint: assume we are a node x in BST, then all of the values from the tree s left branches of x always have the less than or equal ( ) values compared to the value of node x. So, the maximum value won t be existing in the tree s left branches. Where is the maximum value? Please update the function maks() in file DAA1.java. [10 points] Function name: public static int maks (Pohon p) 5. Please create a function, namely hapus() which receives the inputs of Pohon p and int n, whose has a recursive function to delete the value of n from the tree p, if n exists. If n does not exist, then return a new tree. Please update the function hapus() in file DAA1.java. [10 points] Function name: public static Pohon hapus (Pohon p, int n) Pseudo-code: public static Pohon hapus (Pohon p, int n) Jika p adalah kosong maka kembalikan: p Buat variabel, misal a <-- nilai dari p Buat variabel, misal Ki <-- kiri dari p Buat variabel, misal Ka <-- kanan dari p Jika n lebih besar dari a Buat variabel, misal baruka <-- hapus(ka, n) Kembalikan: buat Pohon baru dengan parameter: nilai dari p, Ki, baruka Jika n lebih kecil dari a Buat variabel, misal baruki <-- hapus(ki, n) Kembalikan: buat Pohon baru dengan parameter: nilai dari p, baruki, Ka Jika Ki adalah kosong Kembalikan: Ka jika Ka adalah kosong Kembalikan: Ki // Kedua cabang tidak kosong // Maka salah satu cabang akan kehilangan satu node // Misal di cabang kiri -> maks dari cabang kiri // Atau misal di cabang kanan -> min dari cabang kanan Buat variabel, misal, sebelum <-- maks(ki) Kembalikan: buat Pohon baru dengan parameter: sebelum, hapus(ki, sebelum), Ka P a g e 13

6. Use this following code/file as the building blocks for the next steps. You have to implement these codes either in Java or in any other programming language. File: PohonAVL.java P a g e 14

P a g e 15

P a g e 16

7. Please create a recursive function, namely adalahtinggiseimbang() which receives an input PohonAVL p, that be able to check whether p has a balanced height (AVL tree condition). However, first of all, please define a function, namely tinggi(), which returns the height of PohonAVL p, as below. Please update the function adalahtinggiseimbang() in file DAA2.java. [10 points] public static int tinggi (PohonAVL p) { return p.tinggi(); } Function name: public static Boolean adalahtinggiseimbang (PohonAVL p) Pseudo-code: public static boolean adalahtinggiseimbang (PohonAVL p) Jika p adalah kosong Kembalikan: benar Buat variabel, kirit <-- tinggi(kiri dari p) Buat variabel, kanant <-- tinggi(kanan dari p) Jika Math.abs(kiriT - kanant) kurang dari atau sama dengan 1 Kembalikan: adalahtinggiseimbang(kiri dari p) DAN adalahtinggiseimbang(kanan dari p) Kembalikan: salah 8. Please create a recursive function, namely sisipkantinggiseimbang() which receives the inputs of int n and PohonAVL p, that be able to insert n in p while it keeps preserving the AVL condition. Please update the function sisipkantinggiseimbang() in file DAA2.java. [20 points] Function name: public static PohonAVL sisipkantinggiseimbang (int n, PohonAVL p) Pseudo-code: public static PohonAVL sisipkantinggiseimbang (int n, PohonAVL p) Jika p adalah kosong Kembalikan: buat PohonAVL baru dengan parameter: n, PohonAVL baru kosong, PohonAVL baru kosong jika n kurang dari atau sama dengan nilai dari p Buat variabel, misal: hasil <-- seimbangkankembalikiri dengan parameter: Buat pohonavl baru dengan parameter: nilai dari p, sisipkantinggiseimbang(n, kiri dari p), kanan dari p) // assert adalahbst(hasil) && adalahtinggiseimbang(hasil); Kembalikan: hasil Buat variabel, misal: hasil <-- seimbangkankembalikanan dengan parameter: Buat pohonavl baru dengan parameter: nilai dari p, kiri dari p, sisipkantinggiseimbang(n, kanan dari p) // assert adalahbst(hasil) && adalahtinggiseimbang(hasil); Kembalikan: hasil private static PohonAVL seimbangkankembalikiri (PohonAVL p) Jika tinggi(kiri dari p) kurang dari atau sama dengan (tinggi(kanan dari p) + 1) Kembalikan: p Buat variabel, misal: Ki <-- kiri dari p Buat variabel, misal: Ka <-- kanan dari p Buat variabel, misal: KiKi <-- kiri dari Ki Buat variabel, misal: KiKa <-- kanan dari Ki Jika tinggi(kiki) lebih dari tinggi(ka) // Rotasi KiKi - rotasi tunggal Kembalikan: Buat pohonavl baru dengan parameter: nilai dari Ki, KiKi, buat pohonavl baru dg parameter: nilai p, KiKa, Ka // assert tinggi(kika > tinggi(ka) // Rotasi KiKa - ganda Kembalikan: Buat pohonavl baru dg parameter: nilai dari KiKa, // Kiri (Buat pohonavl baru dg parameter: nilai dari Ki, kiri dari Ki, kiri dari KiKa), // Kanan (Buat pohonavl baru dg parameter: nilai dari p, kanan dari KiKa, kanan dari p) P a g e 17

private static PohonAVL seimbangkankembalikanan (PohonAVL p) Jika tinggi(kanan dari p) kurang dari atau sama dengan (tinggi(kiri dari p) + 1) Kembalikan: p Buat variabel, misal: Ki <-- kiri dari p Buat variabel, misal: Ka <-- kanan dari p Buat variabel, misal: KaKi <-- kiri dari Ka Buat variabel, misal: KaKa <-- kanan dari Ka Jika tinggi(kaka) lebih dari tinggi(ki) // Rotasi KaKa - rotasi tunggal Kembalikan: Buat pohonavl baru dengan parameter: nilai dari Ka, (buat pohonavl baru dg parameter: nilai p, Ki, KaKi), KaKa // assert tinggi(kaki > tinggi(ki) // Rotasi KaKi - ganda Kembalikan: Buat pohonavl baru dg parameter: nilai dari KaKi, // Kiri (Buat pohonavl baru dg parameter: nilai dari p, kiri dari p, kiri dari KaKi), // Kanan (Buat pohonavl baru dg parameter: nilai dari Ka, kanan dari KaKi, kanan dari Ka) 9. Please create a recursive function, namely hapustinggiseimbang() which receives the inputs of PohonAVL p and int n, that be able to delete n from p while it keeps preserving the AVL condition. Please update the function hapustinggiseimbang() in file DAA2.java. [20 points] Nama fungsi: public static PohonAVL hapustinggiseimbang (PohonAVL p, int n) Pseudo-code: public static PohonAVL hapustinggiseimbang (PohonAVL p, int n) Jika p adalah kosong Kembalikan: p Buat variabel, misal: a <-- nilai dari p Buat variabel, misal: Ki <-- kiri dari p Buat variabel, misal: Ka <-- kanan dari p Jika n lebih dari a Buat variabel, misal: baruka <-- hapustinggiseimbang(ka, n); Kembalikan: seimbangkankembalikiri() dg parameter: buat pohonavl baru dg parameter: nilai dari p, Ki, baruka jika n kurang dari a Buat variabel, misal: baruki <-- hapustinggiseimbang(ki, n); Kembalikan: seimbangkankembalikanan() dg parameter: buat pohonavl baru dg parameter: nilai dari p, baruki, Ka Jika Ki adalah kosong Kembalikan: Ka jika Ka adalah kosong Kembalikan: Ki Buat variabel, misal: sebelum <-- maks(ki) Kembalikan: seimbangkankembalikanan() dg parameter: buat pohonavl baru dg parameter: sebelum, hapustinggiseimbang(ki, sebelum), Ka P a g e 18

10. To avoid plagiarism/cheating, every student needs to pledge and declare, then she/he must submit her/his signed pledge and declaration as in the following. Failed to do so will be resulted in getting 0 (zero) grade. Attach the scanned/photo of your declaration in your report. By the name of Allah (God) Almighty, herewith I pledge and truly declare that I have solved midterm exam by myself, didn t do any cheating by any means, didn t do any plagiarism, and didn t accept anybody s help by any means. I am going to accept all of the consequences by any means if it has proven that I have been done any cheating and/or plagiarism. [Place, e.g., Surabaya], [date, e.g., 16 March 2019] <Signed> [Full name, e.g., Mukidi Mukiyo] [NRP, e.g., 05111340000xxx] 11. Please create a full report, in PDF format, of the source codes (.java or any other programming language s source codes), the outputs of your programs and its analysis. Then put this PDF format report along with your declaration (see step #10 above) and all of.java files (or any other programming language s source code) into 1 (one).zip file. Please name this file: IF184401_DAA(F)_MID_NRP_Name.ZIP. 12. Have a great day! Good luck! P a g e 19