
1) Write a full program for the bubble sort algorithm. User is required to enter specific input numbers and the program will be able to sort the given numbers in ascending order. Write down in a table the time (according to your system clock) that it takes for the program to complete. You may do this by running the program for several values of input.
Hints: a) Write full source code b) Use system clock to measure the running time c) Use several input (eg: N = 100 , N = 1000 , N = 10000, N = 100000 etc) d) Have access to a file (to store your running time)
2) What is the difference between static and dynamic memory allocations? List advantages and disadvantages for the both type of memory allocations.
3) Use structure to wrap student information (such as Matrix Number, name and MTS 3023 mark) and manipulate it by reading information to an array of student structure and print them on to console screen.
4) The common error message which might encounter in your program is ?memory access violation? or ?segmentation violation?. What does it mean? How to avoid it?
5) For each of the following four program fragments: a. Give an analysis of the running time (Big-Oh) b. Implement the code and give the running time for several values of N c. Compare your analysis with the actual running times

C++ Bubble Sort
#include <iostream>
using namespace std;
void sort(int ar[], int size)
{
int temp;
for(int i = 0; i < size; i++)
for(int j = 0; j < size - i - 1; j++)
if(ar[j] > ar[j + 1])
{
temp = ar[j];
ar[j] = ar[j + 1];
ar[j + 1] = temp;
}
}
int main()
{
int *array;
int size;
cout << "Enter size of array: ";
cin >> size;
array = new int[size];
for (int x = 0; x < size; x++)
{
cout << "Enter value for index " << x + 1 << ": ";
cin >> array[x];
}
cout << "Before sorting: ";
for (int i = 0; i < size; i++)
{
if (i == (size - 1))
cout << array[i];
else
cout << array[i] << ", ";
}
sort(array, size);
cout << "\nAfter sorting: ";
for (int j = 0; j < size; j++)
{
if (j == (size - 1))
cout << array[j];
else
cout << array[j] << ", ";
}
cin.ignore();
cin.get();
delete array;
return 0;
}

Difference between Static and Dynamic Memory Allocation:
1)Dynamic memory allocation is at runtime. static memory allocation is before run time, but the values of variables may be changed at run time. Static memory allocation saves running time, but can't be possible in all cases.
2)Dynamic memory allocation stores it's memory on heap, and the static memory allocation stores it's data in the "data segment" of the memory.