![]() ![]() Now merge L 1 and L’, which does 30 + 30 = 60 comparisons to form a final sorted list L of size 60. Thus total number of comparisons required to merge lists L 1, L 2 and L 3 would be 50 + 70 = 120.Īlternatively, first merging L 2 and L 3 does 20 + 10 = 30 comparisons, which creates sorted list L’ of size 30. L’ and L 3 can be merged with 60 + 10 = 70 comparisons that forms a sorted list L of size 60. ![]() If we first merge list L 1 and L 2, it does 30 + 20 = 50 comparisons and creates a new array L’ of size 50. Two way merge compares elements of two sorted lists and put them in new sorted list. At each step, the two shortest sequences are merged.Ĭonsider three sorted lists L 1, L 2 and L 3 of size 30, 20 and 10 respectively. Any two sequences can be merged at a time. Optimal Merge Pattern Problem: “Merge n sorted sequences of different lengths into one sequence while minimizing reads”. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |