Sorted Maps with AVL Trees and Splay Trees (Price 200)

Sorted Maps with AVL Trees and Splay Trees

WX: help-assignment
code price: 200

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<K,V> 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.

WX: help-assignment

  • 7
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值