Arrays Bubble Sort Merge Sort - PowerPoint PPT Presentation

1 / 160
About This Presentation
Title:

Arrays Bubble Sort Merge Sort

Description:

Arrays are a little surprising (at first) in Java. Arrays ... Constructions like this are allowed. Box[] ba2={new Box(1,2), new Box(3,4), new Box(2,1) ... – PowerPoint PPT presentation

Number of Views:72
Avg rating:3.0/5.0
Slides: 161
Provided by: BillL161
Category:

less

Transcript and Presenter's Notes

Title: Arrays Bubble Sort Merge Sort


1
ArraysBubble SortMerge Sort
Lecture 23
2
Arrays
3
Arrays
  • Arrays are a little surprising (at first) in Java
  • Arrays themselves are objects!
  • There are two basic types of arrays
  • Arrays of primitives
  • Arrays of object references
  • There are also multidimensional arrays which are
    essentially arrays of array of arrays...
  • We will not go into great detail
  • Just enough to make you dangerous
  • Remember since an array is an object it will have
    a reference

4
Arrays of Primitives
  • There are actually several different legal
    syntaxes for creating arrays. Well just
    demonstrate one. Lets make an array of ints
  • int ia // This is the reference
  • ia new int10 // This makes the object
  • The array object referenced by ia can now hold 10
    ints. They are numbered from 0 to 9.
  • To learn the size of the array we can do this
  • ia.length
  • Note This is not a method call but is like an
    instance variable. It cannot be changed!!!
  • for(int i0 i lt ia.length i)
  • iai i 10

5
Arrays of Objects
  • Actually, Arrays of Object References.
  • Remember our Box class?
  • Box ba // Creates reference
  • ba new Box10 // Makes array object
  • We now have 10 references which can refer to box
    objects! They will all be initialized to null.
  • Constructions like this are allowed
  • Box ba2new Box(1,2), new Box(3,4), new
    Box(2,1)
  • It is very important to understand the necessity
    of creating new objects!

6
Arrays of Objects
  • Box ba new Box5
  • Box b new Box(5,5)
  • for(int i0 i lt ba.length i)
  • bai b
  • Box ba2 new Box5
  • for(int i0 i lt ba.length i)
  • bai new Box(i1,i2)

ba
box l5 w5
ba2
box l1 w2
box l5 w6
box l2 w3
box l4 w5
How many objects?
box l3 w4
7
Multidimensional Arrays
  • When you create an array using new and define
    its dimensions it will be rectangular
  • Box a new Box57
  • But it doesnt have to be rectangular!
  • Box b new Box5
  • for(int i0 ilt5 i)
  • bi new Box(i1)2
  • Dont worry about the fine detail, just be aware
    that if necessary it can be done

8
What we got!
Remember These are Box references...not boxes
Box
Box
0
Box
Box
Box
Box
1
Box
Box
Box
Box
Box
Box
2
Box
Box
Box
Box
Box
Box
Box
Box
3
Box
Box
Box
Box
Box
Box
Box
Box
Box
Box
4
5
6
7
8
9
0
1
2
3
4
Don't panic...we won't ask you to do anything
like this...at least not in CS 1311
9
Questions?
10
Bubble Sort
11
Sorting
  • Sorting takes an unordered array and makes it an
    ordered one.

1 2 3 4 5
6
101
12
5
35
42
77
1 2 3 4 5
6
12
"Bubbling Up" the Largest Element
  • Traverse a collection of elements
  • Move from the front to the end
  • Bubble the largest value to the end using
    pair-wise comparisons and swapping

1 2 3 4 5
6
12
101
5
35
42
77
13
"Bubbling Up" the Largest Element
  • Traverse a collection of elements
  • Move from the front to the end
  • Bubble the largest value to the end using
    pair-wise comparisons and swapping

1 2 3 4 5
6
Swap
12
101
5
35
42
77
14
"Bubbling Up" the Largest Element
  • Traverse a collection of elements
  • Move from the front to the end
  • Bubble the largest value to the end using
    pair-wise comparisons and swapping

1 2 3 4 5
6
Swap
12
101
5
35
77
42
15
"Bubbling Up" the Largest Element
  • Traverse a collection of elements
  • Move from the front to the end
  • Bubble the largest value to the end using
    pair-wise comparisons and swapping

1 2 3 4 5
6
Swap
12
101
5
77
35
42
16
"Bubbling Up" the Largest Element
  • Traverse a collection of elements
  • Move from the front to the end
  • Bubble the largest value to the end using
    pair-wise comparisons and swapping

1 2 3 4 5
6
77
101
5
12
35
42
No need to swap
17
"Bubbling Up" the Largest Element
  • Traverse a collection of elements
  • Move from the front to the end
  • Bubble the largest value to the end using
    pair-wise comparisons and swapping

1 2 3 4 5
6
Swap
77
101
5
12
35
42
18
"Bubbling Up" the Largest Element
  • Traverse a collection of elements
  • Move from the front to the end
  • Bubble the largest value to the end using
    pair-wise comparisons and swapping

1 2 3 4 5
6
101
77
5
12
35
42
Largest value correctly placed
19
The Bubble Up Algorithm
  • // n is the array size
  • int index 1
  • int last_compare_at n 1
  • while( index lt last_compare_at)
  • if(Aindex gt Aindex 1)
  • Swap( A, index )
  • index

20
No, Swap isnt built in.
  • public static void Swap( int A, int I )
  • int t AI
  • AI AI1
  • AI1 AI

21
Items of Interest
  • Notice that only the largest value is correctly
    placed
  • All other values are still out of order
  • So we need to repeat this process

1 2 3 4 5
6
101
77
5
12
35
42
Largest value correctly placed
22
Repeat Bubble Up How Many Times?
  • If we have N elements
  • And if each time we bubble an element, we place
    it in its correct location
  • Then we repeat the bubble up process N 1
    times.
  • This guarantees well correctly place all N
    elements.

23
Bubbling All the Elements
24
Reducing the Number of Comparisons
25
Reducing the Number of Comparisons
  • On the Nth bubble up, we only need to do MAX-N
    comparisons.
  • For example
  • This is the 4th bubble up
  • MAX is 6
  • Thus we have 2 comparisons to do

26
Putting It All Together
27
  • public final static int N 8
  • // Size of Array
  • public static void Swap( int A,
    int I )
  • int t AI
  • AI AI1
  • AI1 AI

28
  • public static void Bubblesort( int AN )
  • int to_do, index
  • to_do N 1
  • while( to_do gt 0 )
  • index 1
  • while (index lt to_do)
  • if(Aindex gt Aindex 1)
  • Swap(A, index)
  • index
  • to_do--
  • // Bubblesort

Outer loop
Inner loop
29
Already Sorted Collections?
  • What if the collection was already sorted?
  • What if only a few elements were out of place and
    after a couple of bubble ups, the collection
    was sorted?
  • We want to be able to detect this and stop
    early!

30
Using a Boolean Flag
  • We can use a boolean variable to determine if any
    swapping occurred during the bubble up.
  • If no swapping occurred, then we know that the
    collection is already sorted!
  • This boolean flag needs to be reset after each
    bubble up.

31
  • did_swap isoftype Boolean
  • did_swap lt- true
  • loop
  • exitif ((to_do 0) OR NOT(did_swap))
  • index lt- 1
  • did_swap lt- false
  • loop
  • exitif(index gt to_do)
  • if(Aindex gt Aindex 1) then
  • Swap(Aindex, Aindex 1)
  • did_swap lt- true
  • endif
  • index lt- index 1
  • endloop
  • to_do lt- to_do - 1
  • endloop

32
  • public static void Bubblesort( int AN )
  • int to_do, index
  • to_do N 1
  • bool did_swap true
  • while( (to_do gt 0) did_swap )
  • index 1
  • did_swap false
  • while (index lt to_do)
  • if(Aindex gt Aindex 1)
  • Swap(A, index)
  • did_swap true
  • index
  • to_do--
  • // Bubblesort

Good reason to use the when only one line
originally
33
An Animated Example
N
8
true
did_swap
to_do
7
index

67
45
23
14
6
33
98
42
1 2 3 4 5 6 7 8
34
An Animated Example
N
8
false
did_swap
to_do
7
index
1
67
45
23
14
6
33
98
42
1 2 3 4 5 6 7 8
35
An Animated Example
N
8
false
did_swap
to_do
7
index
1
Swap
67
45
23
14
6
33
98
42
1 2 3 4 5 6 7 8
36
An Animated Example
N
8
true
did_swap
to_do
7
index
1
Swap
67
45
98
14
6
33
23
42
1 2 3 4 5 6 7 8
37
An Animated Example
N
8
true
did_swap
to_do
7
index
2
67
45
98
14
6
33
23
42
1 2 3 4 5 6 7 8
38
An Animated Example
N
8
true
did_swap
to_do
7
index
2
Swap
67
45
98
14
6
33
23
42
1 2 3 4 5 6 7 8
39
An Animated Example
N
8
true
did_swap
to_do
7
index
2
Swap
67
98
45
14
6
33
23
42
1 2 3 4 5 6 7 8
40
An Animated Example
N
8
true
did_swap
to_do
7
index
3
67
98
45
14
6
33
23
42
1 2 3 4 5 6 7 8
41
An Animated Example
N
8
true
did_swap
to_do
7
index
3
Swap
67
98
45
14
6
33
23
42
1 2 3 4 5 6 7 8
42
An Animated Example
N
8
true
did_swap
to_do
7
index
3
Swap
67
14
45
98
6
33
23
42
1 2 3 4 5 6 7 8
43
An Animated Example
N
8
true
did_swap
to_do
7
index
4
67
14
45
98
6
33
23
42
1 2 3 4 5 6 7 8
44
An Animated Example
N
8
true
did_swap
to_do
7
index
4
Swap
67
14
45
98
6
33
23
42
1 2 3 4 5 6 7 8
45
An Animated Example
N
8
true
did_swap
to_do
7
index
4
Swap
67
14
45
6
98
33
23
42
1 2 3 4 5 6 7 8
46
An Animated Example
N
8
true
did_swap
to_do
7
index
5
67
14
45
6
98
33
23
42
1 2 3 4 5 6 7 8
47
An Animated Example
N
8
true
did_swap
to_do
7
index
5
Swap
67
14
45
6
98
33
23
42
1 2 3 4 5 6 7 8
48
An Animated Example
N
8
true
did_swap
to_do
7
index
5
Swap
98
14
45
6
67
33
23
42
1 2 3 4 5 6 7 8
49
An Animated Example
N
8
true
did_swap
to_do
7
index
6
98
14
45
6
67
33
23
42
1 2 3 4 5 6 7 8
50
An Animated Example
N
8
true
did_swap
to_do
7
index
6
Swap
98
14
45
6
67
33
23
42
1 2 3 4 5 6 7 8
51
An Animated Example
N
8
true
did_swap
to_do
7
index
6
Swap
33
14
45
6
67
98
23
42
1 2 3 4 5 6 7 8
52
An Animated Example
N
8
true
did_swap
to_do
7
index
7
33
14
45
6
67
98
23
42
1 2 3 4 5 6 7 8
53
An Animated Example
N
8
true
did_swap
to_do
7
index
7
Swap
33
14
45
6
67
98
23
42
1 2 3 4 5 6 7 8
54
An Animated Example
N
8
true
did_swap
to_do
7
index
7
Swap
33
14
45
6
67
42
23
98
1 2 3 4 5 6 7 8
55
After First Pass of Outer Loop
N
8
true
did_swap
to_do
7
Finished first Bubble Up
index
8
33
14
45
6
67
42
23
98
1 2 3 4 5 6 7 8
56
The Second Bubble Up
N
8
false
did_swap
to_do
6
index
1
33
14
45
6
67
42
23
98
1 2 3 4 5 6 7 8
57
The Second Bubble Up
N
8
false
did_swap
to_do
6
index
1
No Swap
33
14
45
6
67
42
23
98
1 2 3 4 5 6 7 8
58
The Second Bubble Up
N
8
false
did_swap
to_do
6
index
2
33
14
45
6
67
42
23
98
1 2 3 4 5 6 7 8
59
The Second Bubble Up
N
8
false
did_swap
to_do
6
index
2
Swap
33
14
45
6
67
42
23
98
1 2 3 4 5 6 7 8
60
The Second Bubble Up
N
8
true
did_swap
to_do
6
index
2
Swap
33
45
14
6
67
42
23
98
1 2 3 4 5 6 7 8
61
The Second Bubble Up
N
8
true
did_swap
to_do
6
index
3
33
45
14
6
67
42
23
98
1 2 3 4 5 6 7 8
62
The Second Bubble Up
N
8
true
did_swap
to_do
6
index
3
Swap
33
45
14
6
67
42
23
98
1 2 3 4 5 6 7 8
63
The Second Bubble Up
N
8
true
did_swap
to_do
6
index
3
Swap
33
6
14
45
67
42
23
98
1 2 3 4 5 6 7 8
64
The Second Bubble Up
N
8
true
did_swap
to_do
6
index
4
33
6
14
45
67
42
23
98
1 2 3 4 5 6 7 8
65
The Second Bubble Up
N
8
true
did_swap
to_do
6
index
4
No Swap
33
6
14
45
67
42
23
98
1 2 3 4 5 6 7 8
66
The Second Bubble Up
N
8
true
did_swap
to_do
6
index
5
33
6
14
45
67
42
23
98
1 2 3 4 5 6 7 8
67
The Second Bubble Up
N
8
true
did_swap
to_do
6
index
5
Swap
33
6
14
45
67
42
23
98
1 2 3 4 5 6 7 8
68
The Second Bubble Up
N
8
true
did_swap
to_do
6
index
5
Swap
67
6
14
45
33
42
23
98
1 2 3 4 5 6 7 8
69
The Second Bubble Up
N
8
true
did_swap
to_do
6
index
6
67
6
14
45
33
42
23
98
1 2 3 4 5 6 7 8
70
The Second Bubble Up
N
8
true
did_swap
to_do
6
index
6
Swap
67
6
14
45
33
42
23
98
1 2 3 4 5 6 7 8
71
The Second Bubble Up
N
8
true
did_swap
to_do
6
index
6
Swap
42
6
14
45
33
67
23
98
1 2 3 4 5 6 7 8
72
After Second Pass of Outer Loop
N
8
true
did_swap
to_do
6
Finished second Bubble Up
index
7
42
6
14
45
33
67
23
98
1 2 3 4 5 6 7 8
73
The Third Bubble Up
N
8
false
did_swap
to_do
5
index
1
42
6
14
45
33
67
23
98
1 2 3 4 5 6 7 8
74
The Third Bubble Up
N
8
false
did_swap
to_do
5
index
1
Swap
42
6
14
45
33
67
23
98
1 2 3 4 5 6 7 8
75
The Third Bubble Up
N
8
true
did_swap
to_do
5
index
1
Swap
42
6
23
45
33
67
14
98
1 2 3 4 5 6 7 8
76
The Third Bubble Up
N
8
true
did_swap
to_do
5
index
2
42
6
23
45
33
67
14
98
1 2 3 4 5 6 7 8
77
The Third Bubble Up
N
8
true
did_swap
to_do
5
index
2
Swap
42
6
23
45
33
67
14
98
1 2 3 4 5 6 7 8
78
The Third Bubble Up
N
8
true
did_swap
to_do
5
index
2
Swap
42
23
6
45
33
67
14
98
1 2 3 4 5 6 7 8
79
The Third Bubble Up
N
8
true
did_swap
to_do
5
index
3
42
23
6
45
33
67
14
98
1 2 3 4 5 6 7 8
80
The Third Bubble Up
N
8
true
did_swap
to_do
5
index
3
No Swap
42
23
6
45
33
67
14
98
1 2 3 4 5 6 7 8
81
The Third Bubble Up
N
8
true
did_swap
to_do
5
index
4
42
23
6
45
33
67
14
98
1 2 3 4 5 6 7 8
82
The Third Bubble Up
N
8
true
did_swap
to_do
5
index
4
Swap
42
23
6
45
33
67
14
98
1 2 3 4 5 6 7 8
83
The Third Bubble Up
N
8
true
did_swap
to_do
5
index
4
Swap
42
23
6
33
45
67
14
98
1 2 3 4 5 6 7 8
84
The Third Bubble Up
N
8
true
did_swap
to_do
5
index
5
42
23
6
33
45
67
14
98
1 2 3 4 5 6 7 8
85
The Third Bubble Up
N
8
true
did_swap
to_do
5
index
5
Swap
42
23
6
33
45
67
14
98
1 2 3 4 5 6 7 8
86
The Third Bubble Up
N
8
true
did_swap
to_do
5
index
5
Swap
45
23
6
33
42
67
14
98
1 2 3 4 5 6 7 8
87
After Third Pass of Outer Loop
N
8
true
did_swap
to_do
5
Finished third Bubble Up
index
6
45
23
6
33
42
67
14
98
1 2 3 4 5 6 7 8
88
The Fourth Bubble Up
N
8
false
did_swap
to_do
4
index
1
45
23
6
33
42
67
14
98
1 2 3 4 5 6 7 8
89
The Fourth Bubble Up
N
8
false
did_swap
to_do
4
index
1
Swap
45
23
6
33
42
67
14
98
1 2 3 4 5 6 7 8
90
The Fourth Bubble Up
N
8
true
did_swap
to_do
4
index
1
Swap
45
23
14
33
42
67
6
98
1 2 3 4 5 6 7 8
91
The Fourth Bubble Up
N
8
true
did_swap
to_do
4
index
2
45
23
14
33
42
67
6
98
1 2 3 4 5 6 7 8
92
The Fourth Bubble Up
N
8
true
did_swap
to_do
4
index
2
No Swap
45
23
14
33
42
67
6
98
1 2 3 4 5 6 7 8
93
The Fourth Bubble Up
N
8
true
did_swap
to_do
4
index
3
45
23
14
33
42
67
6
98
1 2 3 4 5 6 7 8
94
The Fourth Bubble Up
N
8
true
did_swap
to_do
4
index
3
No Swap
45
23
14
33
42
67
6
98
1 2 3 4 5 6 7 8
95
The Fourth Bubble Up
N
8
true
did_swap
to_do
4
index
4
45
23
14
33
42
67
6
98
1 2 3 4 5 6 7 8
96
The Fourth Bubble Up
N
8
true
did_swap
to_do
4
index
4
No Swap
45
23
14
33
42
67
6
98
1 2 3 4 5 6 7 8
97
After Fourth Pass of Outer Loop
N
8
true
did_swap
to_do
4
Finished fourth Bubble Up
index
5
45
23
14
33
42
67
6
98
1 2 3 4 5 6 7 8
98
The Fifth Bubble Up
N
8
false
did_swap
to_do
3
index
1
45
23
14
33
42
67
6
98
1 2 3 4 5 6 7 8
99
The Fifth Bubble Up
N
8
false
did_swap
to_do
3
index
1
No Swap
45
23
14
33
42
67
6
98
1 2 3 4 5 6 7 8
100
The Fifth Bubble Up
N
8
false
did_swap
to_do
3
index
2
45
23
14
33
42
67
6
98
1 2 3 4 5 6 7 8
101
The Fifth Bubble Up
N
8
false
did_swap
to_do
3
index
2
No Swap
45
23
14
33
42
67
6
98
1 2 3 4 5 6 7 8
102
The Fifth Bubble Up
N
8
false
did_swap
to_do
3
index
3
45
23
14
33
42
67
6
98
1 2 3 4 5 6 7 8
103
The Fifth Bubble Up
N
8
false
did_swap
to_do
3
index
3
No Swap
45
23
14
33
42
67
6
98
1 2 3 4 5 6 7 8
104
After Fifth Pass of Outer Loop
N
8
false
did_swap
to_do
3
Finished fifth Bubble Up
index
4
45
23
14
33
42
67
6
98
1 2 3 4 5 6 7 8
105
Finished Early
N
8
false
did_swap
to_do
3
We didnt do any swapping,so all of the other
elementsmust be correctly placed. We can skip
the last twopasses of the outer loop.
index
4
45
23
14
33
42
67
6
98
1 2 3 4 5 6 7 8
106
Summary
  • Bubble Up algorithm will move largest value to
    its correct location (to the right)
  • Repeat Bubble Up until all elements are
    correctly placed
  • Maximum of N-1 times
  • Can finish early if no swapping occurs
  • We reduce the number of elements we compare each
    time one is correctly placed

107
Truth in CS Act
LB
  • NOBODY EVER USES BUBBLE SORT
  • NOBODY
  • NOT EVER
  • BECAUSE IT IS EXTREMELY INEFFICIENT

108
Questions?
109
Merge Sort
110
Sorting
  • Sorting takes an unordered collection and makes
    it an ordered one.

1 2 3 4 5
6
101
12
5
35
42
77
1 2 3 4 5
6
111
Divide and Conquer
  • Divide and Conquer cuts the problem in half each
    time, but uses the result of both halves
  • cut the problem in half until the problem is
    trivial
  • solve for both halves
  • combine the solutions

112
Mergesort
  • A divide-and-conquer algorithm
  • Divide the unsorted array into 2 halves until the
    sub-arrays only contain one element
  • Merge the sub-problem solutions together
  • Compare the sub-arrays first elements
  • Remove the smallest element and put it into the
    result array
  • Continue the process until all elements have been
    put into the result array

113
How to Remember Merge Sort?
114
How To Remember Merge Sort?
(q,t)
Just as Mariah recursively moves her hands into
smaller circles, so too does merge sort
recursively split an array into smaller segments.

We need two such recursions, one for each half of
the split array.
115
Algorithm
  • Mergesort(Passed an array)
  • if array size gt 1
  • Divide array in half
  • Call Mergesort on first half.
  • Call Mergesort on second half.
  • Merge two halves.
  • Merge(Passed two arrays)
  • Compare leading element in each array
  • Select lower and place in new array.
  • (If one input array is empty then place
  • remainder of other array in output array)

116
More TRUTH in CS
  • We dont really pass in two arrays!
  • We pass in one array with indicator variables
    which tell us where one set of data starts and
    finishes and where the other set of data starts
    and finishes.
  • Honest.

117
67
45
23
14
6
33
98
42
118
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
119
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
120
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
23
98
121
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
23
98
Merge
122
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
23
98
23
Merge
123
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
23
98
23
98
Merge
124
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
23
98
45
14
23
98
125
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
23
98
45
14
23
98
Merge
126
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
23
98
45
14
14
23
98
Merge
127
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
23
98
45
14
45
23
98
14
Merge
128
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
23
98
45
14
98
45
14
23
Merge
129
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
23
98
45
14
98
14
23
45
14
Merge
130
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
23
98
45
14
23
14
98
45
14
23
Merge
131
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
23
98
45
14
23
98
45
14
14
23
45
Merge
132
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
23
98
45
14
23
98
45
14
14
23
45
98
Merge
133
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
23
98
45
14
14
23
45
98
134
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
23
98
45
14
14
23
45
98
135
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
23
98
45
14
Merge
14
23
45
98
136
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
6
23
98
45
14
Merge
14
23
45
98
137
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
67
23
98
45
14
6
Merge
14
23
45
98
138
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
33
42
23
98
45
14
67
6
14
23
45
98
139
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
33
42
23
98
45
14
67
6
Merge
14
23
45
98
140
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
33
42
33
23
98
45
14
67
6
Merge
14
23
45
98
141
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
33
42
42
23
98
45
14
67
6
33
Merge
14
23
45
98
142
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
33
42
23
98
45
14
67
6
42
33
14
23
45
98
Merge
143
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
33
42
23
98
45
14
6
42
33
67
6
14
23
45
98
Merge
144
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
33
42
23
98
45
14
6
33
67
42
6
33
14
23
45
98
Merge
145
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
33
42
23
98
45
14
6
42
33
67
6
33
42
14
23
45
98
Merge
146
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
33
42
23
98
45
14
67
6
42
33
6
33
42
67
14
23
45
98
Merge
147
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
33
42
23
98
45
14
67
6
42
33
33
42
67
6
23
45
98
14
Merge
148
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
33
42
23
98
45
14
67
6
42
33
6
42
67
33
23
45
98
14
6
Merge
149
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
33
42
23
98
45
14
67
6
42
33
6
42
67
33
14
45
98
23
6
14
Merge
150
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
33
42
23
98
45
14
67
6
42
33
6
42
67
33
14
23
98
45
6
14
23
Merge
151
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
33
42
23
98
45
14
67
6
42
33
6
33
67
42
14
23
98
45
6
14
23
33
Merge
152
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
33
42
23
98
45
14
67
6
42
33
6
33
42
67
14
23
98
45
6
14
23
33
42
Merge
153
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
33
42
23
98
45
14
67
6
42
33
6
33
42
67
14
23
45
98
6
14
23
33
42
45
Merge
154
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
33
42
23
98
45
14
67
6
42
33
6
33
42
67
14
23
45
98
6
14
23
33
42
45
67
Merge
155
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
33
42
23
98
45
14
67
6
42
33
6
33
42
67
14
23
45
98
6
14
23
33
42
45
67
98
Merge
156
67
45
23
14
6
33
98
42
67
45
23
14
6
33
98
42
45
23
14
98
67
6
33
42
23
98
45
14
67
6
33
42
23
98
45
14
67
6
42
33
6
33
42
67
14
23
45
98
6
14
23
33
42
45
67
98
157
67
45
23
14
6
33
98
42
6
14
23
33
42
45
67
98
158
Summary
  • Divide the unsorted collection into two
  • Until the sub-arrays only contain one element
  • Then merge the sub-problem solutions together

159
Questions?
160
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com