1. Homepage
  2. Homework
  3. COMP2123 Data Structures and Algorithms - Assignment 1 s1 2023
This question has been solved

COMP2123 Data Structures and Algorithms - Assignment 1 s1 2023

Engage in a Conversation
AustraliaThe University of SydneyCOMP2123Data Structures and Algorithms

Assignment 1

Problem 1. (20 points)

Consider the following algorithm that given an array A of length n produces ank −1 other array B of length n − k where B[i ] = ∑ij+A [ j ] =i CourseNana.COM

function algorithm(A, k)
    n ← length of A
    B ← new array of size n − k
    for i ∈ [0 : n − k] do
        B [i ] ← 0
        for j ∈ [0 : k ] do
            B [i ] ← B [i ] + A [i + j ]

    return B

▷ i ranges from 0 to n − k − 1
▷ j ranges from 0 to k − 1

Assuming that k < n/2 (but not necessarily a constant) use O-notation to upperbound the running time of the following algorithm in terms of both n and k. CourseNana.COM

Problem 2. (40 points)

We want to build a queue for integer elements that in addition to the operations we saw during the lecture, also supports a seeSaw() operation that on a given queue holding the elements Q0 , Q1 , . . . , Qn−1 returns CourseNana.COM

All operations should run in O(1) time. Your data structure should take O(n) space, where n is the number of elements currently stored in the data structure. CourseNana.COM

Your task is to: a) Design a data structure that supports the required operations in the required time and space. b) Briefly argue the correctness of your data structure and operations. c) Analyse the running time of your operations and space of your data structure. CourseNana.COM

Problem 3. (40 points)

We want to build a stack for elements having a colour attribute (e.g., blue, red, orange, etc). We say that a bunch of consecutive positions in the array for a monochromatic stretch if all the elements stored in those positions have the same colour. In addition to the usual stack operations, we want to support a maxMono() operation that on a given stack returns the maximum length of any monochromatic stretch currently stored in the stack. CourseNana.COM

All operations should run in O(1) time. Your data structure should take O(n) space, where n is the number of elements currently stored in the data structure. a) Design a data structure that supports the required operations in the required time and space. b) Briefly argue the correctness of your data structure and operations. c) Analyse the running time of your operations and space of your data structure. CourseNana.COM

Written 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 algorithm as you would to a friend over the phone, such that you completely and unambiguously describe your algorithm, including all the important (i.e., nontrivial) 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 end you can also include pseudocode, but this is optional. • In particular, when designing an algorithm or data structure, it might help you (and us) if you briefly describe your general idea, and after that you might 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 multiple answers, then we will give you marks only for "your worst answer", as this indicates 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 it. You do not need to write more than necessary (see comment above). • When giving answers to questions, always prove/explain/motivate your answers. • When giving an algorithm as an answer, the algorithm does not have to be given as (pseudo-)code. • If you do give (pseudo-)code, then you still have to explain your code and your ideas in plain English. • Unless otherwise stated, we always ask about worst-case analysis, worst case running times, etc. • As done in the lecture, and as it is typical for an algorithms course, we are interested in the most efficient algorithms and data structures. • If you use further resources (books, scientific papers, the internet,...) to formulate your answers, then add references to your sources and explain it in your own words. Only citing a source doesn’t show your understanding and will thus get you very few (if any) marks. Copying from any source without reference is considered plagiarism. CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
Australia代写,The University of Sydney代写,COMP2123代写,Data Structures and Algorithms代写,Australia代编,The University of Sydney代编,COMP2123代编,Data Structures and Algorithms代编,Australia代考,The University of Sydney代考,COMP2123代考,Data Structures and Algorithms代考,Australiahelp,The University of Sydneyhelp,COMP2123help,Data Structures and Algorithmshelp,Australia作业代写,The University of Sydney作业代写,COMP2123作业代写,Data Structures and Algorithms作业代写,Australia编程代写,The University of Sydney编程代写,COMP2123编程代写,Data Structures and Algorithms编程代写,Australiaprogramming help,The University of Sydneyprogramming help,COMP2123programming help,Data Structures and Algorithmsprogramming help,Australiaassignment help,The University of Sydneyassignment help,COMP2123assignment help,Data Structures and Algorithmsassignment help,Australiasolution,The University of Sydneysolution,COMP2123solution,Data Structures and Algorithmssolution,