4.0

4.0 | 1 rating Rate this file 13 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)

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

| 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)
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
general Dr. Murtaza Khan 22 Oct 2008 07:54:04
mathematics Dr. Murtaza Khan 22 Oct 2008 07:54:04
merge Sören Sieberling 27 Sep 2010 09:08:40

Contact us at files@mathworks.com