COMP2014J代做、Java程序设计代写
Assignment 1:
Sorted Maps with AVL Trees and
Splay Trees
COMP2014J: Data Structures and Algorithms 2
Weight: 20% of final grade
Due Date: 23:59 Friday May 9th 2025
Document Version: 1.1
Introduction
This assignment is intended to give you experience of using an AVL tree and a
Splay Tree to implement a different type of data structure (a type of sorted Map
known as a Tree Map). It is also a good exercise to gain experience about how
generics, inheritance and object references work in Java.
Source code that you must start from has been posted to Brightspace in the file
Assignment1-Source.zip. This also contains the Javadoc for the classes and
interfaces provided (in the “doc” folder). Import this project into IntelliJ in the
usual way.
You must use the interfaces and data structure implementations that are
provided. Do not use any interfaces or implementations from the built-in Java
Collections Framework. If you are in doubt, ask!
Tasks
The main tasks for this assignment are:
• Create an efficient implementation of a sorted map, using an AVL Tree
to store the entries, according to the provided interfaces and base
classes.
• Create an efficient implementation of a sorted map, using a Splay Tree
to store the entries, according to the provided interfaces and base
classes.
• Develop a strategy to test if your implementations are correct.
Tree Map Implementation of ISortedMap Methods
The source code contains a skeleton implementation of a map based on an
AVL Tree (in a file called AVLTreeMap.java) and a Splay Tree (in a file called
SplayTreeMap.java) in the dsa.impl package. All of your work in this section
must be in this class and it must use the interfaces that are provided.
These classes both extend a sorted map that uses a Binary Search Tree
implementation. Your task is to replace the following methods with appropriate
implementations that include the relevant AVL and Splay Tree operations
(checking for balance, tri-node restructuring, splaying).
As you have learned in Data Structures and Algorithms 1, a Map is an ADT
contains key/value pairs (called “entries”). Keys are used to uniquely identify
values. By default, entries in a map have no particular order. The
ISortedMap interface is provided (where K is the generic type of the keys
and V is the generic type of the values) and contains the following methods:
• public V put( K key, V value ) – add a new key/value pair to the
map. If this key was already contained in the map, the old value
associated with it is returned and the new value is stored in the map
instead. Otherwise it returns null.
• public V get( K key ) – get the value associated with the given key,
or null if that key is not contained in the map.
• public V remove( K key ) – remove the entry with the given key
from the map. Returns the value associated with that key if it was
contained in the map, or null otherwise.
If you wish, you may create other methods that help you to complete the task
(e.g. restructure(…), rightRotate(…), leftRotate(…), splay(…), etc.).
Some hints and tips
• Remember your AVLTreeMap and SplayTreeMap extends several other
classes, so you can use some of their helpful methods (e.g.
expandExternal(…), remove(…)).
• The expandExternal(…) method uses newPosition(…) to create all
position objects, so for an AVL Tree all the positions in the tree will be
AVLPosition instances (so that the height is stored). In the
SplayTreeMap, all the positions in the tree will be BTPosition instances.
• You can cast an IPosition to an AVLPosition or BTPosition 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.
A Map that is implemented using any type of binary search tree (often called a
“Tree Map”) can be said to be a kind of sorted map, where all entries can be
accessed according to the natural ordering of their keys.
For example, consider the following key/value entries stored in a map:
{"zh", "Chinese"}, {"ga", "Irish"}, {"de", "German"}, {"en", "English"}
When iterating the keys, the order would be (i.e. in alphabetical order):
- "de", "en", "ga", "zh"
When iterating the values, the order would be (i.e. in order of their keys):
- "German", "English", "Irish", "Chinese"
When iterating the entries, the order would be the same, i.e.:
- {"de", "German"}, {"en", "English"}, {"ga", "Irish"}, {"zh", "Chinese"}
This is because the trees store use the keys to decide where to store the
entries, so an inorder traversal of the tree yields the entries in key order.
Testing the Implementations
You must also write some code to check whether your implementations are
correct. A good way to do this is to use your implementation 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 Map. 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 Map and measures how quickly it runs. This is a
good way to test the efficiency of your implementation.
Mandatory Tests:
- Adjust the AVLTreeStructureTest so that all of the key operations will
be called when it is run (i.e. there are different types of trinode
restructurings, and it will be done differently at the root compared to
deeper in the tree).
- Create a similar SplayTreeStructureTest that does the same for the
SplayTreeMap implementation.
Other Tests:
Create some test classes for your implementations (called Test1, Test2, etc.).
In your tests, you should test all whether the behaviour of the methods that
you have implemented work correctly in different circumstances (e.g. inserting
a new entry with a new key, replacing the value for an existing key, etc.).
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 AVLTreeMap.java, SplayTreeMap.java
and test files (AVLTreeStructureTest.java,
SplayTreeStructureTest.java, 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. Do
not submit your entire IntelliJ project.
Grading
The following grading scheme will be used to grade the assignment:
Item Weight
Correct and efficient implementation of
AVL Tree Map operations
30%
Correct and efficient implementation of
Splay Tree Map operations
30%
Testing of AVL Tree Map 15%
Testing of Splay Tree Map 15%
Code clarity, organisation, commenting 10%
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 (including AI-generated code) 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.
• Your lecturer is available in the lab.
• You can post questions in the Brightspace discussion forum.
• You can email the lecturer (david.lillis@ucd.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?" (N.B. images are not a good way to send code).
Do:
• Send/post 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
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".
Problems?

热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图