Lecture 5.ppt howllw lsdfahdflasdfaslfhosddduusl

shahzebahamd109 10 views 11 slides Mar 02, 2025
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

allow this types slides


Slide Content

The divide and conquer is a strategy
employed to solve a large number of
computational problems:

the problem into a small
number of pieces
solve each piece by
applying divide and conquer to it
recursively
the pieces together into

a global solution.

Divide and conquer strategy is
applicable in a huge number of
computational problems.

The first example of divide and
conquer algorithm we will discuss is
a simple and efficient sorting
procedure called

We are given a sequence of n
numbers A,which we will assume
are stored in an array A[1..n].

The objective is to output a

permutation of this sequence
sorted in increasing order.

This is normally done by permuting
the elements within the array A.

Here is how the merge sort algorithm
works:

: split A down the middle into

two subsequences, each of size
roughly n/2

: sort each subsequence by
calling merge sort recursively on
each.

: split A down the middle into
two subsequences, each of size
roughly n/2

: sort each subsequence by
calling merge sort recursively on
each.

: merge the two sorted
subsequences into a single sorted
list.

The dividing process ends when we
have split the subsequences down
to a single item.

A sequence of length one is trivially
sorted.

The key operation is the combine
stage which merges together two
sorted lists into a single sorted list.

A sequence of length one is trivially
sorted.

The key operation is the combine
stage which merges together two
sorted lists into a single sorted list.

Fortunately, the combining process
is quite easy to implement.

Divide and Conquer Strategy

The divide phase: split the list top-
down into smaller pieces

ノ 15|214| 11613|0|

Merge Sort

Merge sort

The divide phase: split the list top-
down into smaller pieces

ME 回 EK

x

5 4
NY >
5 4

Merge Sort

Merge sort

The divide phase: split the list top-
down into smaller pieces

7[5/2[4[1[6]3[0]
Tags