CS240 Spring 2024 5

Java Python CS240 Spring 2024

Assignment 5

Due Date: Tuesday, July 23 at 5:00pm

Please read the following link for guidelines on submission:

https://student.cs.uwaterloo.ca/~cs240/w24/assignments.phtml#guidelines

Each question  must be  submitted  individually to  MarkUs  as a  PDF with the corresponding file names:  a5q1. pdf, a5q2. pdf, .... It is a good idea to submit questions as you go so you aren’t trying to create several PDF files at the last minute.

Late Policy: Assignments are due at 5:00pm, with the grace period until 11:59pm.

Problem 1 Quadtrees [3+4=7 marks]

For all parts of this question, use the convention that each internal node of a quadtree has exactly four children, corresponding to regions NE, NW, SW and SE, in that order.

a) One application of quadtrees is image compression.  An image (picture) is recursively divided into quadrants until the entire quadrant is only one colour.  Using this rule, draw the quadtree of the following image. There are only three colours  (shades of grey).  For the leaves of the quad tree, use 1 to denote the lightest shade, 2 for the middle shade and 3 for the darkest shade of grey.

b) Another application is to compare two images.  Given two black and white images (i.e. each pixel of the image is either 0 or 1) each of size 2k  × 2k  stored as quadtrees, give an algorithm that returns the quadtree for the Intersection operation: if corresponding pixels in both images is 1, then their intersection is 1; otherwise 0.

Runtime analysis is not required but your algorithm should be as efficient as possible; i.e. marks may be deducted for terribly inefficient implementations.

Problem 2    [3+5=8 marks]

a) Draw the kd-tree representing the set of 2D points

S = {p1,..., p8 } = {(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8)}.

b) Give an algorithm using pseudocode for finding a point with the smallest x-coordinate in a kd-tree storing 2D points.  Your algorithm should be as efficient as possible. State and explain the worst case running time of your algorithm.

Problem 3 Range Trees [2+1+2+2=7 marks]

a) Draw a 2-dimensional range tree of minimal height for the following set of points: {(7, 88), (12, 19), (22, 33), (27, 29), (28, 9), (31, 99), (42, 66)}

b) Suppose a two dimensional range tree data structure stores n points, and that the BST ordered by x-coordinates is perfect, i.e., every level is completely filled. Give an exact closed form formula in terms of n for the sum of the number& CS240 Spring 2024 Assignment 5 nbsp;of nodes in the x-ordered BST plus the total number of nodes in all y-ordered BSTs.

c) Assume that we have a set of n numbers (not necessarily integers) and we are interested only in counting the number of points that lie in a range rather than in reporting all of them. Describe how to modify a 1-dimensional range tree (i.e., a balanced BST) so that such a range counting query can be performed in O(log n) time (independent of s). Briefly justify that your algorithm is within the expected runtime.

d) Next, consider the 2-dimensional case where we have a set of n 2-dimensional points. Given a query rectangle R, suppose we only want to find the number of points inside R, rather than the points themselves.  Explain how to modify the Range Tree data structure and the search algorithm such that counting queries can be performed in O((log n)2 )) time. Briefly justify that your algorithm meets the runtime requirement.

Problem 4 KMP [2+3=5 marks]

a) Compute the failure array for the pattern P =bababc.

b) Show how to search for pattern P =bababc in the text T =bacbbabbabababcbacbb using the KMP algorithm.  Indicate in a table such as Table 1 which characters of P were compared with the characters of T.  Follow the example on slide 16 in module 9. Place each character of P in the column of the compared-to character of T.  Place parentheses around the character if an actual comparison was not performed.  You may not need all space in the table.

Table 1: Table for KMP problem.

Problem 5 Boyer-Moore [2+3+3=8 marks]

a) Construct  the  last  occurrence  function  L  for  pattern  P   =  badodadb  where Σ   = a,b,c,d,o,t.

b) Trace the search for  P  in  T  =  adtbadtbadtadtbadodadbadt  using  the  Boyer-Moore algorithm.  Indicate in a table such as Table 2 which characters of P were compared with which characters of T.  Follow the example on slide 25.  Place each character of P in the column of the compared-to character of T.  Put brackets around the character if they are known to match from the previous step (similar to the example in the slides). Use a new row when sliding the pattern.  You may not need all rows in the table.  Add more rows to the table if you need more.

c) For any m ≥ 1 and any n ≥ m, give a pattern P and a text T such that the Boyer- Moore algorithm “looks at” (compares a character of the text with a character of the pattern) exactly Θ(n/m) characters. Justify your answer.

Problem 6 Suffix Trees and Arrays [3+2=5 marks]

a) Draw the suffix tree corresponding to the text T = abracadabra.

b) Construct suffix array for S = balbes.

Table 2: Table for Boyer-Moore problem         

为了获取2024年春季特定项目的源码,通常这类资源会由课程讲师或项目负责人托管在版本控制系统如Git上,并可能通过学习管理系统(LMS)或其他官方渠道发布给学生或参与者[^1]。 如果目标是访问CS 231, Spring 2024 ASSIGNMENT 3 Python编程部分的源代码,则建议遵循以下途径: - **联系授课教师或助教**:发送邮件询问如何获得作业相关的材料和支持文件。 - **查看学校的学习管理平台**:许多大学使用Canvas、Blackboard等在线服务来分发教学资料和接收学生的提交成果。 - **加入官方讨论论坛或Slack频道**:参与同学间的交流可以更快地找到所需的信息和技术支持。 对于公开可用的Spring框架相关项目,比如构建于Spring 3之上的一些例子,虽然具体的2024年项目细节未知,但可以从已有的开源实例中学到很多有用的知识。例如,在博客文章《Building spring 3》中提到过创建基于Maven的新应用程序的过程[^2]。 至于具体实现方面,假设要建立一个新的Spring Boot应用并集成JaCoCo来进行代码覆盖率分析,下面给出了一段简单的`pom.xml`配置片段用于启动这样的环境: ```xml <build> <plugins> <!-- Other plugins --> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.7</version> <executions> <execution> <goals> <goal>prepare-agent</goal> </goals> </execution> <!-- report generation --> <execution> <id>report</id> <phase>prepare-package</phase> <goals> <goal>report</goal> </goals> </execution> </executions> </plugin> </plugins> </build> ``` 这段XML定义了如何利用Maven插件来准备JaCoCo代理以及生成报告,这对于监控新开发的应用程序中的测试覆盖情况非常有帮助[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值