Professional Documents
Culture Documents
Report 2
Report 2
Report 2
Report
Laboratory Work No.2
Verificat:
Burlacu Natalia, PhD, associate professor
Department of Software and Automation Engineering,
Facultatea FCIM, UTM
Chisinau – 2023
The structure of the report for the laboratory work in the "Data
Structures and Algorithms" course will contain:
Note:
⎯ The report pages should be numbered in the footer, center area;
⎯ The text from items 1 & 2; 4 & 5 have to be written in Times New Roman, font
size 14 pt;
⎯ The space between the lines will be set at 1,5 lines.
⎯ Item 3 of this list (the developed program code should be written in relation to
Courier New, font size 10 pt; the space between code lines being 1.15 lines).
⎯ The report should be uploaded for checking by the lab teacher in the right
Report section (numbered in the same mode as your task) according to the
deadline terms specified by your teacher.
1. Task
2. Scopul lucrarii
I solved the following problems in C++ using the Shell Sort and the Quick Sort, in
order to have a better understanding of how this functions work and how they
should be properly used in the writing of the problem. I did different operations on
the arrays, like modifying the array with a[i+1] for the first exercises, after that
displayed the original array and the modified one, then sorted the array using she
shell sort and quick sort also did the same thing in the descending order amd all of
the comments i have provided in the code for a better understanding of how i have
written it.
int tmp;
while (i <= j) {
i++;
j--;
if (i <= j) {
tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
i++;
j--;
};
if (left < j)
if (i < right)
quickSort(arr, i, right);
int j;
arr[j] = temp;
int main() {
int size;
int arr[size];
cout << "Enter the elements of the array: ";
int original[size];
int modified[size];
int sum = 0;
sum += arr[i];
original[i] = arr[i];
modified[i] = sum;
quickSort(original, 0, size-1);
quickSort(original, 0, size-1);
shellSort(original, size);
shellSort(original, size);
return 0;
}
4. Execuția codului pe consola
5. Flow Chart
6. Concluzie
Quicksort and shellsort are both very efficient sorting algorithms, with time
complexities of O(n log n) and O(n log^2 n), respectively, which make them
suitable for sorting large datasets. Modified sort is a variation of insertion sort,
which typically has a time complexity of O(n^2), but the modification used in this
code improves its efficiency significantly, making it faster than the traditional
insertion sort.
Overall, this code provides a good illustration of how different sorting algorithms
can be implemented in C++, and how to sort arrays in ascending and descending
order.