Microsoft Interview Question Software Engineer / Developers

  • microsoft-interview-questions
    0
    of 0 votes
    5
    Answers

    Onsite interview: Given sorted doubly linked list, write code to insert and delete elements from the list..

    - Anonymous on January 24, 2011 Report Duplicate | Flag
    Microsoft Software Engineer / Developer Algorithm



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 on 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 on 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 on 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 on 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 on July 09, 2011 | Flag Reply


Add a Comment
Name:

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

Books

is a comprehensive book walking you through every aspect of getting a job at a top tech company, while focuses on software engineering interviews.

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