comp2123 Range Function Computation

news/2025/4/1 6:04:18/文章来源:https://www.cnblogs.com/tingkyou/p/18799144

comp2123Assignment 1 s1 2025This assignment is due on March 25 and should be submitted on Gradescope.All submitted work must be done individually without consulting someone else’s

solutions in accordance with the University’s “Academic Dishonesty and Plagiarism” policies.

Before you read any further, go to the last page of this document and readthe Written Assignment Guidelines section.

Problem 1. (10 pointsGiven an array A consisting of n integers, we want to compute a matrix B wherefor any 0 i < j < n we have

B[i][j] = f([A[i], A[i + 1], ..., A[j 1]])Consider the following algorithm for computing B:

Algorithm 1 Range Function Computation

  • ❡✈❡♥✲❞✐❢❢([1, 3, 50, 48]) returns 4,
  • ❡✈❡♥✲❞✐❢❢([1, 3, 50, 48, 30]) returns 4,
  • ❡✈❡♥✲❞✐❢❢([3, 50, 48, 30]) returns 65.We are to design an implementation of the methods ❡♥q✉❡✉❡, ❞❡q✉❡✉❡, and❡✈❡♥✲❞✐❢❢ so that all operations run in O(1) time. You can assume that thedatastructure always starts from the empty queue.

Your data structure should take O(n) space, where n is the number of elements currently stored in the data structure.Your task is to:

Design a data structure that supports the required operations in the required time and space.

  1. a)
  2. b) Briefly argue the correctness of your data structure and operations.
  3. c) Analyse the running time of your operations and space of your data structure.2comp2123Assignment 1 s1 2025

Problem 3. (25 pointsA skyline is defined by an array of n distinct integers A = [h0, h1, h2, h3, h4, ...., hn1

]representing the heights of buildings in a one-代写comp2123 Range Function Computationdimensional city, given in the order they appear from left to right. Suppose you are standing on the rooftop ofone of these buildings. You want to determine the closest taller building to your

left and the closest taller building to your right. The goal is to find an efficientalgorithm to compute this for ALL n buildings.

pecifically, for every building x [0, n 1], compute the two closest indices i

and j to x such that:

i < x, j > x, A[i] > A[x] and A[j] > A[x]Your algorithm should return two arrays of length n:L[0...n 1] where L[x] denotes the index (i) of the nearest taller building tothe left of building x (or ◆♦♥❡ if no such building exists).R[0...n 1] where R[x] denotes the index (j) of the nearest taller building tothe right of building x (or ◆♦♥❡ if no such building exists).

Note:

a)

  1. b) Prove your algorithm is correct.
  2. c) Analyse the running time of your algorithm.3comp2123Assignment 1 s1 2025Written Assignment Guidelines
  • Assignments should be typed and submitted as pdf (no pdf containing text

as images, no handwriting).

  • Start by typing your student ID at the top of the first page of your submission. Do not type your name.
  • Submit only your answers to the questions. Do not copy the questions.
  • When asked to give a plain English description, describe your algorithas you would to a friend over the phone, such that you completely andunambiguously describe your algorithm, including all the important (i.e.non-trivial) details. It often helps to give a very short (1-2 sentence) description of the overall idea, then to describe each step in detail. At the endyou can also include pseudocode, but this is optional.
  • In particular, when designing an algorithm or data structure, it might helpyou (and us) if you briefly describe your general idea, and after that youmight want to develop and elaborate on details. If we don’t see/understand your general idea, we cannot give you marks for it.
  • Be careful with giving multiple or alternative answers. If you give multipleanswers, then we will give you marks only for "your worst answer", as thisindicates how well you understood the question.
  • Some of the questions are very easy (with the help of the slides or book)You can use the material presented in the lecture or book without proving
  1. You do not need to write more than necessary (see comment above).
  • When giving answers to questions, always prove/explain/motivate youranswers.
  • When giving an algorithm as an answer, the algorithm does not have to begiven as (pseudo-)code.
  • If you do give (pseudo-)code, then you still have to explain your code andyour ideas in plain English.
  • Unless otherwise stated, we always ask about worst-case analysis, worstcase running times, etc.
  • As done in the lecture, and as it is typical for an algorithms course, weare interested in the most efficient algorithms and data structures, thoughslower solutions may receive partial marks.
  • If you use further resources (books, scientific papers, the internet,...) toformulate your answers, then add references to your sources and explain itin your own words. Only citing a source doesn’t show your understanding

nd will thus get you very few (if any) marks. Copying from any sourcewithout reference is considered plagiarism4

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/907786.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[P] 结对项目:影蛇舞

项目 内容这个作业属于哪个课程 2025年春季软件工程(罗杰、任健) 这个作业的要求在哪里 [P] 结对项目:影蛇舞 我在这个课程的目标是 学习软件工程知识,通过团队协作开发一个具备实际应用价值的软件,从需求分析、设计、开发到测试和部署,完整经历软件开发生命周期,提高工…

0329-Never Give Up

前言 用LCD1602 去打印一段话吧。 就当作激励和安慰,毕竟,我今天被坏情绪传染了一下,有点点失落和悲伤。 参考 5-2 LCD1602调试器 效果 Never Give UpAttitude Is Everything代码 LCD1602.h #ifndef __LCD1602_H__ #define __LCD1602_H__//用户调用函数: void LCD_Init(); …

JavaScript 数据结构与算法 — 单向链表

链表(Linked List)是一种基本的数据结构,用于表示一组按顺序排列的元素。链表中的每个元素都与下一个元素连接,元素在内存中并不是连续的,而是通过指针来链接在一起。每个元素都包含两部分:自己的数据和指向下一个元素的指针。我们常说的链表指的是单向链表,第一个元素的…

Ethernaut通关(智能合约漏洞)(有缘更新)

SnowSword笑传之出错币Ethernaut通关 参考文章:文章 - Ethernaut闯关录(上) - 先知社区、 智能合约是什么?把智能合约想象成网络上的赛博自动售货机,每个人都可以写自己的智能合约,使用虚拟货币交易物品,并且网络区块链中的所有节点都在为你的交易记账不怕商家提桶跑路……

QML基本组件 滑动条 Slider

描述 Slider通过手柄沿轨迹滑动来设置数值。 Qt帮助文档搜索 “slider” 获取详细信息。属性 from : real to : real value : real orientation : enumeration stepsize : real touchDragThreshold : qreal信号 onValueChange {}import QtQuick import QtQuick.ControlsWindow …

UE5--006--小结(一)

1. Input2. AI Enmy3.Save Game

阶段升级,zhitan-ems开源能源管理系统--集成建筑能耗支路和分项功能

升级介绍 自从春节上班后开源以来,zhitan-ems收到了大家很多的赞誉和认可,很多朋友也提出了中肯的意见。感谢大家。 很多朋友的建议里提到建筑能耗功能,依据大家意见,我们加班加点实现了简单的建筑能耗功能。如下图: 另外打一波广告,欢迎大家star 项目介绍 通过物联网技…

Static Timing Analysis Basics

Preface This note only introduce the essential concepts about Static Timing Analysis, which not contains:Async, i.e. remove, recover Timing conceptions, i.e. false path, multi cycle path etc. Advance timing domain knowledgePOCV, MCMM etc.什么是 STA 由于时钟…

深圳大学的一些简单题

A打表,发现是这样的东西:然后规律很显然,相邻的两个数,一组在左边,另一组在右边,依次循环,偶数的时候是 \(23\) 开头,奇数的时候是 \(12\) 开头,再处理一下 \(1\) 和 \(n\) 就可以,比较简单的分讨 显然规律不止一个点击查看代码 #include <bits/stdc++.h> usin…

AI可解释性 I | 对抗样本(Adversarial Sample)论文导读(持续更新)

本文作为AI可解释性系列的第一部分,旨在以汉语整理并阅读对抗攻击(Adversarial Attack)相关的论文,并持续更新。与此同时,AI可解释性系列的第二部分:归因方法(Attribution)也即将上线,敬请期待。AI可解释性 I | 对抗样本(Adversarial Sample)论文导读(持续更新) 导…

day:33 jmeter性能测试——压力测试

一.单接口性能测试(同一用户进行压力测试) POST http://49.233.201.254:8080/cms/manage/loginJump.do POST data: userAccount=admin&loginPwd=123456(1)在线程中修改虚拟用户数线程组 线程数:虚拟用户数。一个虚拟用户占用一个进程或线程。设置多少虚拟用户数在这里…

c#winform,倒鸭子字幕,仿AE软件的typemonkey插件,类似抖音的瀑布流字幕

不废话 直接上效果图C# winform 开发 类似抖音的瀑布流字幕。也是类似AE软件的typemonkey插件或者咱再网上常说的倒鸭子字幕 主要功能 1,软件可以自定义添加字幕内容2,软件可以添加字幕显示的时间区间3,可以自定义字幕颜色,可以随机颜色4,支持字幕的上下调节5,支持字幕的…