Question

Please Use C++ Language. And Note that please donot post the answer already there Because there...

Please Use C++ Language.

And Note that please donot post the answer already there Because there is similar answer code but I need with modified Quick sort algorithm ​.

Update your program from ... Create an array that holds 1000 random integers between 1-1000. Allow the user to enter an integer to search. Create and implement modified Quick sort algorithm which will sort the array before the Binary Search algorithm is executed. Create and implement a Binary Search Algorithm . If the number exists in the array and output the position. If the search key does not exist in the Array simple output value not found. Use the clock(); method to time the execution of the search and sort Execute the program 3 times. Twice running the modified Quick sort as the sorting algorithm. Describe your results in relation to "Create and implement modified bubble sort algorithm which will sort the array before the Binary Search algorithm is executed.Create and implement Insertion sort algorithm which will sort the array before the Binary Search algorithm is executed.", the insertion sort and the bubble sort.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program #include <iostream> #include <cstdlib> #include <time.h> #include <ctime> using namespace std; int binary Search (int Arr,int k, int size) int start-0; int end = size-1; while (start <- end) int mid = (start + end) / 2; if (kArr[mid]) return mid; if (k < Arr[mid]) [ end = mid-1; else start - mid 1; return-1i void bubble Sort (int Array[], int size) [ int t = 0; for (int i- 0 i< size i++) for (int j -1 j< (size - i) j++) if (Array[j -1 >Arra y tj) ( //swap the elements! t = Array[j - 1];

Editable code

Program

#include<iostream>

#include<cstdlib>

#include <time.h>

#include <ctime>

using namespace std;

int binary_Search(int Arr[], int k, int size) {

     int start = 0;

     int end = size - 1;

     while (start <= end) {

          int mid = (start + end) / 2;

          if (k == Arr[mid]) {

              return mid;

          }

          if (k < Arr[mid]) {

              end = mid - 1;

          }

          else {

              start = mid + 1;

          }

     }

     return -1;

}

void bubble_Sort(int Array[], int size) {

     int t = 0;

     for (int i = 0; i < size; i++) {

          for (int j = 1; j < (size - i); j++) {

              if (Array[j - 1] > Array[j]) {

                   //swap the elements!

                   t = Array[j - 1];

                   Array[j - 1] = Array[j];

                   Array[j] = t;

              }

          }

     }

}

int partitioning(int a[], int l, int u)

{

     int v, i, j, temp;

     v = a[l];

     i = l;

     j = u + 1;

     do

     {

          do

              i++;

          while (a[i]<v&&i <= u);

          do

              j--;

          while (v<a[j]);

          if (i<j)

          {

              temp = a[i];

              a[i] = a[j];

              a[j] = temp;

          }

     } while (i<j);

     a[l] = a[j];

     a[j] = v;

     return(j);

}

void quick_sort(int Array[], int l, int u)

{

     int j;

     if (l<u)

     {

          j = partitioning(Array, l, u);

          quick_sort(Array, l, j - 1);

          quick_sort(Array, j + 1, u);

     }

}

void Insertion_sort(int Array[], int size)

{

     int t,i,j;

     for (i = 1; i < size; i++)

     {

          for (j = i; j >= 1; j--)

          {

              if (Array[j] < Array[j - 1])

              {

                   t = Array[j];

                   Array[j] = Array[j - 1];

                   Array[j - 1] = t;

              }

              else

                   break;

          }

     }

}

int main()

{

     clock_t b1, b2,b3;

     double time1, time2;

     srand(time(NULL));

     int array[1000];

     int l = 0;

     cout << "\nQuick Sort";

     while (l < 3)

     {

          for (int i = 0; i < 1000; i++) {

              array[i] = rand() % 1000 + 1;

          }

          int search;

          cout << "\nEnter the search number: ";

          cin >> search;

          quick_sort(array,0,999);

          bubble_Sort(array, 1000);

          int pos = binary_Search(array, search, 1000);

          b1 = clock();

          if (pos != -1) {

              cout << "\nNumber found at position " << pos << endl;

          }

          else {

              cout << "\nNumber not found" << endl;

          }

          time2 = (double)(b1) / CLOCKS_PER_SEC;

          cout << "\nTime taken for search :" << time2;

          l++;

     }

     cout << "\nbubble sort";

     l = 0;

     while (l < 3)

     {

          for (int i = 0; i < 1000; i++) {

              array[i] = rand() % 1000 + 1;

          }

          int search;

          cout << "\nEnter the search number: ";

          cin >> search;

          bubble_Sort(array, 1000);

          int pos = binary_Search(array, search, 1000);

          b2 = clock();

          if (pos != -1) {

              cout << "\nNumber found at position " << pos << endl;

          }

          else {

              cout << "\nNumber not found" << endl;

          }

          time2 = (double)(b2) / CLOCKS_PER_SEC;

          cout << "\nTime taken for search :" << time2;

          l++;

     }

     cout << "\nInsertion sort";

     l = 0;

     while (l < 3)

     {

          for (int i = 0; i < 1000; i++) {

              array[i] = rand() % 1000 + 1;

          }

          int search;

          cout << "\nEnter the search number: ";

          cin >> search;

          Insertion_sort(array, 1000);

          int pos = binary_Search(array, search, 1000);

          b3 = clock();

          if (pos != -1) {

              cout << "\nNumber found at position " << pos << endl;

          }

          else {

              cout << "\nNumber not found" << endl;

          }

          time2 = (double)(b3) / CLOCKS_PER_SEC;

          cout << "\nTime taken for search :" << time2;

          l++;

     }

     cout << endl;

     system("pause");

     return 0;

}

Add a comment
Know the answer?
Add Answer to:
Please Use C++ Language. And Note that please donot post the answer already there Because there...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • does anyone know how to do this? C++ Your task for this assignment is to use...

    does anyone know how to do this? C++ Your task for this assignment is to use C++ language to implement an insertion sort algorithm. 1. Implement an insertion sort with an array to sort 10 arbitrary numbers using the C++ programming language. The program initializes an array with 10 random 3-digit positive integers. The program then sorts the numbers in the array using the insertion sort algorithm. 2. The program displays the original values in the array before the sort...

  • My following program has an array which holds 1000 random integers between 1-1000. Now I need...

    My following program has an array which holds 1000 random integers between 1-1000. Now I need help to create an array that holds 10,000 random integer between 1-1000 in my following program. The main goal of this program is time analysis by using bubble sort and binary search algorithms. Please do the following task; 1. Replace the 1000 random integers with 10,000 random integers After change please answer the following question 2. what will be happen, if an array holds...

  • Please Use C++ Language. Thank you. Please I need the actual code. Donot post psudocode!! ​And...

    Please Use C++ Language. Thank you. Please I need the actual code. Donot post psudocode!! ​And also I have codes but just donot work so make sure that it works. Requested files: CrosswordGenerator.cpp, CrosswordGenerator.h, CrosswordGenerator_test.cpp CrosswordGenerator - Write a program that helps to generate a crossword puzzle by organizing words that share letters.   For this assignment, you will write a program that forms the basis of a crossword puzzle generator. In order to create a crossword puzzle you need to...

  • In C only Please! This lab is to write a program that will sort an array...

    In C only Please! This lab is to write a program that will sort an array of structs. Use the functions.h header file with your program. Create a source file named functions.c with the following: A sorting function named sortArray. It takes an array of MyStruct's and the length of that array. It returns nothing. You can use any of the sorting algorithms, you would like though it is recommended that you use bubble sort, insertion sort, or selection sort...

  • do in C++ language thank you Task 4: Functions or classes are ok. Please read data...

    do in C++ language thank you Task 4: Functions or classes are ok. Please read data into program from descending_mostly_sorted.txt and store into an array. Implement Selection Sort to sort the values in ascending order. Least → Greatest Measure the time it takes to execute the sort in milliseconds or even nanoseconds. Please run the sort 3 times. Attach Photos of Source Code and Output Task 5: Functions or classes are ok. Please read data into program from descending_mostly_sorted.txt and...

  • Task 3: Functions or classes are ok. Create an array that holds 1000 random floats between...

    Task 3: Functions or classes are ok. Create an array that holds 1000 random floats between 1-1000. Implement Quick Sort to sort the values in ascending order. Least → Greatest Measure the time it takes to execute the sort in milliseconds. Please run the sort 3 times. Attach Photos of Source Code and Output

  • ***PLEASE USE C++ LANGUAGE*** Binary Search of Strings 1. Write a version of the selection sort...

    ***PLEASE USE C++ LANGUAGE*** Binary Search of Strings 1. Write a version of the selection sort algorithm presented in the unit, which is used to search a list of strings. 2. Write a version of the binary search algorithm presented in the unit, which is used to search a list of strings. (Use the selection sort that you designed above to sort the list of strings.) 3. Create a test program that primes the list with a set of strings,...

  • c++ data structures please Pick any inefficient sorting algorithm you want, selection, bubble, insertion, etc., and...

    c++ data structures please Pick any inefficient sorting algorithm you want, selection, bubble, insertion, etc., and implement it as a function. Using the system clock as a timer, determine when the efficiency of the algorithm breaks down. For example, does it become slow after 1000 elements, 10000 elements, 100000 elements? Write some code to figure this out. Then use the sort() algorithm that is part of the STL <algorithm> library. How does this function compare to the function you implemented?...

  • Comparison of Sorting Algorithms You are required to implement all the sorting algorithms (Bubble, Selection, Insertion...

    Comparison of Sorting Algorithms You are required to implement all the sorting algorithms (Bubble, Selection, Insertion, Quick, Merge). Take help from lecture slides and welb . You will then create arrays of different sizes as instructed below, test each algorithm on each array and record the execution times of each individual algorithm on each array. . You will report these execution times in a table and then write a report explaining the execution times of the sorting algorithms according to...

  • 1. a. Using C++, represent the following graph using adjacency matrix, and implement depth first searching...

    1. a. Using C++, represent the following graph using adjacency matrix, and implement depth first searching (DFS) by stack (define it with class) to traverse the graph. 6 7 2 4 b. If starting with node 2, when node 7 is printed, what numbers are in the stack (for DFS)? Please draw the stack step by step to show how the numbers are pushed into and popped out of it. 2. a. Given a set of integer numbers as int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT