COMP2003J代写、代做Python/Java编程语言
Assignment 1: AVL & Splay Trees
COMP2003J: Data Structures and Algorithms 2
Weight: 10% of final grade
Document Version: 1.0
Introduction
This assignment is intended to give you experience implementing AVL and
Splay trees. It is also a good exercise to gain experience about how generics,
inheritance and object references work in Java.
Source code that you can start from has been posted to BrightSpace in the file
Assignment1-Source.zip. This also contains the Javadoc API documentation for
the classes that have been provided (in the “doc” folder). Import this project into
Eclipse in the usual way.
Tasks
The main tasks for this assignment are:
• Implement the key methods for an AVL Tree.
• Implement the key methods for a Splay Tree.
• Develop a strategy to test if your implementations are correct.
Implementation of AVL Tree Methods
The source code contains a partial implementation of an AVL Tree in a file
called AVLTree.java in the dsa.impl package. Your work in this section must be
in this class and it must use the interfaces that are provided.
You must implement the following methods:
• public void insert( T value ) – insert a value into the AVL tree.
• public void remove( T value ) – remove a value from the AVL tree.
• public boolean contains(T value) – check to see if a value is contained in
the AVL tree. Returns true if the value is in the tree, or false if not.
• private void restructure( IPosition x ) – trinode restructuring (the three
nodes are x, its parent and its grandparent).
If you wish, you may create other methods that help you to complete the task
(e.g. rightRotate(IPosition n), leftRotate(IPosition n), etc.).
Some hints and tips:
- Remember your AVLTree extends several other classes, so you can
use some of their helpful methods (e.g. expandExternal(…)).
- The expandExternal(…) method uses newPosition(…) to create all
position objects, so all the positions in the tree will be AVLPosition
instances.
- You can cast an IPosition to an AVLPosition in the same way as you
did in previous worksheets.
- Remember every parent/child relationship works in two directions.
Every time you change one of these references, you must change both.
- In the lectures we talk about attaching subtrees. BUT when we program
this, we notice that the subtree structure does not change at all. We just
need to put the root of the subtree in the right place.
- An AVLPosition object has a height attribute. You will need to efficiently
calculate the height of the positions in the tree when the tree changes.
Calculating the heights of all positions every time the tree changes will
be at best O(n). An efficient implementation would be at worst O(h) when
an insert(…) or remove(…) operation is called.
- The TreePrinter class has been provided, so you can print the contents
of your tree and see what it contains.
Implementation of Splay Tree Methods
The source code contains a partial implementation of a Splay Tree in a file
called SplayTree.java in the dsa.impl package. Your work in this section must be
in this class and it must use the interfaces that are provided.
You must implement the following methods:
• private void splay( IPosition p ) – splay a position in the tree.
• public void insert( T value ) – insert a value into the splay tree.
• public void remove( T value ) – remove a value from the splay tree.
• public boolean contains( T value ) – check to see if a value is contained
in the splay tree. Returns true if the value is in the tree, or false if not.
Remember, this method also causes a splay(…) operation.
Testing the Tree Implementations
It is important to check whether your implementations are correct. A good way
to do this is to use your tree to perform some operations, and then check if the
outcome is correct. This is best done using a program, rather than doing it
manually every time.
An example is given in the AVLTreeStructureTest class in the dsa.example
package. This performs some operations (only insert) on an AVL tree. To check
if the final AVL tree is correct, it compares it with a Binary Search Tree that has
the final expected shape (I worked this out manually).
Another example is shown in the AVLTreeSpeedTest class. This performs several
operations on an AVL Tree and measures how quickly it runs. This is a good
way to test the efficiency of your implementation.
Create some test classes for your implementation (called Test1, Test2, etc.).
You can follow these examples or have your own ideas.
In your tests, you should test all the different types of restructuring that are
possible (e.g. for a Splay Tree they should cause zig, zig-zig and zig-zag splays
to both sides, and at the root and deeper in the tree).
Each test class must have a comment to explain the purpose of the test and
what the outcome was.
Submission
• This is an individual programming assignment. Therefore, all code
must be written by yourself. There is some advice below about avoiding
plagiarism in programming assignments.
• All code should be well-formatted and well-commented to describe what
it is trying to do.
• If you write code outside the SplayTree.java, AVLTree.java and test files
(Test1.java, Test2.java, etc.), it will not be noticed when grading. Write
code only in these files.
• Submit a single .zip file to Brightspace.
o This should Include only the files you have written code in. It is
not necessary to submit your entire Eclipse project.
Assignment 1 Grading Rubric
This document shows the grading guidelines for Assignment 1 (implementation of AVL
Trees and Splay Trees). Below are the main criteria that will be applied for the major grades
(A, B, C, etc.). Other aspects will also be taken into account to decide minor grades (i.e.
the difference between B+, B, B-, etc.).
- Readability and organisation of code (including use of appropriate functions,
variable names, helpful comments, etc.).
- Quality of solution (including code efficiency, minor bugs, etc.).
Passing Grades
D Grade
Good implementation of an AVL Tree or Splay Tree, plus some basic testing.
A "good" implementation is one where all the key methods work correctly in the vast
majority of cases (i.e. some occasional bugs will be tolerated).
C Grade
Good implementation of an AVL Tree and a Splay Tree, plus some basic testing of both;
OR
Good implementation of an AVL Tree or a Splay Tree, plus comprehensive testing of the
tree in question.
"Comprehensive" testing should make sure that the different operations of the tree(s) are
all tested (e.g. for a Splay Tree "Zig" operation, it would check both situations where the
node is a left child and where the node is a right child. For a "Zig-Zig" operation, this
should also be tested for both sides, as well as being tested where the splay operation
happens at the root and where it happens deeper in the tree).
B Grade
Excellent implementation of an AVL Tree and a Splay Tree, plus comprehensive testing
of both; OR
Excellent implementation of an AVL Tree and a Splay Tree, with some basic testing and
an efficient approach to height calculation for AVL trees.
A Grade
Excellent implementations of AVL Tree and Splay Tree, with comprehensive testing of
both and an efficient approach to height calculation in AVL Trees.
Failing Grades
ABS/NM Grade
No submission received/no relevant work attempted.
G Grade
Code does not compile; OR
Little or no evidence of meaningful work attempted.
F Grade
Some evidence of work attempted, but few (if any) methods operate in the correct
manner.
E Grade
AVL Tree and/or Splay Tree have been attempted, but there are too many
implementation errors for the implementation to be useful in practice.
Plagiarism in Programming Assignments
• This is an individual assignment, not a group assignment.
• This means that you must submit your own work only.
If you submit somebody else's work and pretend that you wrote it, this
is plagiarism.
• Plagiarism is a very serious academic offence.
Why should you not plagiarise?
• You don't learn anything!
• It is unfair to other students who work hard to write their own solutions.
• It's cheating! There are very serious punishments for students who
plagiarise. The UCD policy on plagiarism can be found online1.
- A student found to have plagiarised can be exclude from their
programme and not allowed to graduate.
Asking for Help
If you find things difficult, help is available.
• TAs are available during lab times.
• You can post questions in the Brightspace discussion forum or our
Wechat group.
• You can email the head TA (dairui.liu@ucdconnect.ie).
• You can get help from your classmates.
**Getting help to understand something is not the same as copying a
solution! **
The best way to get useful answers is to ask good questions.
Don't just send a photo of your computer screen and ask "Why does this not
work?".
Do:
• Send your Java file(s) as an attachment. We can't run code that's in a
photograph to test it out!
• Say what error message you got when you tried to run the code (if
any).
• Say what the code did that you did not expect.
• Say what the code did not do that you did expect.
1 https://www.ucd.ie/t4cms/UCD%20Plagiarism%20Policy%20and%20Procedures.pdf
How to avoid plagiarism: Helping without copying.
If you are trying to help a classmate with a programming assignment, there
are two golden rules:
Never, ever give your code to somebody else.
• You don't know what they will do with it or who they will give it to.
• If somebody else submits code that is the same as yours, you will be
in trouble too.
Don't touch their keyboard (this advice is more relevant when we are in labs together)
• Don't type solutions for them! It will end up looking a lot like your code.
Also, they don't learn anything.
Here are some other ways you can help a friend with an assignment, without
risking plagiarism:
• If their code doesn't work, it's OK to explain what is wrong with it.
• If they don't understand a concept, draw a diagram to explain.
• Tell them about useful methods that I have provided that can help
achieve their goals.
• Describe an algorithm that will help.
• Describe it in words or diagrams, not in code!
• E.g. "You could try saving the node's right child as a variable.
Then you could use a loop to keep getting that node's left child
until you reach the bottom of the tree".

热门主题

课程名

omp9727 ddes9903 mgt253 fc021 int2067/int5051 bsb151 babs2202 mis2002s phya21 18-213 cege0012 math39512 math38032 mech5125 mdia1002 cisc102 07 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 efim20036 mn-3503 comp9414 math21112 fins5568 comp4337 bcpm000028 info6030 inft6800 bcpm0054 comp(2041|9044) 110.807 bma0092 cs365 math20212 ce335 math2010 ec3450 comm1170 cenv6141 ftec5580 ecmt1010 csci-ua.0480-003 econ12-200 ectb60h3f cs247—assignment ib3960 tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 econ7230 msinm014/msing014/msing014b math2014 math350-real eec180 stat141b econ2101 fit2004 comp643 bu1002 cm2030 mn7182sr ectb60h3s ib2d30 ohss7000 fit3175 econ20120/econ30320 acct7104 compsci 369 math226 127.241 info1110 37007 math137a mgt4701 comm1180 fc300 ectb60h3 llp120 bio99 econ7030 csse2310/csse7231 comm1190 125.330 110.309 csc3100 bu1007 comp 636 qbus3600 compx222 stat437 kit317 hw1 ag942 fit3139 115.213 ipa61006 econ214 envm7512 6010acc fit4005 fins5542 slsp5360m 119729 cs148 hld-4267-r comp4002/gam cava1001 or4023 cosc2758/cosc2938 cse140 fu010055 csci410 finc3017 comp9417 fsc60504 24309 bsys702 mgec61 cive9831m pubh5010 5bus1037 info90004 p6769 bsan3209 plana4310 caes1000 econ0060 ap/adms4540 ast101h5f plan6392 625.609.81 csmai21 fnce6012 misy262 ifb106tc csci910 502it comp603/ense600 4035 csca08 8iar101 bsd131 msci242l csci 4261 elec51020 blaw1002 ec3044 acct40115 csi2108–cryptographic 158225 7014mhr econ60822 ecn302 philo225-24a acst2001 fit9132 comp1117b ad654 comp3221 st332 cs170 econ0033 engr228-digital law-10027u fit5057 ve311 sle210 n1608 msim3101 badp2003 mth002 6012acc 072243a 3809ict amath 483 ifn556 cven4051 2024 comp9024 158.739-2024 comp 3023 ecs122a com63004 bms5021 comp1028
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图