**** PLEASE READ THIS GRAY BOX CAREFULLY BEFORE STARTING THE ASSIGNMENT ****
Evaluation Policy:
β will be applied to the total score.
100% penalty
β will be applied for the submission and marked as zero.
β We do not accept any submission via email; they will be ignored.
keyboard-typed submissions for the written assignment
β We do not accept any .
β You can do your written assignment in two ways:
β Use tablet (i.e. Galaxy Tab, iPad, etc) and stylus pen, and save your work as .pdf.
β Write on any paper, scan it, and save as .pdf file
β We recommend using Microsoft Lens to scan your works.
your process of solving the problems
β Please describe as detailed as possible.
β If you write down your answer only, you will not earn a point.
β Please write neatly when showing your work.
β Hardly unrecognizable work might be marked as zero points.
β Your code will be automatically tested using an evaluation program.
β Each problem has the maximum score.
β Full points will be given only if all test cases are passed; there are no partial points if only some portion of the test cases work, and the others donβt.
β Points will be deducted for any typos or incorrect formatting
β Do not modify auxiliary files
β utils.h, utils.cpp, evaluate.cpp, and so on.
β Compile your code using βReplitβ and check your program before submission.
You should not use C++ standard template library
β other than given ones.
β DO NOT INCLUDE <queue>, <vector>, <stack>, or other container libraries β Any submission using such STL library will be disregarded.
β Using only the given libraries will suffice.
Files You Need to Submit:
[your_student_id]_assignment1.zip
β .zip file named (i.e. 20241234_assignment1.zip) containing:
β pa1.cpp (do not change your filename!)
β wa1.pdf (your written assignment)
If You Find Bugs in the Program:
as soon as possible
β Please notify us
Any other questions? Please use PLMS Q&A board in English.
Written Assignment #1
Q1. (1pt)
Order the following functions by ascending asymptotic growth rate using big-Oh notation. Assume the base of given log function as 2. (1pt)
3log + 5 210 2 4 + 8log 5 + 32
3 + 42 3 2log log3 !
Q2. (Total 1pt, 0.5pt each)
1) Compute the time complexity of countVowels using big-O notation, given that the length of the input string str is n.
int countVowels(string str) { int result = 0;
string vowels = βaeiouAEIOUβ;
for (int i = 0; i < str.length(); i++) { for (int j = 0; j < vowels.length(); j++) { if (str[i] == vowels[j]) { result++;
}
}
}
return result;
}
2) Compute the time complexity of triangularNumber using big-O notation.
int triangularNumber(int n) { int result = 0; int i = 1;
while (result < n) { result += i;
i++;
}
return result;
}
Q3. (Total 1pt, 0.5pt each)
You are given an array of n elements. All elements in an array are integers ranging from 0 to n-2. All elements are unique except for two; there are two elements with duplicate values. Your task is to identify the duplicate value in the array.
1) Compute the time complexity of findDuplicate using big-O notation.
int findDuplicate(int arr[], int n) { int result = -1;
for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (arr[i] == arr[j]) { result = arr[i]; break;
}
}
}
return result;
}
2) Compute the time complexity of findDuplicate2 using big-O notation.
int findDuplicate2(int arr[], int n) { int result = -1;
int* count = new int[n-1];
for (int i = 0; i < n; i++) { if (count[arr[i]] == 1) { result = arr[i]; break;
} else { count[arr[i]]++;
}
}
delete count;
return result;
}
Programming Assignment #1
Basic Instruction
Please refer to C++ Environment Setup Guide, which is on PLMS.
Use the command below to compile your code:
$ g++ -std=c++11 -o pa1 pa1.cpp utils.cpp
[Task 1] List (3pts)
Description
β Implement a function that can insert or delete an integer into the list.
β A user can:
β Insert an element in ascending order
β Delete an element from the list at the specific index
β If the specified index is out of range of the given list, print βERRORβ.
Input
β Sequence of commands, which is one of the following:
β (βinsertβ, integer value): insert integer value at the appropriate position in the list, ensuring that the elements within the array are always in ascending order.
β (βdeleteβ, index): delete an element at the index in the list.
β Index indicates zero-based index.
Output
β After all sequence of commands are processed, the resulting string of list elements should have spaces between each element, but no space after the last element.
β βERRORβ should be printed if the deleting index is out of range.
Input Output
[(βinsertβ,2), (βinsertβ,1), (βinsertβ,3)] 1 2 3
[(βinsertβ,0), (βinsertβ,0), (βinsertβ,1)] 0 0 1
[(βinsertβ,0), (βinsertβ,1), (βdeleteβ,0)] 1
[(βinsertβ,1), (βdeleteβ,1)] ERROR
[(βdeleteβ,0)] ERROR
[(βinsertβ,5), (βinsertβ,9), (βdeleteβ,0),
(βinsertβ,1), (βinsertβ,2)] 1 2 9
Example Usage
$ ./pa1 1 β[(βinsertβ,2), (βinsertβ,1), (βinsertβ,3)]β
The file named βsubmit.txtβ will be generated with the content below, or if already exists, the following output will be added at the end of the file:
[Task 1]
1 2 3
[Task 2] Postfix Expression Calculator / Stack (4pt)
Description
β Postfix expression is the expression of the form
β [operand1] [operand2] [operator]
β c.f. Infix expression is the expression of the form
β [operand1] [operator] [operand2]
β Implement an array-based stack and a function EvaluatePostfix.
β This function returns the string that contains the evaluated value of the given postfix expression, utilizing your implementation of stack.
Input
β A string of postfix expression. Input is given without space.
β The operators that need to be implemented is shown below:
β β+β: addition
β β-β: subtraction
β β*β: multiplication
β β/β: integer division
β The operands can be 1-digit integers between 0-9.
Output
β βERRORβ for the cases of:
β The operator does not have enough number of available operands.
β More than one value left after evaluation
β βDIVISIONBYZEROβ for division by zero case
β Otherwise, the resulting Integer value of the expression
β Use to_string(int value) to convert int to string
β You need not to handle the case of exceeding maximum stack capacity
More Specifications
β You should handle numbers next to each other in the input as separate values β 42 should be handled as 4 and 2, not the value 42.
β During the operations, youβll also need to handle the values other than 1-digit numbers. β You do not need to handle the case of exceeding maximum stack capacity.
Input Output
2 2
234+* 14
56*34*+ 42
68-* ERROR
71 ERROR
733-/ DIVISIONBYZERO
Example Usage
$ ./pa1 2 β56*34*+β
The file named βsubmit.txtβ will be generated with the content below, or if already exists, the following output will be added at the end of the file:
[Task 2]
42
[Task 3] Round Robin / Circular Queue (5pt)
Description
β Round-robin (RR) is one of the CPU scheduling algorithms, where each process is allocated with equal share of CPU time. Processes are put into a circular queue, and when the allocated time expires, the process goes to the very back of the queue, allowing the next process to be processed by the CPU.
β For further knowledge, see the link below:
https://en.wikipedia.org/wiki/Round-robin_scheduling β Implement RR algorithm utilizing circular queue.
β For the simplicity of the given task, you only need to handle the case where all processes arrive at the queue at the same arrival time.
Input
β Sequence of instructions, each containing process name and its burst time (total time required to complete the process)
β (βprocess_nameβ,t): enqueue the process named process_name with burst time t to the circular queue. Burst time t is assumed to be > 1.
Output
β Sequence of names of the processes handled at each time point (t = 0, 1, 2, 3, β¦) until the end of the execution. The names should be separated with a blank β β.
β See examples for better understanding. More Specifications
β You should assume that the time quantum = 1, which is the allocated time for a process to run in a preemptive manner.
β The process should go back to the queue even if thereβs still remaining execution time to be finished.
β If the process finishes, then it is dequeued from the circular queue.
β Hint: Implement rotate() without using enqueue and dequeue, which is to be used in moving unfinished process to the back
Input Output
[(βP0β,5), (βP1β,3)] P0 P1 P0 P1 P0 P1 P0 P0
[(βP0β,3)] P0 P0 P0
[(βP0β,2), (βP1β,1), (βP2β,3)] P0 P1 P2 P0 P2 P2
Example Usage
$ ./pa1 3 β[(βP0β,2), (βP1β,1), (βP2β,3)]β
The file named βsubmit.txtβ will be generated with the content below, or if already exists, the following output will be added at the end of the file:
[Task 3]
P0 P1 P2 P0 P2 P2

![[SOLVED] Csed233 β assignment #1](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip.jpg)

![[SOLVED] Lab 8 Numeric Conversion](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip-1200x1200.jpg)
Reviews
There are no reviews yet.