墨尔本大学COMP90038课业解析

惰性珊瑚
• 阅读 1275

题意:

在一个2D游戏背景下设计和分析算法以提高对算法和递归关系复杂度的理解

解析:

游戏背景:

墨尔本大学COMP90038课业解析

墨尔本大学COMP90038课业解析

涉及知识点
分治与递归,算法时间复杂度分析,邻接矩阵

更多可加微信讨论

微信号:alexa_au

pdf全文
The University of Melbourne
School of Computing and Information Systems
COMP90038 Algorithms and Complexity
Assignment 1, Semester 2 2019
Released: Friday August 23 2019. Deadline: Sunday September 8 2019 23:59
This assignment is marked out of 30 and is worth 15% of your grade for COMP90038.
Objectives
To improve your understanding of the time complexity of algorithms and recurrence relations. To develop problem-solving and design skills. To improve written communication skills; in particular the ability to present algorithms clearly, precisely and unambiguously.
Problems
Let’s play a game. Or, more precisely, design and analyse some algorithms that might be used in a simple two-dimensional (2D) game.

墨尔本大学COMP90038课业解析

Consider a game played on an two-dimensional grid, whose Cartesian coordinates range from (−M, M). . .(M, M). Figure 1 depicts a game board for which M = 4.
The game contains a fixed number N of enemy players, who are AI-controlled. Each player (including the human player and each enemy AI) is located at some arbitrary but fixed position (x, y) on the board,i.e. for which −M ≤ x ≤ M and −M ≤ y ≤ M.
The human player can perform certain attacks, which damage all enemy players within a certain range of the human player. To avoid the need to calculate with expensive multiplication and square root operations, we will approximate the range by a square situated about the human player.

墨尔本大学COMP90038课业解析

[2 marks] Consider the following recurrence relations. Which one best describes the worst-base complexity of the MarkAffectedDC function, whose input size is n = hi −lo + 1 and whose basic operations are calling IsAffected and Mark? Justify your answer in no more than a paragraph of text.
T(1) = 1
T(n) = 2T(n/2)
T(1) = 2
T(n) = 2T(n/2) + 2
T(1) = 0
T(n) = 2T(n/2)
T(1) = 2
T(n) = 2T(n/2)

4.[2 marks] Use telescoping (aka back substitution) to derive a closed form for your chosen recurrence relation and thereby prove that the worst case complexity of the MarkAffectedDC algorithm is in Θ(n).

墨尔本大学COMP90038课业解析

  1. [2 marks] How many elements will need to be marked in the worst case and what, therefore, would be the worst-case complexity of an algorithm that, given an array A sorted according to your comparison function, implemented the behaviour of MarkAffected above? Express your answer in Big-Theta notation.
  2. [2 marks] The worst case is quite pessimistic. On average, we might expect that enemy AIs are uniformly distributed throughout the game board.Let d be the expected number of enemy AIs contained in or on the borders of a box of bound b(i.e. whose width and height are each 2b) on the board. For simplicity, we limit our attention to boxes that are contained entirely within the game baord.Consider an algorithm that, given an array A sorted according to your comparison function,implemented the behaviour of MarkAffected above by first using your Θ(log(N)) function to determine the elements that need to be marked (of which we expect there to be d), and then marking those d elements. We might characterise its expected complexity as:

log(N) + d
Derive a formula for d in terms of b, M and N.

9.[2 marks] As a point of comparison, what is the expected complexity of the divide-and-conquer
algorithm above in this average case, expressed in Big-Theta notation? Justify your answer in no
more than a paragraph of text.

10.[2 marks] Now compare the best case complexity of the divide-and-conquer algorithm and the one
that uses a pre-sorted array A described above. Express the best-case complexity of each in BigTheta notation as a function of N. Justify both in no more than a paragraph of text.

11.[4 marks] Suppose now that the enemy AIs can send each other messages. However, two AIs,
whose positions are (x1, y1) and (x2, y2) respectively, can directly communicate only if the line
(x1, y1) — (x2, y2) that connects them does not pass through the rectangle (including its borders)
surrounding the human player whose bottom left corner is (px−b, py −b) and whose top-right corner
is (px + b, py + b), where (px, py) is the human player’s position.
Implement a function that determines whether two enemy AIs can directly communicate. Include
a brief description (no more than a single paragraph) of how your function works, i.e. the rationale
behind its design.
function CanDirectlyCommunicate((x1, y1),(x2, y2),(px, py), b)
. . .

12.[6 marks] Imagine that your CanDirectlyCommunicate function has been used to construct a
graph whose nodes are the enemy AIs, such that there exists an edge between node n1 and n2 if and
only if those two AIs can directly communicate. This graph is stored as an adjacency matrix M.Here the nodes ni are simply the indices of enemy AIs in the array A, so each of them is simply an integer in the range 0 ≤ ni ≤ N −1. Therefore the adjacency matrix M is simply a two-dimensional array, M0 . . . MN − 1.
Implement an O(N2) algorithm that, given two enemy AIs n1 and n2 determines whether there exists a path by which they might communicate via other enemy AIs. If a path exists, your algorithm should return the shortest path by which communication is possible. Otherwise, your algorithm should return the empty path. Your algorithm also takes as its input the adjacency matrix representation of the graph described above.
You should represent a path as a linked list of enemy AI indices ni. The empty path is therefore the empty linked list without any nodes.

Submission and Evaluation
• You must submit a PDF document via the LMS. Note: handwritten, scanned images, and/or Microsoft Word submissions are not acceptable — if you use Word, create a PDF version for submission.
• Marks are primarily allocated for correctness, but elegance of algorithms and how clearly you communicate your thinking will also be taken into account. Where indicated, the complexity of algorithms also matters.
• We expect your work to be neat – parts of your submission that are difficult to read or decipher will be deemed incorrect. Make sure that you have enough time towards the end of the assignment to present your solutions carefully. Time you put in early will usually turn out to be more productive than a last-minute effort.
• You are reminded that your submission for this assignment is to be your own individual work. For many students, discussions with friends will form a natural part of the undertaking of the assignment work. However, it is still an individual task. You should not share your answers (even draft solutions) with other students. Do not post solutions (or even partial solutions) on social
media or the discussion board. It is University policy that cheating by students in any form is not permitted, and that work submitted for assessment purposes must be the independent work of the student concerned.
Please see https://academicintegrity.uni...

If you have any questions, you are welcome to post them on the LMS discussion board so long as you do not reveal details about your own solutions. You can also email the Head Tutor, Lianglu Pan (lianglu.pan@unimelb.edu.au) or the Lecturer, Toby Murray (toby.murray@unimelb.edu.au). In your message, make sure you include COMP90038 in the subject line. In the body of your message, include a precise description of the problem.

Late Submission and Extension
Late submission will be possible, but a late submission penalty will apply: a flagfall of 2 marks, and then 1 mark per 12 hours late.
Extensions will only be awarded in extreme/emergency cases, assuming appropriate documentation is provided simply submitting a medical certificate on the due date will not result in an extension.

点赞
收藏
评论区
推荐文章
Oracle 分组与拼接字符串同时使用
SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(
Wesley13 Wesley13
4年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Wesley13 Wesley13
4年前
Unity小王子私藏的开发2D游戏的常用插件合集
Unity以开发3D游戏见长,早期版本的Unity在开发2D游戏时不慎方便,因此AssetStore出现了很多2D游戏开发引擎。现在Unity对2D游戏的支持越来越好,而这些开发2D游戏的Unity插件也得到了更多开发者的喜爱。1:RexEngine:Classic2DPlatformerEngine(https://www.os
Wesley13 Wesley13
4年前
Unity2D游戏开发之保卫萝卜
!(https://img2018.cnblogs.com/blog/54608/201912/5460820191203062607084286309123.png)  保卫萝卜是2D塔防游戏里边的一个经典案例,这次去开发这个游戏,我们会尽力去实现和原版一样的功能,做好我们可以处理好的每一个游戏细节(比如塔攻击的集火目标优先攻击,与自动搜索
Stella981 Stella981
4年前
Master公式计算递归时间复杂度
我们在算递归算法的时间复杂度时,Master定理为我们提供了很强大的便利!Master公式在我们的面试编程算法中除了BFPRT算法的复杂度计算不了之外,其他都可以准确计算!这里用求数组最大值的递归函数来举例:publicstaticintgetMax(intarr,intL,intR){if
深度学习 深度学习
8个月前
力扣701题:二叉搜索树插入操作 - 递归解法详解
一、内容简介本文详细解析了力扣701题"二叉搜索树中的插入操作"的递归实现方法。通过遵循二叉搜索树的性质,展示了如何高效地在BST中插入新节点。文章包含完整注释代码、算法思路讲解和复杂度分析,帮助读者掌握BST操作的核心技巧。二、算法思路‌递归终止条件‌:
为什么mysql不推荐使用雪花ID作为主键
作者:毛辰飞背景在mysql中设计表的时候,mysql官方推荐不要使用uuid或者不连续不重复的雪花id(long形且唯一),而是推荐连续自增的主键id,官方的推荐是auto_increment,那么为什么不建议采用uuid,使用uuid究
贾蔷 贾蔷
9个月前
力扣1137题 解题思路和步骤 C++代码实现,力扣一共多少题
一、题目分析力扣1137题要求我们找到第N个泰波那契数。泰波那契数的定义是:T00,T11,T21,且在n0的条件下Tn3TnTn1Tn2。,当n4时,T4T3T2T14。这道题主要考查我们对递归或动态规划的理解和运用。在思考解题方法时,我们
惰性珊瑚
惰性珊瑚
Lv1
想像每场日落那样让人惊喜和灿烂。
文章
8
粉丝
0
获赞
0