Write a program in C++ that removes the duplicates from a given array. You will
ID: 3575662 • Letter: W
Question
Write a program in C++ that removes the duplicates from a given array. You will use a binary search tree to implement the following algorithm 1. You will create an array of 100 integers and fill in the array with randomly generated numbers between 0 and 100. Print this initial array on the screen 2. Your program will remove the duplicates using a binary search tree as follows a. Insert the numbers in the array into the binary tree b. If the number already exists in the tree l. Do not insert this duplicate value into the tree ll. Print a message on the screen that a duplicate is found 3. Copy the numbers from the binary search tree to a new array in increasing order and print it on the screen. This new array will not contain any duplicate numbers. Comment on your program What is the complexity of this algorithm? Can this algorithm be implemented without a binary search tree? What will be the efficiency of the algorithm in this case?Explanation / Answer
1.
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int main()
{
int array[100]; // for storing 100 elements.
srand((unsigned)time(0)); //to generate random numbers in time interval of 0 sec.
for(int i=0; i<100; i++) //to store random numbers in the array
{
array[i] = (rand()%100)+1;
cout << array[i] << endl; // to print the elements in the array.
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.