Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
Course design of data structure and
algorithm analysis – Final Report
2021-2022-1
Name: SIAM ABDUR RAHMAN
Student ID: 19416443
School: Aliyun School of BigData Class: CS 193 (English)
Instructor/Lecture: Yi Liu Score:
December 6, 2020 ~ December 24, 2021
1
Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
Curriculum design assignment
Of Changzhou University
Design topic and content
There are six design topics. You can choose one of them.
(1)Binary balanced sort tree
[problem description]
Starting from an empty tree, in the process of creating, we should ensure the order of the tree and
make some adjustments to the balance of the tree. Finally, the binary sort tree should be
transformed into a binary balanced sort tree.
[basic requirements]
1) create (insert, adjust);2) Output.
(2)Design and implementation of hash table
[problem description]
The hash table is designed to realize the telephone number searching system.
[basic requirements]
1) Suppose that each record has the following data items: telephone number, user name, and
address;
2) Input each record from the keyboard, and set up a hash table with telephone number and user
name as keywords respectively;
3) Adopt certain methods to solve the conflict;
4) Search and display the record of a given telephone number;
5) Find and display records for a given user name.
(3)The making of address book
[problem description]
Using the bidirectional linked list in a data structure as the data structure, combined with the basic
knowledge of C language. Write an address book management system. In order to apply the data
structure knowledge to the actual software development.
[basic requirements]
The system should complete the following functions:
1) Enter information - enter ():
2) Display information - display ():
3) Search (), with name as the key word;
4) Delete ();
5) Save ():
6)load ();
(4)Conversion of number system
[problem description]
Any given M-ary number x, please achieve the following requirements
[basic requirements]
2
Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
1) Find the decimal value of this number x (expressed in HD)
2) Realize the conversion of X to any non-m-ary number.
3) stack or array is used to achieve the above requirements.
(5) DFS traversal of Graphs
[problem description]
Starting from any given vertex (called initial point) in a given graph, all vertices in the graph are
accessed along the edge of the graph according to some search method, so that each vertex is
accessed only once. Please use DFS depth-first search process to realize traversal.
[basic requirements]
1) First, create any graph;
2) Implementation of recursive and non-recursive algorithms for DFS of graph
3) It is required to use an adjacency matrix or adjacency table to store.
(6)Ranking synthesis
[problem description]
Use the random function to generate N random integers, and sort these numbers in various ways.
[basic requirements]
1) At least three methods are used to solve the above problems (prompt, quick sort must be done o
other available methods are inserted sort, Hill sort, bubble sort, select sort, heap sort, and merge
sort). The sorted results are saved in different files.
2) Count the performance of each sorting method (based on the time it takes to run the program on
the computer), and find out two faster methods.
3) If four or more methods are used, additional points can be given.
Submission
1) Submit the curriculum design report; 2) Submit the source program.
3
Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
4
Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
Final Report
I have answered question 6, whose topic Ranking synthesis
1. Problem Analysis (15 points)
Sorting is the process of placing elements from a collection in some kind of order. For
example, a list of words could be sorted alphabetically or by length. A list of cities
could be sorted by population, by area, or by zip code. We have already seen several
algorithms that we're able to benefit from having a sorted list.
In the following scientific report, the basic sorting algorithms will be discussed and
examined. Timing will be done on the different sorting algorithms and experiments
will be done to count the performance of each sorting method (based on the time it
takes to run the program on the computer), and find out two faster methods.
We will discuss the reasons why each sorting algorithm is efficient and under which
conditions are efficient. A brief explanation of each sorting algorithm will be given to
get the basic idea of what it’s all about by giving coding. Then a brief conclusion will
be done to the round of the scientific report. The sorting method we know are quick
sort, bubble sort, merge sort, insertion sort, selection sort, heap sort, and many many
other sorts but in this experiment, I will use four methods of sorting which are quick
sort, bubble sort, insert sort, and selection sort. Shown below is the performance of
each sorting method in the program output option.
2. Algorithm Design (30 points)
2.1 Quick Sort:
(i) Algorithm of Quick Sort:
Make elements randomly as user required.
Partition the array based on pivot.
Apply a quick sort on the left partition recursively.
Apply a quick sort on the right partition recursively.
5
Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
Show sorted array order.
(ii) Pseudo code for quick sort:
low --> Starting index, high --> Ending index
sortPivotPosition (A[], low, high)
{
pivot = A[high];
i = (low - 1);
for (j = low; j <= high- 1; j++)
{
if (A[j] < pivot)
{
i++;
swap A[i] and A[j]
}
}
swap A[i + 1] and A[high])
return (i + 1)
}
quickSort(A[], low, high)
{
if (low < high)
{
pivot = SortPivotPosition(A, low, high);
quickSort(A, low, pivot - 1);
quickSort(A, pivot + 1, high);
}
}
2.2 Bubble Sort:
(i) Algorithm of Bubble Sort:
Make randomize elements as user required.
Repeatedly iterate through the array.
Swap adjacent elements that are unordered.
Sorted the elements recursively.
Show the sorted order as output.
6
Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
(ii) Pseudocode for bubble sort:
Initialize n = Length of Array
BubbleSort(Array, n)
{
for i = 0 to n-2
{
for j = 0 to n-2
{
if Array[j] > Array[j+1]
{
swap(Array[j], Array[j+1])
}
}
}
}
2.3 Insertion Sort:
(i)Algorithm of Insertion Sort:
Make array elements randomly.
The first element of an array is assumed in the right position. Take the second
element and store it separately.
Compare the key/second element with the first element. If the first element is
greater than the key, then the key is placed in front of the first element.
Similarly, place every unsorted element at its correct position.
Finally, show the output of the sorted order.
(ii) Pseudo code for insertion sort:
Initialize n = Length of Array
InsertionSort(Array, n)
{
for i = 1 to n-1
{
7
Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
value = Array[i]
position = i
while (position > 0 and Array[position-1] > value)
{
Array[position] = Array[position - 1]
position = position - 1
}
Array[position] = value;
}
}
2.4 Selection Sort
(i)Algorithm of Selection Sort:
Randomize array elements.
Set min to the location.
Search the minimum element in the array.
Swap the first location with the minimum value in the array.
Assign the second element as min.
Repeat the process until we get a sorted array.
Show final sorted array order.
(ii) Pseudocode for selection sort:
Initialize n = Length of Array
SelectionSort (Array, n)
for i = 0 to n-2
i_min = i
for j = i+1 to n-1
{
8
Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
if Array[j] < Array[i_min]
i_min = j
Swap(Array[j], Array[i_min])
3. Source Code (30 points)
(i)Quick sort
/* C implementation QuickSort */
#include<stdio.h>
#include <stdlib.h>
// A utility function to swap two elements
void swap(int* a, int* b)
int t = *a;
*a = *b;
*b = t;
9
Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
/* This function takes the last element as pivot, places
the pivot element at its correct position in sorted
array, and places all smaller (smaller than pivot)
to the left of the pivot and all greater elements to the right
of pivot */
int partition (int arr[], int low, int high)
int pivot = arr[high]; // pivot
int i = (low - 1); // Index of smaller element
for (int j = low; j <= high- 1; j++)
// If current element is smaller than the pivot
if (arr[j] < pivot)
i++; // increment index of smaller element
swap(&arr[i], &arr[j]);
swap(&arr[i + 1], &arr[high]);
return (i + 1);
10
Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
/* The main function that implements QuickSort
arr[] --> Array to be sorted,
low --> Starting index,
high --> Ending index */
void quickSort(int arr[], int low, int high)
if (low < high)
/* pi is partitioning index, arr[p] is now
at right place */
int pi = partition(arr, low, high);
// Separately sort elements before
// partition and after partition
quickSort(arr, low, pi - 1);
quickSort(arr, pi + 1, high);
/* Function to print an array */
void printArray(int arr[], int size)
11
Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
int i;
for (i=0; i < size; i++)
printf("%d ", arr[i]);
printf("\n");
// Driver program to test above functions
int main()
//int arr[] = {10, 7, 8, 9, 1, 5};
//int n = sizeof(arr)/sizeof(arr[0]);
int sz;
printf("Enter the size of array: ");
scanf("%d",&sz);
int array[sz],i;
for(i=0;i<sz;i++){
array[i]=rand()%100;
quickSort(array, 0, sz-1);
printf("Sorted array: \n");
12
Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
printArray(array, sz);
return 0;
(ii) Bubble sort
// C program for implementation of Bubble sort
#include <stdio.h>
#include <stdlib.h>
void swap(int *xp, int *yp)
int temp = *xp;
*xp = *yp;
*yp = temp;
// A function to implement bubble sort
void bubbleSort(int arr[], int n)
int i, j;
for (i = 0; i < n-1; i++)
// Last i elements are already in place
13
Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
for (j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1])
swap(&arr[j], &arr[j+1]);
/* Function to print an array */
void printArray(int arr[], int size)
int i;
for (i=0; i < size; i++)
printf("%d ", arr[i]);
printf("\n");
// Driver program to test above functions
int main()
//int arr[] = {64, 34, 25, 12, 22, 11, 90};
//int n = sizeof(arr)/sizeof(arr[0]);
int sz;
printf("Enter the size of array: ");
14
Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
scanf("%d",&sz);
int array[sz],i;
for(i=0;i<sz;i++){
array[i]=rand()%100;
bubbleSort(array, sz);
printf("Sorted array: \n");
printArray(array, sz);
return 0;
(iii) Insert sort
// C program for insertion sort
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
/* Function to sort an array using insertion sort*/
void insertionSort(int arr[], int n)
int i, key, j;
for (i = 1; i < n; i++) {
15
Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
key = arr[i];
j = i - 1;
/* Move elements of arr[0..i-1], that are
greater than key, to one position ahead
of their current position */
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j = j - 1;
arr[j + 1] = key;
// A utility function to print an array of size n
void printArray(int arr[], int n)
int i;
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
16
Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
/* Driver program to test insertion sort */
int main()
int sz;
printf("Enter the size of array: ");
scanf("%d",&sz);
int array[sz],i;
for(i=0;i<sz;i++){
array[i]=rand()%100;
insertionSort(array, sz);
printArray(array, sz);
return 0;
(iv) Selection sort
17
Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
// C program for implementation of selection sort
#include <stdio.h>
#include <stdlib.h>
void swap(int *xp, int *yp)
int temp = *xp;
*xp = *yp;
*yp = temp;
void selectionSort(int arr[], int n)
int i, j, min_idx;
// One by one move boundary of unsorted subarray
for (i = 0; i < n-1; i++)
// Find the minimum element in unsorted array
min_idx = i;
for (j = i+1; j < n; j++)
if (arr[j] < arr[min_idx])
18
Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
min_idx = j;
// Swap the found minimum element with the first element
swap(&arr[min_idx], &arr[i]);
/* Function to print an array */
void printArray(int arr[], int size)
int i;
for (i=0; i < size; i++)
printf("%d ", arr[i]);
printf("\n");
// Driver program to test above functions
int main()
//int arr[] = {64, 25, 12, 22, 11};
//int n = sizeof(arr)/sizeof(arr[0]);
19
Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
int sz;
printf("Enter the size of array: ");
scanf("%d",&sz);
int array[sz],i;
for(i=0;i<sz;i++){
array[i]=rand()%100;
selectionSort(array, sz);
printf("Sorted array: \n");
printArray(array, sz);
return 0;
4. Program Output (10 points)
Quicksort
20
Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
Bubblesort
Insert sort
Selection sort
Count the performance of each sorting method (based on the time it takes to run the
program on the computer), and find out two faster methods.
Quicksort: 4.767 seconds
Bubble sort: 2.755 seconds
Insert sort: 3.182 seconds
Selection sort: 3.616 seconds
Bubble sort and Insert sort were the two fast methods.
5. Conclusion (15 points)
The way the experiment was executed:
Code was written for each sorting algorithm in a method in a specific program. A
new timing class was created, to have something to time how fast or slow the different
21
Course design of data structure and algorithm analysis Name: SIAM ABDUR RAHMAN Student ID:19416443
sorting algorithms get sorted. Then the method for every four sorting algorithms gets
executed and run to get an average, to eliminate errors that might have been caused.
After all the data has been recorded.
In my research, Bubble sort is probably one of the most popular and simple sorting
algorithms. It is often used as a programming exercise for beginners because it is
relatively easy to grasp and understand. The problem though is that it's not very
efficient, therefore bubble sort only gets used once in a blue moon. There are more
efficient sorting algorithms used in a real application.
Problems that arise:
The main problem that happened was, each time the program ran the results weren’t
always constant. And if the program was not dedicated (i.e. the only program running
at the time) then the values went haywire. This problem was fixed by forcing the dev
c++ and code block ide to run a garbage collector and collect all the garbage, to
make sure that when the program runs all the processing power is used for the
program so the times will be more accurate.
Conclusion, In this report four different sorting algorithms were discussed. Each one
was investigated and briefly explained how they work by coding, and why each one is
efficient in their own right. As the experiment when on it was noticed that some
sorting algorithms are less efficient than other’s and that had all to do with how each
sorting algorithm works.
22