max. operations?

S

Shraddha

On which of the following we cannot perform max. operations?

1. Array
2. Hash Table
3. Linked List
4. Heap
5. Bianry Tree
 
J

John Harrison

Shraddha said:
On which of the following we cannot perform max. operations?

1. Array
2. Hash Table
3. Linked List
4. Heap
5. Bianry Tree

My answer would be 'none of them'. They are all collections, so they all
have a maximum element. On some of them it will be easier to find the
maximum element than others.

But really it depends on what you mean by 'max. operations'. Perhaps you
shold explain the question a little better.

john
 
J

James Kanze

My answer would be 'none of them'. They are all collections, so they all
have a maximum element. On some of them it will be easier to find the
maximum element than others.

All of them, or none of them. They are all collections, and we
don't know what they contain. If what they contain doesn't
support ordering, max doesn't even have a meaning.
But really it depends on what you mean by 'max. operations'.

An interesting example is std::set< complex< double >, MyCmp >.
The user defines an arbitrary ordering, because std::set (a
binary tree, normally) requires one, but any relationship with
what a normal user would consider "max" is totally arbitrary.

Since this group is concerned with C++ (and not algorithms and
data structures), I suppose that the correct answer would be
that the algorithme std::max_element can be called on any
containter which provides forward iterators, provided, of
course, that either the value_type supports the operator<. or
that you provide a compatible comparison function for the
value_type. (Which is, of course, just what you said, couched
in C++'ese.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,292
Messages
2,571,494
Members
48,174
Latest member
RonnyLoren

Latest Threads

Top