Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please I need help with this... in C++ *****************************************

ID: 3792996 • Letter: P

Question

Please I need help with this... in C++

***********************************************************************************************

1. What are the top 2 sorting and searching algorithms ?

    Explain why so...

2. Write a OOP program that store an array of 100 integers.

    Add/code 1 of the top 2 sorting algorithms you mentioned above

    Add/code 1 of the top 2 searching algorithms you mentioned above

    Have a function to ask the user for input.

    Have a function to print out the array

    Have a function to delete an integer

    Have the ability to know/printout the count the number of integers

Explanation / Answer

1)
i) The top 2 sorting alogrithms are: insertion sort and quick sort. They are top 2 sorting algorithms because they will give the less time complexity and more throughput.

ii) The top 2 searching algorithms are linear search and the binary search. The binary search will give the less searching time when compared to the linear search.

Codes illustrating the insertion sort and binary search and the functions asked above:

2)Code:

#include<conio.h>
#include<iostream.h>
int ip;
int a[50],count=0,n,i,j,k;
int main(){

   user_ip();
   print_array();
   perform_binary_search(ip);
   perform_insertion_sort();
   return 0;

}
void user_ip(){
   cout<<"Enter input:";
   cin>>ip;
}
void print_array(){
   int i;
   for(i=0;i<sizeof(a)/sizeof(int);i++)
       cout<<a[i]<<" ";
}
void count_array(){
   for(i=0;i<sizeof(a)/sizeof(int);i++)
       count++;
   cout<<"Total no.of elements in array:"<<count<<endl;
}
void perform_binary_search(int ip){
   int low=0,n = count;
   key = ip;
   int high = n-1;
   while(low<=high){
       mid = (low+high)/2;
       if(a[mid] == key)
           cout<<"element is found at position:"<<mid + 1;
       else if (a[mid] > key)
           high = mid -1;
       else
           low = mid + 1;
   }
}

void perform_insertion_sort(){
   int temp;
   n = count;
   for(i=0;i<n;i++)
       for(j=i+1;j<n;j++)
           if(a[i]>a[j])
           {
               temp = a[i];
               a[i] = a[j];
               a[j] = temp;
           }
   cout<<"Sorted array:"<<endl;
   for(i=0;i<n;i++)
       cout<<a[i]<<" ";

}