CPP

CPP

Heaps has 7 Questions

What is meant by heap?

Used for fast reterival of elements
Used for organising the elements
Both a & b
None of the mentioned
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     #include 
  4.     using namespace std; 
  5.     int main ()
  6.     {
  7.         int myints[] = {2, 4, 6, 8, 10};
  8.         vector<int> v(myints, myints + 5);
  9.         make_heap (v.begin(),v.end());
  10.         cout  << v.front() << '\n'; 
  11.         return 0;
  12.     }

10
20
4
8
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     #include 
  4.     using namespace std; 
  5.     int main ()
  6.     {
  7.         int myints[] = {2, 4, 6, 8, 10};
  8.         vector<int> v(myints, myints + 5);
  9.         make_heap (v.begin(),v.end());
  10.         cout  << v.front() << '\n'; 
  11.         return 0;
  12.     }

10
20
4
8
How many types are there in binary heaps?

1
2
3
4
In what form does the STL provides heap?

queue
list
vector
priority_queue
How to protect the heap from affecting the memory?

Avoid using pointers for associating two data structures
Embed pointed child objects into the parent object
Allocate objects in chunks
All of the mentioned
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     #include 
  4.     using namespace std;
  5.     bool myfunction (int i,int j) { return (i<j); }
  6.     int main () 
  7.     {
  8.         int myints[] = {9, 8, 7, 6, 5};
  9.         vector<int> myvector (myints, myints + 5);
  10.         partial_sort (myvector.begin(), myvector.begin() + 3, myvector.end());
  11.         partial_sort (myvector.begin(), myvector.begin() + 2, myvector.end(), 
  12.         myfunction);
  13.         for (vector<int> :: iterator it = myvector.begin(); it != myvector.end(); ++it)
  14.             cout << ' ' << *it;
  15.         return 0;
  16.     }

5 6 7
5 6 7 9 8
9 8 7 6 5
None of the mentioned