This is what I have to do:

Make an ordered array. Put a bunch of random numbers into

it.

Do 20 linear searches and 20 binary searches of that array.

(Code for linear search and binary search are found in the

book.)Print out how many elements were checked before the

item is found

I'm not looking for answers as it is homework. However I don't understand what I'm doing. This course is being held online(no other options) and that's not how I learn so I'm struggling. From my understanding I have to make a templated ordered array (which I don't understand at all) and then do searches (which I also don't understand). Any help would be appreciated

Make an ordered array. Put a bunch of random numbers into

it.

Do 20 linear searches and 20 binary searches of that array.

(Code for linear search and binary search are found in the

book.)Print out how many elements were checked before the

item is found

I'm not looking for answers as it is homework. However I don't understand what I'm doing. This course is being held online(no other options) and that's not how I learn so I'm struggling. From my understanding I have to make a templated ordered array (which I don't understand at all) and then do searches (which I also don't understand). Any help would be appreciated

Ordered array is an array where all elemets are sorted.

If you do not need array which keeps itself ordered, I suggest to use

Assigment says you should have code for linear and binary search in your book and there probably is explanation on what is it.

Wikipedia articles on subject:

http://en.wikipedia.org/wiki/Linear_search

http://en.wikipedia.org/wiki/Binary_search

In standard C++ library linear search are often but not always implemented in std::find: http://www.cplusplus.com/reference/algorithm/find/ and binary one in std::binary_search: http://www.cplusplus.com/reference/algorithm/binary_search/

If you do not need array which keeps itself ordered, I suggest to use

`std::vector<``int`>

, put a bunch of random numbers in it and sort it using `std::sort`

.Assigment says you should have code for linear and binary search in your book and there probably is explanation on what is it.

Wikipedia articles on subject:

http://en.wikipedia.org/wiki/Linear_search

http://en.wikipedia.org/wiki/Binary_search

In standard C++ library linear search are often but not always implemented in std::find: http://www.cplusplus.com/reference/algorithm/find/ and binary one in std::binary_search: http://www.cplusplus.com/reference/algorithm/binary_search/

Topic archived. No new replies allowed.