Parallel and Distributed lec 11
Parallel and Distributed lec 11
Computing
COMP3139
Contents
•
Parallel Search
• Searching Algorithms
• Examples
• Parallel sort
• Sorting Algorithm
• Examples
PARALLEL SEARCH
3
PARALLEL SEARCH
• Example:
• Suppose you have a large array of numbers, and you want to find if a
specific number exists in this array.
• In sequential search (linear search), you would check each element one
by one until you either find the number or reach the end of the array. This
is slow for large datasets.
• Divide the array into multiple sections and assign each section to a
different processor or thread.
4
PARALLEL SEARCH ALGORITHM
5
PARALLEL SEARCH ALGORITHM
2. Depth-First Search
Depth-First Search (or DFS) is an algorithm for searching a tree or an
undirected graph data structure.
Concept is to start from the starting node known as the root and traverse
as far as possible in the same branch.
If we get a node with no successor node, we return and continue with the
vertex, which is yet to be visited.
6
PARALLEL SEARCH ALGORITHM
2. Depth-First Search
• Consider a node (root) that is not
visited previously and mark it visited.
• Visit the first adjacent successor node
and mark it visited.
• If all the successors' nodes of the
considered node are already visited or
it doesn’t have any more successor
node, return to its parent node.
7
PARALLEL SEARCH ALGORITHM
3. Best-First Search
• Best-First Search is an algorithm that traverses a graph to reach a target in the
shortest possible path. Unlike BFS and DFS,
• Start with the root node, mark it visited.
• Find the next appropriate node and mark it visited.
• Go to the next level and find the appropriate node and mark it visited.
• Continue this process until the target is reached.
8
PARALLEL SEARCH ALGORITHM
3. Best-First Search
Pseudocode
9
PARALLEL SORTING
1.Enumeration Sort
• Enumeration sort is a method of arranging all the elements in a list by
finding the final position of each element in a sorted list.
• It is done by comparing each element with all other elements and finding the
number of elements having smaller value.
10
PARALLEL SORTING
11
PARALLEL SORTING
12
PARALLEL SORTING
2. Parallel Merge
Sort
Algorithm:
13
PARALLEL SORTING