Igate Interview Question for Technical Architects


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
1
of 1 vote

Both vectors and deques provide a very similar interface and can be used for similar purposes, but internally both work in quite different ways: While vectors are very similar to a plain array that grows by reallocating all of its elements in a unique block when its capacity is exhausted, the elements of a deques can be divided in several chunks of storage, with the class keeping all this information and providing a uniform access to the elements. Therefore, deques are a little more complex internally, but this generally allows them to grow more efficiently than the vectors with their capacity managed automatically, specially in large sequences, because massive reallocations are avoided.

So deques can be preferred over vector when the estimated size of data is not clearly known and much reallocation is expected.

When an element is inserted into a deque there is a check for available space for the new entry. If no space is available a chunk of memory is allocated and linking information is added to deque class.

- romilshah29 July 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@eugene: Correct, i dont know the "exact" internal implementation of deque but i see it is a class with number of dynamically allocated memory chunks and information about how these chunks are linked. Having said that, I believe the information I shared does answer the 3 questions asked.

- Anonymous July 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Deque is double ended so you can efficiently add to both ends. Vector can be added only added to at the back. Deque also has a shrink to fit functionality which reduces the size of deque when a "page" is not required anymore. Vector can not reclaim space on deletions.

- Anonymous August 04, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Deque would be implemented with linked list, insertion and deletion in deque is same as link list, whereas vectors are just array(no links, efficient), expansion happens by realloc+memcopy.

- Sakthi August 05, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More