Question

In: Computer Science

Question 2 Indicate six key differences between a deque and a vector. When should you choose...

Question 2
Indicate six key differences between a deque and a vector. When should you choose one over the other? Explain how a deque works internally by providing a thorough explanation of how the item insertion happens.

Solutions

Expert Solution

Deque and Vector

The Deque is the double ended queues which contain expansion and contraction on both the ends.

It is similar to vectors but are more efficient in case insertion and deletion elements. It provides operation for insertion at front, middle and end. It performs push_front() and pop_front() operation to add and delete element from front.

Vectors are same as dynamic arrays and it has the ability the resize its size when the element is inserted or deleted. And in vectors the insertion takes place in the end. And the insertion and deletion takes place at the middle and end part only. It performs good performance while doing the insertion and deletion at the end part. But in case of insertion and deletion at the middle performs bad.

The key difference between Deque and Vector are:

Vector.

1. It provides insertion and deletion at the middle and end

2. Bad performance while doing insertion and deletion at the front.

3. Store elements contiguously.

4. Good performance for addition and deletion at the end.

5. It performs push_back() and pop_back() operation.

6. No iteration invalidation happends

Deque.

1. It provides insertion and deletion at the front, middle and end.

2. Good performance for insertion and deletion at the front.

3. While storing the elements contiguously, it contains a list of memory chunks.

4. Poor performance for insertion and deletion at the end.

5. It performs push_front() and pop_fornt() operation

6. Iteration invalidation happens.

We can choose deque over vector, if we want to add or delete the elements from the ends like we are implementing a Queue.

In the similar way, we can choose vector over deque that is we can insert or delete the elements are performed at the end like implementing the Stack.

Insertion in Deque.

For inserting an element we can use

deque insert()

By using this function we can insert the element at a specified position. That is the insertion can be done in desired position where the user want to fix the element.

And also we can insert N number of elements to this position.

It is also used the specified range of elements.

For example, if we enter the input range as

12345

Then the output must shows like:

112345

In this first we want to declare the deque after declaring it we want to print the deque. Then we want to print the declare insert() function.


Related Solutions

Indicate six key differences between a deque and a vector. in C++
Indicate six key differences between a deque and a vector. in C++
When should you choose a deque over a vector and a vector over a deque in...
When should you choose a deque over a vector and a vector over a deque in c++
1. Describe the differences between the six classifications of pressure injuries. 2. How do you explain...
1. Describe the differences between the six classifications of pressure injuries. 2. How do you explain the fact that eschar must be removed before an injury can be accurately staged? 3. You are assigned to care for a 74-year-old male patient with a stage 3 pressure injury on his coccyx that is infected with methicillin-resistant Staphylococcus aureus (MRSA). You will need to irrigate the injury and apply a wet-to-damp dressing. You will also need to take the proper transmission-based precautions...
What are the key leadership skills a manager should have? Choose a CEO that you perceive...
What are the key leadership skills a manager should have? Choose a CEO that you perceive as being a leader. Describe his leadership style and how it is impacting the success of his company. What are the drivers of globalization? Describe the major changes for businesses.
question 1 If you were to choose on emphasizing on one of the three key dimensions...
question 1 If you were to choose on emphasizing on one of the three key dimensions to a project, which one would you choose to have more of and why?
Between long straddle and long strangle, which one should a trader choose when there is a...
Between long straddle and long strangle, which one should a trader choose when there is a volatility market?
What are the key differences in gametogenesis between females and males? What is the key step...
What are the key differences in gametogenesis between females and males? What is the key step in spermatogenesis that allows for unlimited sperm production? This step is not present in oogenesis and therefore only a finite number of eggs could be produced. (0-5pts) Guidelines: You must include in your answer how the processes are similar and how they differ. What would health implications have the finite number of eggs present to the female? What organs are responsible for each gametogenesis?...
the question should be done on Matlab. There is a vector defined as H = [-88,...
the question should be done on Matlab. There is a vector defined as H = [-88, 45, 75, 24, 14, 19, -11, 9, -5, -3, 12, 19 ,56, -4, 5, 17, -6, -8, -9, 6, 15] Write a program as a script file that triples the elements that are positive and a divisible by 3 or 5, and, raises to the power of 2 the elements that are negative but greater than -11.
Question 2. Required: (a) If you could choose between a €100,000 non-refundable grant from a public...
Question 2. Required: (a) If you could choose between a €100,000 non-refundable grant from a public authority and a €25,000 investment in exchange for equity from a serial entrepreneur (smart money), which one would you choose? Please give reasons for your answer.                                                                                          (b) Describe the key features of the ‘virtuous cycle of a venture capital fund’. (c) Investors in start-ups need to know what is going on in the companies they invest in. Explain why key metrics are needed...
Differences Between Linux and Windows Operating Systems Two key differences between a Linux operating system and...
Differences Between Linux and Windows Operating Systems Two key differences between a Linux operating system and a Windows operating system are the concepts of “mounting” and “drive” letters. Provide an example for each. Why is it important to plan disk partitioning before installing Linux? Discuss the advantages of disk partitioning. Also discuss what logical volume management (LVM) is and why or why you might use it.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT