answersLogoWhite

0


Best Answer

#include<iostream.h> #include<conio.h> void main() { clrscr(); int i,k,a[10],c[10],n,l; cout<<"Enter the no. of elements\t"; cin>>n; cout<<"\nEnter the sorted elments for optimal merge pattern"; for(i=0;i<n;i++) { cout<<"\t"; cin>>a[i]; } i=0;k=0; c[k]=a[i]+a[i+1]; i=2; while(i<n) { k++; if((c[k-1]+a[i])<=(a[i]+a[i+1])) { c[k]=c[k-1]+a[i]; } else { c[k]=a[i]+a[i+1]; i=i+2; while(i<n) { k++; if((c[k-1]+a[i])<=(c[k-2]+a[i])) { c[k]=c[k-1]+a[i]; } else { c[k]=c[k-2]+a[i]; }i++; } }i++; } k++; c[k]=c[k-1]+c[k-2]; cout<<"\n\nThe optimal sum are as follows......\n\n"; for(k=0;k<n-1;k++) { cout<<c[k]<<"\t"; } l=0; for(k=0;k<n-1;k++) { l=l+c[k]; } cout<<"\n\n The external path length is ......"<<l; getch(); }

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

rite aprogram for optimal merge pattern.#include<iostream.h>#include<conio.h>void main(){clrscr();int i,k,a[10],c[10],n,l;cout<<"Enter the no. of elements\t";cin>>n;cout<<"\nEnter the sorted elments for optimal merge pattern";for(i=0;i<n;i++){cout<<"\t";cin>>a[i];}i=0;k=0;c[k]=a[i]+a[i+1];i=2;while(i<n){k++;if((c[k-1]+a[i])<=(a[i]+a[i+1])){c[k]=c[k-1]+a[i];}else{c[k]=a[i]+a[i+1];i=i+2;while(i<n)

{ k++;if((c[k-1]+a[i])<=(c[k-2]+a[i])){c[k]=c[k-1]+a[i];}else{c[k]=c[k-2]+a[i];}i++;}}i++;}k++;c[k]=c[k-1]+c[k-2];cout<<"\n\nThe optimal sum are as follows......\n\n";for(k=0;k<n-1;k++){cout<<c[k]<<"\t";}l=0;for(k=0;k<n-1;k++){l=l+c[k];}cout<<"\n\n The external path length is ......"<<l;getch();}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C program for optimal merge pattern?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How to write aC program to merge two singly linked list?

write a c program to circular queue


How Can you Merge an empty unallocated partition to your C Drive?

You need a program like partition magic, it will format and merge the partition. If you want to reinstall your operating system, you can format all of the partitions into one before installing the system.


How do you merge 2 Visual C programs to get a single output?

You cannot. A C program can only have one global main function but you'd be trying to compile a program that has two main functions. The only way to merge the two programs is to modularise both programs so that neither is dependent upon their main functions. Once modularised, you can include those modules in any program. Alternatively, you can create binary libraries from the modules and link them into any program.


The easy logic of Merge sort in C?

Top down merge sort is the easy way of merge sort in C language . It is used to derived o(n log n) algorithm . This is in par with the other methods.


Is the optimal pH of tryspin acidic or basic?

Basic. Trypsins have an optimal operating pH of about 8(and optimal operating temperature of about 37&deg;C)


C program was introduced in the year?

c program was introduced in the year 1972 by Dennis RitchieNo, it was the C language, not the C program.


Features of c program?

the features of a C program


What is executive a c program?

I think it is 'execution of a C program'.


C program on left factoring in compiler design?

how to create a c program for left factoring.


Different types of sorting techniques in c language?

types of sorting in c language are: insertion sort selection sort bubble sort merge sort two way merge sort heap sort quick sort


Different parts of c language program?

what are the parts of C language program


Program for sin series in c language?

find the program in c-pgms.blogspot.com