单个算法的数据结构

beplay体育怎么安装数据结构和算法
参考号:EM13763

Compares the number of comparisons used by various data structures for a single algorithm. The algorithm is the one that is used to determine representation in the U.S. House of Representatives, and is described below.

这data structures are based on LinkedLists, ArrayLists, TreeSets, and PriorityQueues, as described below.

具体而言,分配的测试类A1假定了一个抽象类分配程序的子类ArrayListapportion,LinkedListapportioner,treeseTapportioner和PriorityqueEeAporpter的存在。根据以下规范定义这些子类中的最后三个。

  • the Apportioner class
  • the ArrayListApportioner subclass,
  • 下面描述的CountingComparator类,
  • the A1 test class, and
  • 测试数据的各种文件

分配程序类和分配算法

分摊问题将国家及其人口的集合以及立法机关的总数。您要使用的算法(美国房屋使用)将这些座位分配给一个州之一

1.首先分配每个状态一个座位

2. then repeatedly assigning a seat to the state with the highest priority for it, until the seats are exhausted

每个州的优先级都被计算为其人口的商,也是根据当前分配的座位数量计算的除数。对于美国房屋使用的算法,您要使用的算法,此除数是R(r+1)的平方根。请注意,此值大约为R + 0.5。还要注意,每当一个州获得新的代表时,其除数会增加,因此优先级会减少。

这分配程序class has a simple concrete apportion method whose code corresponds to the simple high-level algorithm given above. The class also provides a concrete method for computing the divisor in the priority function, and a concrete method for reading the name and population of a single state. Otherwise the apportion method is based on specific abstract methods that subclasses need to define concretely. One of these methods returns the apportionment as a list of elements of class Map.Entry.

这分配程序class also has two abstract methods for dealing with the number of comparisons of various types made during an apportionment. Its subclasses are to call these methods, as described below.

分配示例

在一个大小,中和小的房屋大小为7和三个状态的示例中,各自种群的45、32和18,算法将通过与下表的行相对应的步骤迭代。

Apportionment

Priority

Large

中等的

小的

Large

中等的

小的

1

1

1

32.8

21.6

12.7

2

1

1

18.4

21.6

12.7

2

2

1

18.4

13.1

12.7

3

2

1

13.0

13.1

12.7

3

3

1

-

-

-

分配程序子类

Each of your subclasses is to implement each of the abstract methods of the Apportioner class, based on a specified data type.

In addition, each subclass is to count the number of comparisons that it uses to peform apportionments, including those that it uses to initialize data structures.在这里,比较包括平等的比较 - 请勿使用equalsmethod for these comparisons, or rely on a library method that does so.Each subclass is to count separately those comparisons used to update priorities, and those used for other purposes.

Specifically, the compare method for each of your CountingComparator subclasses is to increment the appropriate one of the two comparison counters. This method should return a negative number if the first argument has alargerpriority than the second argument; this is particularly important for the priority queue data type. The resetComparisonCounters method of your Apportioner subclass is to set both of the class's counters to 0; the getComparisonCounters method is to return an array of size 2 that contains the two comparison counters, with the counter used for priorities appearing last.

分配程序子类的初始化方法是假设单独的数据结构用于存储每个州的人群,当前的座位数量和当前优先级。即使在每种情况下都不会实现Java的MAP接口,也将这些数据汇总称为“地图”很方便。该方法不需要初始化每个子类中的所有地图 - 您可能会发现最好在定义,构造函数或ReadInput方法中初始化一些地图。如果您的子类具有不是地图或比较计数器的实例变量,则您可能还需要在Initializemaps中初始化它们。

Note that, depending on the data type of the priority map and its entries, updating priorities in the assignRepAndUpdatePriority method may be possible by simply mutating an entry, or may need to be done by removing an entry and inserting an updated version of it into the map.

Getapportion方法是返回按状态排序的列表。如果需要明确的排序,则将通过计算比较的排序算法执行此类。这可能是通过collections.sort来完成的,也可以使用已使用CountingComparator参数构建的Treemet或Treemap来完成。

Each subclass may assume that the MiniScanner methods that appear in the superclass definition all work correctly.

对于每个子类,readInput方法a filename argument should check that the file of the given name is not empty. The readInput method that takes a list argument should check that the list is not empty. In each case, the method should throw an IOException with an informative message component. Neither method needs to handle any exceptions, or check for any other errors. In particular, you needn't check for repeated state names. The rest of the subclass's methods may assume that there is at least one state and that the population map is not empty.

TROEDETAPPORTERTER类

In the TreeSetApportioner class, you are to represent the priority data as a TreeSet of Strings, constructed with a Comparator argument that compares strings by priority (where items of larger priority value precede items of smaller priority value). The population data and the apportionment data are to be represented as HashMaps from String to Long and Integer respectively. Note that here HashMaps are preferable to TreeMaps since the order of the state names is unimportant during apportionment.

这PriorityQueueApportioner class

在PriorityQueueApporter类中,您应将优先数据表示为表示状态名称的字符串的优先级。人口数据和分配数据应像hashmaps一样表示,如thetreesetapportial案例中。您将需要一个类似于TreeseTapportioner类的比较类别类。

参考号:EM13763

以前的问答

Calculate the expected value of returns of stock

Calculate the expected value of returns of stock.

人力资源管理系统的开发

Development of Human Resource Management System for the Health Service.

Show the accessibility and usability of website

该网页必须有几个有关阿塞拜疆国家 /地区的菜单,例如“关于阿塞拜疆”“历史”“地理”“景观”和“可访问性”菜单。

在赞美价格时

使用两个图显示政府干预前后的消费者盈余。

写有关库存管理系统的论文

Write paper on Inventory Management System.

写有关财务分析和业务分析的论文

写有关财务分析和业务分析的论文

Euclids算法的递归实施

编写欧几里得算法的递归实现,以找到两个整数的最大共同除数(GCD)

统计项目

Identify sample, population, sampling frame (if applicable), and response rate (if applicable). Describe sampling technique (if applicable) or experimental design

Design a dynamic database

Design a dynamic database using Mangodb, html , and php.

Java中的插座编程:TCP

In this project we will develop a Web server in two steps. In the end, you will have built a multi-threaded Web server that is capable of processing multiple simultaneous service requests in parallel.

Reviews

Write a Review

类似的问答

Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

如何通过Unicore访问虚拟化应用程序

如何通过Unicore访问虚拟化应用程序

Currency conversion development

货币转换开发

Determine the mean salary as well as the number of salaries

Determine the mean salary as well as the number of salaries.

在Java设计GUI并实施TIC TAC TOE游戏

Design a GUI and implement Tic Tac Toe game in java

实现一个开放的哈希表

In this programming assignment you will implement an open hash table and compare the performance of four hash functions using various prime table sizes.

递归树算法

Write a recursive function to determine if a binary tree is a binary search tree.

使用搜索树查找解决方案

Explain how will use a search tree to find the solution.

Euclids算法的递归实施

编写欧几里得算法的递归实现,以找到两个整数的最大共同除数(GCD)

免费任务报价

确保++等级

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

beplay安卓下载

Baidu