KEMBAR78
Implementing Merge Sort | PPTX
IMPLEMENTING MERGE-SORT
OUTLINE
īą INTRODUCTION
īą Divide & Conquer approach
īą Illustration
īą LITERATURE REVIEW
īą PROBLEM STATEMENT
īą CONCLUSION
īą REFERENCES
2
INTRODUCTION
3
 Merge Sort:
īŽ "Break the data to sort in half, sort each half separately using
merge sort, and merge the halves back together into a single
sorted list."
īŽ It employs a common algorithmic paradigm based on
recursion, i.e. divide-and-conquer paradigm.
īŽ Divide-and-conquer algorithm works in three steps:
īŽ Divide
īŽ Conquer
īŽ Combine
DIVIDE & CONQUER APPROACH
4
Fig. 1: Divide & Conquer view of one
step[3]
Here's how to view one step, assuming that each divide step
creates two subproblems:
ILLUSTRATION
5
Here is a diagrammatic example for how merge sort works:
Fig. 2: Merge Sort Working[5]
LITERATURE-REVIEW
6
LITERATURE-REVIEW(1/2)
7
 Title: ” Formal Model Merging Applied to Class
Diagram Integration”[1]
Authors: Artur Boronat, Jose A. C., Isidro Ramos, Patrico Letelier
 Objective: The deīŦnition of Merge operator is applied on class
diagrams integration to present an automated approach for
generic model merging providing support for conīŦ‚ict
resolution and traceability between software artifacts.
Keywords: Model-Driven Engineering, Model Management, model
merging, conīŦ‚ict resolution.
LITERATURE-REVIEW(1/2 Cont..)
8
 Introduction:
 Models are the main assets in the software
development process.
 Models collect the information that describes the
information system at a high abstraction level, which
permits the development of the application in an
automated way.
 In this process, models constitute software artifacts
that experience reīŦnements from the problem space to
the solution space.
CASE STUDY
9
 Use Case Analysis using Partial Class
Diagrams:
 Case Study - To illustrate how Merge operator can be
used eīŦ€ectively to deal with the required needs like
inconsistencies or conīŦ‚icts among partial models
which often arises, etc.
 Here, part of a system for managing submissions that
are received in a conference is presented.
 In this example, the focus is on the fragment of the
Use-Case Model (Fig. 3).
USE CASE MODEL
10
Software development methodologies based on UML propose an approach where
the process is Use Case Driven, which means that all artifacts have traceability
links from Use Cases (The artifacts are reīŦned through several transformation
steps).
The Use Case Model must sacriīŦce precision to facilitate readability and
validation. So, the analysis of use cases is mainly a manual activity.
Fig. 3: Use Case Model[1]
GENERIC SEMANTICS
11
 Merge Operator:
 The Merge operator takes two models as input and
produces a third one.
 If A and B are models in a speciīŦc meta-model
algebraic speciīŦcation, the application of the Merge
operator on them produces a model C, which consists
the union of A and B.
 Taking into account that duplicates are not allowed in a
model, the union is disjoint.
LITERATURE-REVIEW(1/2 Cont..)
12
 Semantics of the Merge operator needs to introduce three
concepts:
 The equivalence relation;
 The conīŦ‚ict resolution strategy;
 The refreshment of a construct.
UML CASE tools permit the arrangement of Use Cases and their
corresponding partial Class Diagram into the same package, i.e. no option
is provided to obtain the global Class Diagram from the partial ones.
The Rational Rose Model Integration tool provides an ad-hoc solution to
merge UML models.
Once the merged model is generated, there is no way to relate the
obtained model to the partial source models in order to keep some degree
of traceability.
LITERATURE-REVIEW(2/2)
13
 Title: “Heuristic and pattern based Merge Sort”[2]
Author: Manouchehr Zadahmaf jafarlou, Parisa Yousefzadeh fard
 Objective: The aim of this study is to present a stable and
adaptable Merge Sort algorithm that uses the design
patterns to reduce computational complexity of swaps and
memory usage.
 Keywords: Merge sort, Design patterns, computational complexity.
LITERATURE-REVIEW(2/2 Cont..)
14
 Introduction:
 Although many consider that sorting algorithm is a solved
problem, useful new sorting algorithms are still being
invented (for example, library sort was first published in
2004).
 Sorting algorithms are prevalent in introductory computer
science classes, where the abundance of algorithms for the
problem provides a gentle introduction to a variety of core
algorithm concepts, such as big O notation, divide and
conquer algorithms, data structures, best, worst and average
case analysis, etc.
15
 Sorting algorithms used in computer science are often
classified as:
īŽ Computational complexity.
īŽ Memory usage.
īŽ Recursion.
īŽ Stability: stable sorting algorithms maintain the relative order of
records with equal values.
īŽ Whether or not they are a comparison sort. A comparison sort
examines the data only by comparing two elements with a
comparison operator.
īŽ General method: insertion, exchange, selection, merging, etc.
īŽ Adaptability: Whether or not the pre sorted-ness of the input
affects the running time.
CLASSIFICATION
LITERATURE-REVIEW(2/2 Cont..)
16
 Heuristic and pattern based Merge Sort implementation:
Fig. 4. Heuristic and pattern based Merge Sort implementation[2]
LITERATURE-REVIEW(2/2 Cont..)
17
 First algorithm:
 First element of status is the index of first element of next partial
array and the second one represent "the number of elements of
partial array“ (+1) for ascending partial array or (-1) for
descending partial array.
 Used when the numbers of arrays are so many that cannot move
to volatile memory.
 Ex.: Given array -4, -3, 0, 1, 3, 8, 9, 14, 5, 6, 8, 14, 2, 1, -3, 1 ..
īŽ if the (-4, -3, 0, 1, 3, 8, 9, 14) be the part of array that sorted
before with stMS, (5, 6, 8, 14) will be the next partial ordered
array and so the status array is (8, +4).
LITERATURE-REVIEW(2/2 Cont..)
18
 Second algorithm:
 “The first index of first entry of partial arrays" (+1) for
ascending arrays and "the first index of first entry of partial
arrays" (-1) for descending arrays.
 Causes a high performance by eliminating of first steps of merge
sort algorithm.
 For example for array -8, -4, 0, 4, 3, 1, 0, -2, 5, 7, 9, 10, 5, 4, 2,
1, 3
īŽ For status: +1, -4, +8, -12, +15; Partial arrays are indexed as 0->3
(ascending), 4->7 (descending), 8->11 (ascending), 12->14
(descending), 15->15 (ascending). Then status send as argument
to stgMS and partial arrays will be the building blocks for stgM
algorithm.
LITERATURE-REVIEW(2/2 Cont..)
19
 Third algorithm:
 “The number of partial arrays " (+1) for ascending arrays
and "the number of partial arrays" (-1) for descending
arrays.
 Here, stgMS is a Huffman coding algorithm used to Optimize the
merging process by choosing two partial arrays, that sum of
elements of them is less than others before each merging.
 Then these two partial arrays send as argument to stgM
algorithm and merged.
PROBLEM STATEMENT
20
 When the Use Case Model has many use cases,
managing traceability between each use case and the
corresponding elements in the resulting class diagram
can be a diīŦƒcult task.
 Regarding traceability, this strategy is a sensible
solution, but when several team members work in
parallel with diīŦ€erent use cases, inconsistencies or
conīŦ‚icts among partial models often arise, which must
be solved when obtaining the integrated model.
CONCLUSION
21
 Merge sort is an appropriate algorithm with O(nlgn)
Computational complexity, but petitioning of array to one
element partial arrays and then merging them cause
increasing complexity in time order, system software and
hardware work.
 The presented algorithm eliminates these extra work using
patterns.
REFERENCES
22
1. Artur Boronat, Jose A. C., Isidro Ramos, Patrico Letelier,” Formal Model Merging
Applied to Class Diagram Integration”, © 2006-Elsevier.
2. Manouchehr Zadahmaf jafarlou, Parisa Yousefzadeh fard,” Heuristic and pattern
based Merge Sort”, © 2010-Elsevier.
3. https://www.khanacademy.org/computing/computer-science/algorithms/merge-
sort/a/divide-and-conquer-algorithms [09/12/2015, 22:33]
4. http://computationaltales.blogspot.in/2011/10/merge-sort-and-lines-of-
kindergarteners.html [09/12/2015, 22:13]
5. http://coding-geek.com/how-databases-work/ [09/12/2015, 22:28]

Implementing Merge Sort

  • 1.
  • 2.
    OUTLINE īą INTRODUCTION īą Divide& Conquer approach īą Illustration īą LITERATURE REVIEW īą PROBLEM STATEMENT īą CONCLUSION īą REFERENCES 2
  • 3.
    INTRODUCTION 3  Merge Sort: īŽ"Break the data to sort in half, sort each half separately using merge sort, and merge the halves back together into a single sorted list." īŽ It employs a common algorithmic paradigm based on recursion, i.e. divide-and-conquer paradigm. īŽ Divide-and-conquer algorithm works in three steps: īŽ Divide īŽ Conquer īŽ Combine
  • 4.
    DIVIDE & CONQUERAPPROACH 4 Fig. 1: Divide & Conquer view of one step[3] Here's how to view one step, assuming that each divide step creates two subproblems:
  • 5.
    ILLUSTRATION 5 Here is adiagrammatic example for how merge sort works: Fig. 2: Merge Sort Working[5]
  • 6.
  • 7.
    LITERATURE-REVIEW(1/2) 7  Title: ”Formal Model Merging Applied to Class Diagram Integration”[1] Authors: Artur Boronat, Jose A. C., Isidro Ramos, Patrico Letelier  Objective: The deīŦnition of Merge operator is applied on class diagrams integration to present an automated approach for generic model merging providing support for conīŦ‚ict resolution and traceability between software artifacts. Keywords: Model-Driven Engineering, Model Management, model merging, conīŦ‚ict resolution.
  • 8.
    LITERATURE-REVIEW(1/2 Cont..) 8  Introduction: Models are the main assets in the software development process.  Models collect the information that describes the information system at a high abstraction level, which permits the development of the application in an automated way.  In this process, models constitute software artifacts that experience reīŦnements from the problem space to the solution space.
  • 9.
    CASE STUDY 9  UseCase Analysis using Partial Class Diagrams:  Case Study - To illustrate how Merge operator can be used eīŦ€ectively to deal with the required needs like inconsistencies or conīŦ‚icts among partial models which often arises, etc.  Here, part of a system for managing submissions that are received in a conference is presented.  In this example, the focus is on the fragment of the Use-Case Model (Fig. 3).
  • 10.
    USE CASE MODEL 10 Softwaredevelopment methodologies based on UML propose an approach where the process is Use Case Driven, which means that all artifacts have traceability links from Use Cases (The artifacts are reīŦned through several transformation steps). The Use Case Model must sacriīŦce precision to facilitate readability and validation. So, the analysis of use cases is mainly a manual activity. Fig. 3: Use Case Model[1]
  • 11.
    GENERIC SEMANTICS 11  MergeOperator:  The Merge operator takes two models as input and produces a third one.  If A and B are models in a speciīŦc meta-model algebraic speciīŦcation, the application of the Merge operator on them produces a model C, which consists the union of A and B.  Taking into account that duplicates are not allowed in a model, the union is disjoint.
  • 12.
    LITERATURE-REVIEW(1/2 Cont..) 12  Semanticsof the Merge operator needs to introduce three concepts:  The equivalence relation;  The conīŦ‚ict resolution strategy;  The refreshment of a construct. UML CASE tools permit the arrangement of Use Cases and their corresponding partial Class Diagram into the same package, i.e. no option is provided to obtain the global Class Diagram from the partial ones. The Rational Rose Model Integration tool provides an ad-hoc solution to merge UML models. Once the merged model is generated, there is no way to relate the obtained model to the partial source models in order to keep some degree of traceability.
  • 13.
    LITERATURE-REVIEW(2/2) 13  Title: “Heuristicand pattern based Merge Sort”[2] Author: Manouchehr Zadahmaf jafarlou, Parisa Yousefzadeh fard  Objective: The aim of this study is to present a stable and adaptable Merge Sort algorithm that uses the design patterns to reduce computational complexity of swaps and memory usage.  Keywords: Merge sort, Design patterns, computational complexity.
  • 14.
    LITERATURE-REVIEW(2/2 Cont..) 14  Introduction: Although many consider that sorting algorithm is a solved problem, useful new sorting algorithms are still being invented (for example, library sort was first published in 2004).  Sorting algorithms are prevalent in introductory computer science classes, where the abundance of algorithms for the problem provides a gentle introduction to a variety of core algorithm concepts, such as big O notation, divide and conquer algorithms, data structures, best, worst and average case analysis, etc.
  • 15.
    15  Sorting algorithmsused in computer science are often classified as: īŽ Computational complexity. īŽ Memory usage. īŽ Recursion. īŽ Stability: stable sorting algorithms maintain the relative order of records with equal values. īŽ Whether or not they are a comparison sort. A comparison sort examines the data only by comparing two elements with a comparison operator. īŽ General method: insertion, exchange, selection, merging, etc. īŽ Adaptability: Whether or not the pre sorted-ness of the input affects the running time. CLASSIFICATION
  • 16.
    LITERATURE-REVIEW(2/2 Cont..) 16  Heuristicand pattern based Merge Sort implementation: Fig. 4. Heuristic and pattern based Merge Sort implementation[2]
  • 17.
    LITERATURE-REVIEW(2/2 Cont..) 17  Firstalgorithm:  First element of status is the index of first element of next partial array and the second one represent "the number of elements of partial array“ (+1) for ascending partial array or (-1) for descending partial array.  Used when the numbers of arrays are so many that cannot move to volatile memory.  Ex.: Given array -4, -3, 0, 1, 3, 8, 9, 14, 5, 6, 8, 14, 2, 1, -3, 1 .. īŽ if the (-4, -3, 0, 1, 3, 8, 9, 14) be the part of array that sorted before with stMS, (5, 6, 8, 14) will be the next partial ordered array and so the status array is (8, +4).
  • 18.
    LITERATURE-REVIEW(2/2 Cont..) 18  Secondalgorithm:  “The first index of first entry of partial arrays" (+1) for ascending arrays and "the first index of first entry of partial arrays" (-1) for descending arrays.  Causes a high performance by eliminating of first steps of merge sort algorithm.  For example for array -8, -4, 0, 4, 3, 1, 0, -2, 5, 7, 9, 10, 5, 4, 2, 1, 3 īŽ For status: +1, -4, +8, -12, +15; Partial arrays are indexed as 0->3 (ascending), 4->7 (descending), 8->11 (ascending), 12->14 (descending), 15->15 (ascending). Then status send as argument to stgMS and partial arrays will be the building blocks for stgM algorithm.
  • 19.
    LITERATURE-REVIEW(2/2 Cont..) 19  Thirdalgorithm:  “The number of partial arrays " (+1) for ascending arrays and "the number of partial arrays" (-1) for descending arrays.  Here, stgMS is a Huffman coding algorithm used to Optimize the merging process by choosing two partial arrays, that sum of elements of them is less than others before each merging.  Then these two partial arrays send as argument to stgM algorithm and merged.
  • 20.
    PROBLEM STATEMENT 20  Whenthe Use Case Model has many use cases, managing traceability between each use case and the corresponding elements in the resulting class diagram can be a diīŦƒcult task.  Regarding traceability, this strategy is a sensible solution, but when several team members work in parallel with diīŦ€erent use cases, inconsistencies or conīŦ‚icts among partial models often arise, which must be solved when obtaining the integrated model.
  • 21.
    CONCLUSION 21  Merge sortis an appropriate algorithm with O(nlgn) Computational complexity, but petitioning of array to one element partial arrays and then merging them cause increasing complexity in time order, system software and hardware work.  The presented algorithm eliminates these extra work using patterns.
  • 22.
    REFERENCES 22 1. Artur Boronat,Jose A. C., Isidro Ramos, Patrico Letelier,” Formal Model Merging Applied to Class Diagram Integration”, © 2006-Elsevier. 2. Manouchehr Zadahmaf jafarlou, Parisa Yousefzadeh fard,” Heuristic and pattern based Merge Sort”, © 2010-Elsevier. 3. https://www.khanacademy.org/computing/computer-science/algorithms/merge- sort/a/divide-and-conquer-algorithms [09/12/2015, 22:33] 4. http://computationaltales.blogspot.in/2011/10/merge-sort-and-lines-of- kindergarteners.html [09/12/2015, 22:13] 5. http://coding-geek.com/how-databases-work/ [09/12/2015, 22:28]