4.0

4.0 | 1 rating Rate this file 113 downloads (last 30 days) File Size: 2.62 KB File ID: #8097

Merge two sorted vectors into a sorted vector

by Dr. Murtaza Khan

 

25 Jul 2005 (Updated 09 Jul 2009)

Code covered by BSD License  

Merge two sorted vectors 'a' and 'b' into a sorted vector 'c'

Download Now | Watch this File

File Information
Description

mergesorted.m
------------------
If we have two individually sorted vectors "a" and "b" but they are not sorted with respect to each other and we want to merge them into vector "c" such that "c" is also a sorted vector. Then c=mergesorted(a,b) can be used.

This function most likely make difference for very large vectors (may be elements in million). On P-4 machine when length of "a" is 2 million and length of "b" is 2.5 million then c=mergesorted(a,b) is around 3 times faster than using MATLAB builtin function c=sort([a,b]).

testmergesorted.m
----------------------
A simple test program to that test "mergesorted" and builtin "sort" function and compare their performance.

MATLAB release MATLAB 7.0.1 (R14SP1)
Zip File Content  
Other Files license.txt,
mergesortedvectors/mergesorted.m,
mergesortedvectors/readme.txt,
mergesortedvectors/testmergesorted.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
02 Nov 2007 Jhonty R.

very helpful to implement Merge-Sort algorithm

Please login to add a comment or rating.
Updates
09 Jul 2009

BSD License

Tag Activity for this File
Tag Applied By Date/Time
merge Dr. Murtaza Khan 22 Oct 2008 07:54:04
sorted Dr. Murtaza Khan 22 Oct 2008 07:54:04
vectors Dr. Murtaza Khan 22 Oct 2008 07:54:04
mathematics Dr. Murtaza Khan 22 Oct 2008 07:54:04
general Dr. Murtaza Khan 22 Oct 2008 07:54:04
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com