#include <iostream>
using namespace std;
//brute force method where we check all the combinations and see
if their sum is 20
void print_pairs_forunsorted(int a[],int n)
{
int i,j;
cout<<"\nPrinting pairs for unsorted array";
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]+a[j]==20)
{
cout<<"\n("<<a[i]<<","<<a[j]<<")";
}
}
}
}
//for sorted we have two pointers one to the beginning l and one to ending r
//if a[l]+a[r] is less than 20 then we need to choose element greater than a[l] so we increment l
//if a[l]+a[r] is greaterthan 20 then we need to choose element
lessthan a[r] so we decrementl
void print_pairs_forsorted(int a[],int n)
{
int l = 0;
int r = n - 1;
cout<<"\nPrinting pairs for sorted array";
while (l < r)
{
if(a[l]+a[r]== 20)
{
cout<<"\n("<<a[l]<<","<<a[r]<<")";
l++;
r--;
}
else if(a[l]+a[r]< 20)
l++;
else if(a[l]+a[r]>20)
r--;
}
}
int main()
{
int a[] = {1, 2, 3, 17, 18, 20};
int b[] = {11, 2, 9, 17, 18, 3};
print_pairs_forunsorted(b,6);
print_pairs_forsorted(a,6);
return 0;
}

Using simple and basic C++ (do not use #include <algorithm>), write two functions (one for a...
With basic (do not use #include <algorithm>, etc.) and simple C++ Write a program which reads a text file “input.txt” and stores all the distinct words in an array. A word consists of letters only - uppercase and/or lowercase. An incoming word should be inserted into the array such that it is always in ascending order. Use binary search to ensure that no duplicate words are added. Assume that there are no more than 100 distinct words. Assume that the...
Exercise 3: Searching Applications Design and implement an algorithm that determines whether or not a given array of integers, list1, is completely contained within another given array of integers, list2. Consider two different scenarios: (1) Both arrays are unsorted and (2) both arrays are sorted and write functions unsortedSearch and sortedSearch for (1) and (2), respectively. Your algorithm for (2) is expected to be more efficient than the one for (1). Please Answer in c++ and show the algorithm working
In C++: Write a C++ function binsearch that carries out the binary search algorithm on a sorted array of integers. Your function takes as parameters an array of integers (sorted in increasing order), the size of the array, and a target integer to search for. The function returns the index of the target in the array, and returns -1 if the target is not in the array. Using the code below, add your binsearch function to this C++ program. (Do...
Write a C++ function binsearch that carries out the binary search algorithm on a sorted array of integers. Your function takes as parameters an array of integers (sorted in increasing order), the size of the array, and a target integer to search for. The function returns the index of the target in the array, and returns -1 if the target is not in the array. The file main1.txt on the webpage contains code that generates a specific array of integers...
In C++ Do not use classes. Write a function to add two integers of any length, say up to 200 digits. he suggested approach as follows: treat each number as a list array, each of those elements is a block of digits of that number ( say block of 1 to 4 digits, your choice). For example the integer 123456789101112 might be stored as N(1)=1112, N(2)=8910, N(3)=4567, N(4)=123. then add two integers (list) element by element, caring from one element...
TO DO: IMPLEMENT SELECTION SORT, BUBBLE SORT, MERGE SORT INSTRUCTIONS: GENERATE AN ARRAY arr AND FILL IT WITH 100 RANDOM INTEGERS, HAVING VALUES 0-99. PRINT THE UNSORTED ARRAY IMPLEMENT EACH SORTING ALGORITHM (DO NOT USE THE BUILT-IN LIBRARIES) FOR EACH ALGORITHM, INCLUDE PSEUDOCODE WITH NUMBERED STEPS. IN YOUR CODE, CLEARLY COMMENT WHICH STEP IS BEING PERFORMED BY THE LINE OR BLOCK OF CODE. USE A TIMER TO CHECK HOW LONG EACH ALGORITHM TAKES TO SORT THE ARRAY. THIS SHOULD BE...
keep it as simple as possible. do not use any advanced
algorithm or functions.
Based on 2d arrays and other basic C++ functions
first picture is the start of the program plz follow
const int HAXTBLSIE100 theable ssze 100 int main void 무{ nt tg3ize int ebaiee ea c for 4 int 1-0, choice "-i “ tilesane [1] !-.., i.., 白 printTrg . table, trgSize): tindPathO princPathOeeda par ein ehoiee Save the oatpat belo
In the text box below, write down a divide and conquer algorithm for counting the number of entries in a sorted array of ints that are smaller than a given value. In other words, the function takes as input an array A and an int value and returns the number of ints in A that are less than value. To get any credit, your solution must use the divide and conquer technique. To get full credit, your solution should run in time in the...
Please help me with this algorithm assignment using Java Write 2 functions to calculate the MSS of a given array one with running time of O(n) and one with O(nlogn) .Request the user to enter a positive integer, and call it n. 1.Generate n random integers between -100 to 100 and save them in array a. 2.Print the generated array and the outputsof your two functions
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...