Microsoft Interview Question for Software Engineer / Developers






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

node* insert(node* ptr,int x)
{
node* ptr1=ptr,ptr2=NULL;
ptr2=(node*)malloc(sizeof(node));
if(ptr!=NULL)
{
while(ptr!=NULL && ptr->data >= x)
{
ptr1=ptr;
ptr=ptr->next;
}
if(ptr!=NULL)
{
ptr->left->right=ptr2;
ptr2->right=ptr;
ptr->left=ptr2;
}
else
{
ptr1->right=ptr2;
ptr2->left=ptr1;
ptr2->right=NULL;
}
}
else
{
ptr2->data=x;
ptr2->left=NULL;
ptr2->right=NULL;
}
}

- Anonymous January 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Pure insertion sort, Like binary search, go to the middle of the selected set everytime and see if the number is greater .. then, once you find the smallest.. traverse from there and insert it...

Deletion is also same !!

- Anonymous January 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

well, going to the middle would take traversing n/2 elements because this is a doubly linked list not an array. so the complexity with this algo would be = n/2 + n/4 + n/8.... + n/n ==> O(n) for searching and O(1) for inserting.
Instead, why not just traverse through the array?
the complexity = O(position_Of_New_Element)

- GekkoGordan January 28, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

-> Obtain a pointer to the begin, middle and end of the double linked list and store it.
-> For every new element to be inserted, 
     check if it is less than middle element or not {O(1)}
     traverse to the left or right based on the comparison {O(n/2)}
-> worst case complexity: O(n/2)
        space complexity: O(1)

- GekkoGordan January 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

node * RecInsertDLL(p, prev, num)
{
if(p == null || p->value > num)
{
x = new node;
x->prev = prev;
x->next = p;
x->value = num;
return x;
}

x->next = RIDLL(p->next, p);
return p;
}

- WellSaid July 09, 2011 | 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