answersLogoWhite

0


Best Answer

#include<iostream>

#include<iomanip>

#include<vector>

#include<algorithm>

#include<random>

#include<time.h>

void initialise (std::vector<unsigned>& data)

{

// Pseudo-random number generator (range: 1 to 99).

std::default_random_engine generator;

generator.seed ((unsigned) time (NULL));

std::uniform_int_distribution<unsigned> distribution (1, 99);

data.clear();

unsigned max_elements(50);

while (max_elements--)

data.push_back (distribution (generator));

}

int linear_search(std::vector<unsigned>& data, unsigned value, unsigned& comparisons)

{

int index(-1);

for( comparisons=0; comparisons<data.size() && index<0; ++comparisons)

if (data[comparisons] -1)

{

std::cout << "not found. ";

}

else

{

std::cout << "found at index " << binary_index << ". ";

}

std::cout << "Comparisons: " << binary_comparisons << std::endl;

}

}

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Program to perform binary search operations using dynamic memory allocation?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering
Related questions

How to overload the new and delete operators to provide custom dynamic allocation of memory?

You don't. Remember that C++ is a superset of the C language. You can still use the old malloc/free functions to perform your own memory allocation/deletion.


What is a list of instructions that cause the central processing unit to perform operations to complete a task?

Program


What is to perform the indicated operations?

It means to Simplify


What is emm server in veritas netbackup?

Enterprise Media Manager (EMM) server is a centralized data sore and group of services that perform the management and allocation of resources required for all the NetBackup operations.


What are the functions of the ALU?

to perform arthmatic and logical operations


Is that ture A data file contains instructions for a computer on how to perform a specific task?

This would be true. A data file is a file that contains the data which controls the operations of a program or task, which is the instructions for how to perform the task or run the program.


What are the primary arithmetic operations a computer program can perform?

The four primary arithmetic operations a computer program can perform are addition, subtraction, multiplication and division.2 + 3 = 5 is an example of addition9 - 7 = 7 is an example of subtraction2 x 3 = 6 is an example of multiplication10 / 2 = 5 is an example of division


What is difference between Static analysis and Dynamic analysis?

Static analysis can be seen as a stricter check of syntax made by an advanced compiler (that will not produce binary code but error messages). Dynamic analysis is a specific analysis done when the program is actually running. Thins kind of analysis, being done at runtime, can detect specific behaviors, like accessing deallocated memory, leaking memory, time spent in functions and so on. To put it roughly, is static analysis is advanced compilation, dynamic analysis is a particular form of testing that often requires your program to be "instrumented" for it (i.e., modified at the binary level). In Xcode, dynamic analysis is available through Instruments. You can found more information about it by googling for "xcode instruments tutorial". In short, you can run your program under dynamic analysis choosing "Running with Performance Tool" and choosing the kind of analysis you want to perform (memory leaks, memory allocation, performance, zombies, etc.). Instruments will show you in a graphical environment how memory usage evolves, or how long it takes for specific functions to perform, etc.


_________, also called a program, tells the computer what tasks to perform and how to perform them?

program


Is CU is responsible for decision making IN COMPUTER?

CU is not responsible for decision making, It is only responsible for how fast the computation is performed. For decision making need logical operations and for that we've some software program which perform logical operations which does decision making.


What is the difference between hql and criteria?

HQL is to perform both select and non-select operations on data, but Criteria is only for selecting data, we can't perform non-select operations using criteria.HQL is suitable for executing static queries, where as Criteria is suitable for dynamic queries.HQL doesn't support pagination concept, but we can achieve pagination with Criteria.Criteria used to take more time to execute than HQL.With Criteria we are safe with SQL injection, because of its dynamic query operation, but in HQL as your queries are either fixed or parametrized , there is no safe for SQL injection.


Why do you have to use order of operations for every problem?

Because if you perform the operations in a different order your answer will be wrong.