×

 0 In the problem Not a Triangle , i have used c language and followed the algo : 1.Sort the array using merge sort in ascending order. 2.find the smallest index of array such that it is a[index] >a[i]+a[j] so chosen using binary search. here is the code : #include void sort(int a[] ,int start1 ,int end1 ,int start2 ,int end2)//part of merge sort { int temp[end1-start1 +1 + end2-start2+1 ]; int i=start1,j=start2,count=0; while(i<=end1 && j<=end2) { if(a[i]<=a[j]) temp[count++]=a[i++]; else temp[count++]=a[j++]; } for(;i<=end1;++i) temp[count++]=a[i]; for(;j<=end2;++j) temp[count++]=a[j]; for(i=0;ikey) end=middle-1; } return start;//this gives the index where the number > key starts as key is not present in array } int main() { int n,i,j,count; scanf("%d",&n); while(n!=0) { int a[n]; count=0; for(i=0;i

 1 Binary search wont work if you have repeated values. e.g. 6 1 2 4 4 4 4 correct ans is 4 but your code gives 3 answered 16 May '14, 19:47 4★abbas 411●8 accept rate: 28%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×3,820
×558
×11

question asked: 16 May '14, 18:28

question was seen: 816 times

last updated: 16 May '14, 19:47