1. Homepage
  2. Programming
  3. CSC3100 Data Structures Fall 2024 Programming - Assignment 2: Queue and Time Complexity

CSC3100 Data Structures Fall 2024 Programming - Assignment 2: Queue and Time Complexity

Engage in a Conversation
CUHKCSC3100Data StructuresQueueTime ComplexityJavaC++

A. Requirements Code (90%) CourseNana.COM

You can write your code in Java, Python, C, or C++. The time limit may vary among different languages, depending on the performance of the language. Your code must be a complete excutable program instead of only a function. We guarantee test data strictly compliance with the requirements in the description, and you do not need to deal with cases where the input data is invalid. CourseNana.COM

No AI Assistance or Plagiarism: All code must be your own. The use of AI tools (e.g., ChatGPT, GitHub Copilot) or copying from external sources or peers is strictly forbidden. CourseNana.COM

Violations of the plagiarism rules will result in 0 points or even failure of this course. Libraries in this assignment: CourseNana.COM

  • For C/C++, you can only include standard library. CourseNana.COM

  • For Java, you can only import java.util.* CourseNana.COM

  • For Python, you can only import standard library. In other words, you cannot import libraries such as numpy. CourseNana.COM

    We provide an example problem to illustrate the information above better. CourseNana.COM

    Report (10%) CourseNana.COM

    You also need to write a report in pdf type to explain the following: What are the possible solutions for the problem?
    How do you solve this problem?
    Why is your solution better than others? CourseNana.COM

    Please note that the maximum number of pages allowed for your report is 5 pages. CourseNana.COM

    Remember that the report is to illustrate your thinking process. Keep in mind that your report is supposed to show your ideas and thinking process. We expect clear and precise textual descriptions in your report, and we do not recommend that you over-format your report. CourseNana.COM

    B. Example Problem: A + B Problem Description CourseNana.COM

    Given 2 integers A and B, compute and print A + B CourseNana.COM

    Input CourseNana.COM

    Two integers in one line: A, and B CourseNana.COM

    Output CourseNana.COM

    One integer: A + B CourseNana.COM

    Sample Input 1 Sample Output 1 CourseNana.COM

    123 CourseNana.COM

Problem Scale & Subtasks CourseNana.COM

For 100% of the test cases, 0 A,B 106 CourseNana.COM

Solutions CourseNana.COM

Java CourseNana.COM

import java.util.*; CourseNana.COM

public class Example {
public static void main(String[] args) { CourseNana.COM

int a, b;
Scanner scanner =
new Scanner(System.in); a = scanner.nextInt();
b = scanner.nextInt();
scanner.close();
System.out.println(a + b);
CourseNana.COM

} } CourseNana.COM

Python CourseNana.COM

AB = input (). split ()
A, B =
int(AB[0]), int(AB[1]) print(A + B) CourseNana.COM

C CourseNana.COM

#include <stdio.h> CourseNana.COM

int main(int argc, char *argv[]) { CourseNana.COM

int A, B; scanf("%d%d", &A, &B); printf("%d\n", A + B); return 0; CourseNana.COM

} CourseNana.COM

C++ CourseNana.COM

#include <iostream > CourseNana.COM

int main(int argc, char *argv[]) { CourseNana.COM

int A, B;
std::cin>> A >> B;
std::cout<< A + B << std::endl;
return 0; CourseNana.COM

} CourseNana.COM

C. Submission CourseNana.COM

After finishing this assignment, you are required to submit your code to the Online Judge System (OJ), and upload your .zip package of your code files and report to BlackBoard. CourseNana.COM

C.1 Online Judge CourseNana.COM

Once you have completed one problem, you can submit your code on the page on the Online Judge platform (oj.cuhk.edu.cn, campus only) to gain marks for the code part. You can submit your solution of one problem for no more than 80 times. CourseNana.COM

After you have submitted your program, OJ will test your program on all test cases and give you a grade. The grade of your latest submission will be regarded as the final grade of the corresponding problem. Each problem is tested on multiple test cases of different difficulty. You will get a part of the score even if your algorithm is not the best. CourseNana.COM

Note: The program running time may vary on different machines. Please refer to the result of the online judge system. OJ will show the time and memory limits for different languages on the corresponding problem page. CourseNana.COM

If you have other questions about the online judge system, please refer to OJ wiki (campus network only). If this cannot help you, feel free to contact us. CourseNana.COM

C.2 BlackBoard CourseNana.COM

You are required to upload your source codes and report to the BlackBoard platform. You need to name your files according to the following rules and compress them into A2_<Student ID>.zip : CourseNana.COM

A2_<Student ID>.zip
|-- A2_P1_<Student ID>.java/py/c/cpp |-- A2_P2_<Student ID>.java/py/c/cpp |-- A2_Report_<Student ID>.pdf
CourseNana.COM

For Java users, you don’t need to consider the consistency of class name and file name. For example, suppose your ID is 123456789, and your problem 1 is written in Python, problem 2 is CourseNana.COM

written in Java then the following contents should be included in your submitted A2_123456789.zip: CourseNana.COM

A2_123456789.zip
|-- A2_P1_123456789.py
|-- A2_P2_123456789.java |-- A2_Report_123456789.pdf
CourseNana.COM

C.3 Late Submissions CourseNana.COM

Submissions after Oct. 24 2024 23:59:00(UTC+8) would be considered as LATE.
The LATE submission page will open after deadline on OJ.
Submisson time = max
{latest submisson time for every problem, BlackBoard submisson time} There will be penalties for late submission: CourseNana.COM

0–24 hours after deadline: final score = your score×0.8 24–72 hours after deadline: final score = your score×0.5 72+ hours after deadline: final score = your score×0 CourseNana.COM

FAQs CourseNana.COM

Q: My program passes samples on my computer, but not get AC on OJ. A: Refer to OJ Wiki Q&A CourseNana.COM

Authors CourseNana.COM

If you have questions for the problems below, please contact: Problem 1. Chunxu Lin: 221012033@link.cuhk.edu.cn Problem 2. Zirong Zeng: zirongzeng@link.cuhk.edu.cn CourseNana.COM

CSC3100 Data Structures Fall 2024 Programming Assignment 2 CourseNana.COM

Zirong Zeng: zirongzeng@link.cuhk.edu.cn Chunxu Lin: 221012033@link.cuhk.edu.cn CourseNana.COM

Due: Oct. 24 2024 23:59:00 CourseNana.COM

Assignment Link: https://oj.cuhk.edu.cn/d/csc3100_2024_fall/homework/6706a6d32579925ba8060510 1 Queue (40% of this assignment) CourseNana.COM

1.1 Description CourseNana.COM

Given an n-length list, the value ai in the list satisfies that ai ∈ {1, ..., n} and i = 1, ..., n. Then, numbering each element ai in the list as bi, bi = i. CourseNana.COM

Please find the minimum number of elements that should be deleted so that the list of remaining elements has the same elements as the list of their corresponding numbers. CourseNana.COM

For example, given a list A = {2,1,2,2,4}, and its number list N = {1,2,3,4,5}. We need to delete the 3-rd and 5-th elements from lists A and N because numbers 3 and 5 are not in the list A. Then, the list A = {2,1,2} and its number N = {1,2,4}. However, since 4 is not in the list A, we need to delete the 3-rd element from lists A and N . Finally, we get the list A = {2, 1} and its number list N = {1, 2}, where the list A = {2, 1} has the same elements as its number list N = {1, 2}. Conclusively, we delete 3 elements from the list A. CourseNana.COM

1.2 Input CourseNana.COM

The first line contains a positive integer n. The second line contains the n-length list. CourseNana.COM

1.3 Output CourseNana.COM

The minimum number of deleted elements. Sample Input 1 CourseNana.COM

Sample Output 1 CourseNana.COM

53 21224 CourseNana.COM

Sample Input 2 Sample Output 2 CourseNana.COM

50 13425 CourseNana.COM

For a list A = {1,3,4,2,5}, its number list is N = {1,2,3,4,5}. We do not need to delete any element from lists A and N since the list A has the same elements as its number list N. CourseNana.COM

Sample Input 3 CourseNana.COM

See attached sample.in CourseNana.COM

Problem Scale & Subtasks CourseNana.COM

For 100% of the test cases, 1 n 2 105. CourseNana.COM

Sample Output 3 CourseNana.COM

See attached sample.out CourseNana.COM

Test Case No. 1-6 CourseNana.COM

7-8 9-10 CourseNana.COM

Hint CourseNana.COM

Constraints n 10
n 100
n 2 105 CourseNana.COM

Hint1: You can use a queue to store elements that are not in a given list but are in its list of numbers. 2 Time Complexity (50% of this assignment) CourseNana.COM

2.1 Description CourseNana.COM

John is learning a new programming language called A++. Having just mastered loops, he is excitedly writing many programs that contain only loop structures. However, he does not know how to compute the time complexity of his programs. So he turns to you for help. What you need to do is to write a program to calculate the time complexity for each program that John writes. CourseNana.COM

The loop structure in A++ is as follows: CourseNana.COM

Fixy
... // code block to be executed
CourseNana.COM

E CourseNana.COM

Here ”F i x y” indicates creating a variable i initialized as x, then compare i with y, and enter the loop if and only if i is smaller or equal to y. Each time the execution of the code block inside the loop ends, i will be changed to i + 1. Then i will be compared with y to determine whether to enter the loop again. The loop ends when i becomes larger than y. CourseNana.COM

Both x and y can be positive integers or the variable n. n represents the size of the data and must be retained during time complexity calculations. It cannot be treated as a constant. The value of n is much greater than 100. x is guaranteed to be smaller or equal to y. CourseNana.COM

”E” indicates the end of the loop. When the loop ends, any variables created within that loop are also destroyed. CourseNana.COM

Note: For the sake of convenience in writing, the uppercase letter O is used to represent the standard notion of Θ when describing time complexity in this problem. CourseNana.COM

2.2 Input CourseNana.COM

The first line contains a positive integer t, indicating that John writes t (1 t 10) programs in total (the programs contain only loop structures). Note that the loop structures are allowed to be nested. The following lines describe the t programs in order. CourseNana.COM

For each program, the first line contains a positive integer L (1 L 20000), indicating the number of lines in this program. The next L lines describe the program in detail: each line is either in the form of ”F i x y” or ”E”, where i is a lowercase letter (it is guaranteed that i will not be letter ”n”), x and CourseNana.COM

CourseNana.COM

y are either variable n or positive integers smaller than 100, and x is guaranteed to be smaller or equal to y. Since John has mastered loops quite well, there will be no syntax errors in his programs. i.e. F and E are guaranteed to match each other and he will not use variables that haven’t been destroyed in a loop. CourseNana.COM

2.3 Output CourseNana.COM

Output t lines, each indicating the time complexity of a program, in the order of the input. In this problem, time complexity is either in the form of O(1) or O(nˆw), where w is a positive integer smaller than 20000. O(1) means constant time complexity and O(nˆw) means that the time complexity is O(nw ) CourseNana.COM

Sample Input 1 CourseNana.COM

6
2 Fi11 E
2 Fx1n E
4 Fx5n F y 10 n E
E
4 Fx9n E Fy2n E
4 Fx9n Fynn E
E
4
F y 1 99 Fxnn E
E
CourseNana.COM

Problem Scale & Subtasks CourseNana.COM

Sample Output 1 CourseNana.COM

O(1) O(n^1) O(n^2) O(n^1) O(n^1) O(1) CourseNana.COM

Test Case No. 1-3
4-6
7-10
CourseNana.COM

Constraints Properties L 10 A
L 500
L 20000 CourseNana.COM

A: For each program, the first L/2 lines are in the form of ”F i x y”, and the lines from L/2+1 to L are in the form of ”E”. CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
CUHK代写,CSC3100代写,Data Structures代写,Queue代写,Time Complexity代写,Java代写,C++代写,CUHK代编,CSC3100代编,Data Structures代编,Queue代编,Time Complexity代编,Java代编,C++代编,CUHK代考,CSC3100代考,Data Structures代考,Queue代考,Time Complexity代考,Java代考,C++代考,CUHKhelp,CSC3100help,Data Structureshelp,Queuehelp,Time Complexityhelp,Javahelp,C++help,CUHK作业代写,CSC3100作业代写,Data Structures作业代写,Queue作业代写,Time Complexity作业代写,Java作业代写,C++作业代写,CUHK编程代写,CSC3100编程代写,Data Structures编程代写,Queue编程代写,Time Complexity编程代写,Java编程代写,C++编程代写,CUHKprogramming help,CSC3100programming help,Data Structuresprogramming help,Queueprogramming help,Time Complexityprogramming help,Javaprogramming help,C++programming help,CUHKassignment help,CSC3100assignment help,Data Structuresassignment help,Queueassignment help,Time Complexityassignment help,Javaassignment help,C++assignment help,CUHKsolution,CSC3100solution,Data Structuressolution,Queuesolution,Time Complexitysolution,Javasolution,C++solution,