## From Where Do I Learn Data Structure?

Multiple resources can aid students to learn Data Structure and algorithms. Among the best Data Structure assignment assistance team are found on the website Assignment Online Help. The website has positioned itself as the ultimate assignment help on areas of Data Structure among other related concepts and topics. To get assistance on Data Structure college homework, simply contact customer support at Assignment Online Help.

When learning data structure, students can use useful books such as Advanced Data Structure in C++ that has crucial information that can assist one to be better in a data structure, I used this book and it helped shaped me to be good at Data Structure concepts. The most important thing about all programming languages is that learners should always implement the various concepts they are taught. Constant practicing will enable students to clarify the areas taught and be more competent.

If you are an advanced learner in the data structure, I would recommend for the book introduction to algorithms by CLS. This book serves as the cookbook for all the important Data Structure. The complex language associated with the book will make it unsuitable for beginners. For any other queries relating to Data Structure assignments or Data Structure college coursework assistance, I would recommend for students to share their queries with Data Structure specialists at Assignment Online Help.

The good thing about Assignment Online Help is that it caters to all assignment coursework related to the data structure. Most importantly, the website assures learners of their privacy regardless of the services offered. Post your Data Structure assignment today at Assignment Online Help.

How Can I Lean Data Structures Effectively?

How Can I Lean Data Structures Effectively?

Assignment Online Help is the leading Data Structure and Algorithm assignment help services. The website has attained this state after consistently assisting students to solve Data Structure and Algorithm assignments accurately and professionally for more than ten years. I would recommend the website Assignment Online Help for students struggling with Data Structure and Algorithm homework problems.

What is important to note when dealing with Data Structure and Algorithm is that there are no shortcuts. The following steps recommended by Data Structure and Algorithms experts should be followed.

1. Learning both fundamentals and theory. This will consist of the following topics, Algorithms, collection, arrays, complexity analysis, Graphs, Hashtables, Linked lists, Heaps, Research, trees, Sot, and recursions.

2. Step two will involve checking examples and the application of knowledge. A good place to find examples in the course is the website Assignment Online Help.

For those preparing for professional interviews on Data Structure and Algorithm, I would recommend the following steps to be followed.

- Placement preparation guide
- A detailed guide to step by step guide for placement preparation
- The 10 algorithms in interview questions
- Preparations for tom MNCs
- Sudo placement

Apart from the steps mentioned above, it is important for students to consistently practice concepts in data structure and algorithm. This will improve their level of competency and make them conversant with the technical aspect of Data Structure and Algorithm college coursework.

I advise learners in Data structure and algorithms to find solutions to their queries relating to Data Structure and Algorithm by visiting Assignment Online Help.

**Our C++ Experts have prepared sample assignment solution to demonstrate the quality of our work. All the solutions have been prepared by following a simplistic approach and include step by step explanations. These solutions reflect the in-depth expertise and experience of our online C++ assignment experts.**

**INSTRUCTIONS:**You are writing a program. It must compile, execute and produce the desired output. Use C/C++, Java. You *may* be asked to show that your program compiles, executes and produces the desired output, by scheduling a meeting time with the Instructor.

**OBJECTIVE:**

Write a program to sort a given array A[n] by:

1. quicksort

2. mergesort

**PROCESSING:**

1. Sort the given array using quicksort and output the sorted array.

2. Sort the given array using mergesort and output the sorted array.

Your program must have the following function clearly identified and implemented:

Comparison function - to compare an array element to another array element: -

LESS(a, b) : if (a < b) return true, else return false.

Note that all other operators (>, >=, <=, ==, !=) can be computed by making appropriate calls to the above function.

The above function must increment a counter 'comparison_count' (this will be needed for output).

Obviously, one of your goals is to minimize the total number of array element comparisons. ABSOLUTELY NO "array element" comparisons outside of this function.

The program should output the sorted array and the total number of element comparisons taken for each of the sorting methods.

**INPUT:**

You can assume the elements will be of type 'double'.

Read the input array from a file named "input.txt".

This file will have the array elements separated ONLY by "end of line (newline)" characters.

The first line will have the number of elements (integer).

Thereafter, each line will contain one element of the array (double).

No other characters will be present in the file.

For Example:

3

23.65

8.56

10.45

Test your program with arrays of size ~10,000 or higher. Note that your program must NOT take command line inputs.

**OUTPUT(S):**

Your program will generate 2 output files:

_quick.txt: output the sorted array for quicksort (keep same format as the input) output the total number of comparisons taken

_merge.txt: output the sorted array for mergesort (keep same format as the input) output the total number of comparisons taken

For example, mine will be deepak_quick.txt and deepak_merge.txt.

**SOLUTION:**

#include

#include

#include

using namespace std;

int merge_count = 0;

int quick_count = 0;

void displayArray(double arr[], int n)

{

for(int i = 0;i
{

cout<
}

cout<<""<
}

int partition(double arr[], int start, int end)

{

int pivot = arr[start];

int count = 0;

for (int i = start + 1; i <= end; i++) {

if (arr[i] <= pivot)

count++;

quick_count++;

}

int pivotIndex = start + count;

swap(arr[pivotIndex], arr[start]);

int i = start, j = end;

while (i < pivotIndex && j > pivotIndex) {

while (arr[i] <= pivot) {

i++;

}

while (arr[j] > pivot) {

j--;

}

if (i < pivotIndex && j > pivotIndex) {

swap(arr[i++], arr[j--]);

}

}

return pivotIndex;

}

void quickSort(double arr[], int start, int end)

{

if (start >= end)

return;

int p = partition(arr, start, end);

quickSort(arr, start, p - 1);

quickSort(arr, p + 1, end);

}

void merge(double values[], int leftFirst, int leftLast, int rightFirst, int rightLast){

double temparray[1000];

int index = leftFirst;

int saveFirst = leftFirst;

while((leftFirst <= leftLast) && ( rightFirst <= rightLast)){//compare and select smallest from two subarrays

if(values[leftFirst] < values[rightFirst]){

temparray[index] = values[leftFirst]; //smallest assigned to temp

leftFirst++;

}

else

{

temparray[index] = values[rightFirst];

rightFirst++;

}

index++;

merge_count++; //count of comaparisons done during merge. One comparison is done per iteration of while loop.

}

while(leftFirst <= leftLast){

temparray[index] = values[leftFirst];

leftFirst++;

index++;

}

while(rightFirst <= rightLast){

temparray[index] = values[rightFirst];

rightFirst++;

index++;

}

for(index = saveFirst; index <= rightLast; index++)//copies from temp array to values array

values[index] = temparray[index];

}

void mergesort(double a[], int start, int end){

if(start < end){

int mid = (start+end)/2;

mergesort(a,start, mid);

mergesort(a,mid+1,end);

merge(a, start,mid, mid+1, end);

}

}

void writeToFile(string file_name,double arr[], int size,int count)

{

ofstream file;

file.open(file_name);

file<
for(int i =0;i
{

file << arr[i] <<"\n";

}

file<<"Number of comparision: "<
file.close();

}

int main()

{

// reading the file

ifstream file;

file.open("input.txt");

if(file.is_open())

{

string size;

getline(file, size);

int l = stoi(size);

double arr[1000];

double temp_arr[1000];

int index = 0;

double element;

string data;

while(file)

{

getline(file, data);

element = stod(data);

arr[index] = element;

temp_arr[index] = element;

index++;

}

cout<<"Array Read From File"<
displayArray(arr,l);

mergesort(arr,0,l-1);

cout<<"Array After Merge Sort"<
displayArray(arr,l);

cout<<"Number Of Comparision In Merge Sort: "<

quickSort(temp_arr, 0, l-1);

cout<<"Array After Quick Sort"<
displayArray(temp_arr,l);

cout<<"Number Of Comparision In Quick Sort: "<

writeToFile("merge.txt", arr,l, merge_count);

writeToFile("quick.txt", temp_arr,l, quick_count);

cout<<"Data Writtien To File"<
}

else

{

cout<<"Cannot open the file input.txt"<
}

return 0;

}