You are here:

C++/few programming questions

Advertisement


Question
Good day,

Been trying to get better in programming data structures and have came to a point where i got some questions on which i would be greatful to get answers.

1. Why the binary search cant be used in an unsorted array?
2. why a priority queue has to be oredered after adding the new element?
3. why random acces is not possible in a list?
4. What is a difference between stack and deque?
5. Which of these structures are linear: an array, a multiply linked list or a queue?
6. How many values can have a boolean variable?

Answer
> 1. Why the binary search cant be used in an unsorted array?

Because it is a dichotomic search algorithm.
http://en.wikipedia.org/wiki/Dichotomic_search
http://en.wikipedia.org/wiki/Binary_search

> 2. why a priority queue has to be oredered after adding the new element?
It is typically implemented as a binary heap.
See: http://en.wikipedia.org/wiki/Binary_heap

> 3. why random acces is not possible in a list?

In a list, given the position of an item, its address cannot be computed in constant time.


> 4. What is a difference between stack and deque?

In a stack, insertion and deletions (push and pop) take place at only one end.
In a deque (double ended queue), insertion and deletions (push_back, push_front, pop_back and pop_front) can take place at both ends.

> 5. Which of these structures are linear: an array, a multiply linked list or a queue?

Obviously an array. A multiply linked list, if it is a doubly linked list.

> 6. How many values can have a boolean variable?

By definition, two. Either true or false.  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


vijayan

Expertise

my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.

Experience

about 15 years or so

Education/Credentials
post graduate engineer

©2016 About.com. All rights reserved.