Work in HR or Recruiting?
Salesforce.com
3.8 of 5 541 reviews
www.salesforce.com San Francisco, CA 5000+ Employees

93 interview experiences Back to all Salesforce.com Interview Questions & Reviews

Interview Question for Software QA Engineer Intern at Salesforce.com:
Apr 13, 2012

Was asked to program quick-sort in Java.


Tags: java, sorting algorithm
Add Tags [?]

See more for this Salesforce.com Software QA Engineer Intern Interview

Helpful Question?  
Yes | No
Inappropriate?

Answers & Comments (1)

Jul 10, 2012

by Jigargosha:

void QuickSort(int[] arr, int low, int high)
 {
     while (low < high)
     {
         int pivot = (low+high)/2;
         int partition = Partition(arr, low, high, pivot);
         QuickSort(arr, low, partition);
         QuickSort(arr, partition+1, high);
     }
 }

 void Partition(int[] arr, int low, int high, int pivot)
 {
     // take pivot element to end
     swap(arr[pivot], arr[high]);

     int pivotElement = arr[high];
     int finalPosition = 0;

     for (int i = low; i < high - 1; ++i)
     {
         if (arr[i] < pivotElement)
         {
             swap(arr[i],arr[finalPosition]);
             finalPosition++;
         }
     }

     // put pivot element in its "final position"
     swap(arr[finalPosition],arr[high-1]);
 }
Helpful Answer?  
Yes | No
Inappropriate?

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords, helping to categorise interview questions that have something in common.