Parallel Computing: how to do tree traversal using parallelism.
Introduction
An algorithm is said to be “tree traversal” if it enables us to visit each node in a tree only once and not more than that number of times. This may be accomplished by a variety of means, but regardless of the approach used, there are a few stages that are always included.
You are required to do the following for each node in the tree:
- Check to see whether a left subtree or node already exists, and if one does, proceed to recursively explore it.
- Check to see whether the correct subtree or node exists, and if it does, go through the process of recursively traversing it.
- Treat the node itself as the object of your attention.
These stages may be performed in any order, but the order in which they are finished will dictate the order in which the nodes of the tree are traversed. These steps can be done in any order.
Pre-Order Traversal
The procedures described above are carried out in the following sequence during a pre-order traversal:
- Taking care of the present node is your responsibility.
- Take the route that goes to the left subtree.
- Follow the path that goes to the right subtree.
The following figure illustrates this point most clearly:
If we were to print out the value of each node in the tree that was just described, the output would look something like this: “2, 7, 2, 6, 5, 11, 5, 9, 4.”
In-Order Traversal
The following procedures are carried out in the correct sequence during an in-order traversal:
- Take the route on the left subtree.
- Take care of the currently selected node.
- Navigate through the correct subtree.
The following figure illustrates this point most clearly:
If we were to print out the value of each node in the tree that was just described, the output would look something like this: “5; 15; 18; 20; 25; 30; 35; 40; 45; 50; 60.”
Post-Order Traversal
You can probably figure out the following sequence in which a post-order traversal completes the tasks it sets out to do:
- Take the route that goes to the left. Subtree
- Follow the path that goes to the right. Subtree
- Take care of the active node in the hierarchy.
If we were to print out the value of each node in the tree that was just described, the output would look something like this: “6, 5, 2, 11, 7, 4, 9, 5, 2.”
The methods for tree traversal that have been studied up to this point all fall under the category of sequential algorithms. Because of this, it is essential that we have a solid understanding of how we will continue with a parallel approach in the tree traversal. This will enable it to process data more rapidly than with the methods that have been used up to this point.
why do we use parallel programming?
When doing numerous tasks simultaneously, parallel computing makes use of a number of different computer cores. In contrast to serial computing, parallel architecture is able to divide a task into its component components and perform many operations on each one simultaneously. Modeling and reproducing real-world occurrences is a task that lends itself particularly well to parallel computer systems.
In the older kind of computing known as “serial computing,” a processor moves through a program sequentially, much as a person would walk along a path. When compared to executing things in parallel, this method is much less efficient. On the other hand, parallel processing is analogous to copying oneself three or five times, then having all of those copies walk side by side while simultaneously covering a large number of steps down the road.
To put it mildly, carrying out digital operations would be very laborious in the absence of parallel computing. If your iPhone or your HP Spectre x360 laptop could only do one action at a time, the time it takes to complete each job would be significantly increased. Consider the mobile phones that were available in 2010 in order to get a sense of the speed — or lack thereof — of serial computing. Serial processors were employed in both the iPhone 4 and the Motorola Droid. To open an email on your phone may take up to a minute and a half, which seems like an eternity in this day and age. What if there was a connection between them? Forget it!
In 2011, the first mobile devices with Android and iPhone equipped with multi-core CPUs were released [1]. Ten years earlier, in 2001, IBM was the first company to market multi-core processors for use in personal computers [2]. But hold for a second… if we’ve had parallel computers for decades, why is there suddenly so much buzz about them?
The benefits of parallel computing are as follows:
- The real world may be modelled using parallel computing:The reality that we live in is not sequential in any way. Things do not take place in sequential order, waiting for one occurrence to conclude before moving on to the next one. Parallel computers are required so that we can analyse large amounts of data simultaneously in a variety of fields, including meteorology, transportation, economics, industry, agriculture, polar regions, and healthcare.
- HELPS SAVE TIME: Computing in serial order compels even the most powerful processors to do tasks in an ineffective manner. It would be the equivalent of driving twenty oranges from Maine to Boston one at a time in a Ferrari. No matter how quickly that automobile can go, doing many trips to make the same number of deliveries is not an effective use of time.
- SAVES MONEY: Parallel computing reduces the amount of time needed to complete a task, which in turn lowers costs. When seen on a smaller scale, the benefits of using resources in a more effective manner may not seem to be significant. On the other hand, when we scale up a system to billions of activities, like the software used in banks, we realise significant cost reductions.
- RESOLVE PROBLEMS THAT ARE EITHER MORE COMPLEX OR GREATER IN SIZE: Computing is maturing. When combined with big data and AI, a single web app has the potential to perform millions of transactions every single second. In addition, “grand issues” such as ensuring the safety of cyberspace and bringing down the cost of solar energy will need for petaFLOPS of computing resources . Computing in parallel will allow us to get there more quickly.
- TAKE ADVANTAGE OF DISTANCES RESOURCES: Every every day, people produce 2.5 quintillion bytes worth of new knowledge. It’s written as the number 25 followed by 29 zeros. We are not even going to attempt to calculate such figures. Or do we have a choice? When using parallel processing, numerous computers, each with a number of processor cores, are able to sort through a significant amount of real-time data in comparison to a single serial computer operating on its own.
Illustrations of Parallel Computing
It’s possible that you’re reading this article on a parallel computer, but here’s the thing: parallel computers have been available since the early 1960s. They might be as unassuming as the low-cost Raspberry Pi computer or as dependable as the Summit supercomputer, which is the most powerful in the world. You may see some instances of how parallel processing drives our environment in the paragraphs that follow.
- Smartphones
- Laptops And Desktops
- ILLIAC IV
- NASA’S SPACE SHUTTLE COMPUTER SYSTEM
- AMERICAN SUMMIT SUPERCOMPUTER
- SETI
- BITCOIN
- MULTITHREADING
- THE INTERNET OF THINGS (IOT)
- MULTITHREADING
- PYTHON
- PARALLEL COMPUTING IN R
- PARALLEL COMPUTING TOOLBOX
Parallel Tree Traversal Technique
We are going to use a method that was developed by Euler and is known as the Euler tour technique so that we can traverse parallel trees. This strategy would include making use of the idea of a jump pointer; thus, let’s first have a clear understanding of what a jump pointer really is.
One strategy for the design of parallel algorithms that work on pointer structures, such as linked lists and directed graphs, is pointer hopping, often known as “path doubling.” An algorithm is able to follow pathways with a time complexity that is logarithmic with respect to the length of the path that is taken. Pointer hopping is one method that does this. To do this, it will “jump” to the end of the route that has been calculated by its neighbors.
The most fundamental step involved in the process of pointer hopping is the replacement of each neighbor in a pointer structure with the neighbor of that structure. This replacement is carried out for each node in the data structure at each stage of the process. This work may be done in a step-by-step fashion or in parallel, depending on your preference. When a neighbor’s neighbor is followed in the subsequent step, the route of the neighbor that was followed in the step before that is added to the path that the node has already followed in a single step. This occurs when the path of a neighbor that was followed in the step before that is followed. As a result, the distance that has been traveled along the pathways that have been examined effectively increases by a factor of two with each step.
The Euler tour is a means of traveling through a tree in which each node that is visited adds a new vertex to the tour (either moving down from the parent vertex or returning from the child vertex). We begin at the root node, and after traveling to each vertex, we make our way back to the base node.
In order to store an Euler tour, precisely 2*N-1 vertices are required.
On the tree, we are going to perform the DFS (depth-first search) algorithm as follows:
- Visit root node, i.e., 1
vis[1] = 1, Euler [0] = 1.
run dfs() for all unvisited adjacent nodes (2) - Visit node 2 with vis[2] = 1, Euler[1] = 2,
and run dfs() for all unvisited adjacent nodes (3, 4) - Visit node 3:
vis[3] = 1, Euler[2] = 3.
All adjacent nodes are already visited; return to the parent node
and add the parent to the Euler tour. - Visit node 4:
vis[4] = 1, Euler[4] = 4.
All adjacent nodes are already visited; return to the parent node
and add the parent to the Euler tour, Euler[5]=2 - Visit node 2.
All adjacent nodes are already visited; return to the parent node
and add the parent to the Euler tour, Euler[6]=1 - Visit node 1.
All adjacent nodes have already been visited, and node 1 is the root node,
so we stop our recursion here.
Complexity Analysis:
- Auxiliary Space: O (N)
- Time Complexity: O (N)
All of these nodes will be assigned to different processors and will point to the grandfather node until all of the nodes will point to the same node, which is ultimately the root node of the tree. For parallel tree traversal, we will be traversing through the nodes of the tree by jumping the pointer to the grandfather node of each child node. This will allow us to move quickly through the tree’s nodes.
CONCLUSION
We gained knowledge about parallel computing and how it may be used in the process of tree traversal via this blog.
Computing in parallel enables computers to concurrently evaluate massive volumes of data in a range of sectors, such as meteorology, transportation, agriculture, polar regions, and healthcare, among others. One of the advantages of parallel computing is a reduction in the amount of time necessary to do a work, in addition to a reduction in associated expenses. Beginning in the early 1960s, people were able to purchase parallel computers. They may be as inconspicuous as the computer known as the Raspberry Pi, or they could be as trustworthy as the supercomputer known as the Summit, which is the most powerful in the world. In the paragraphs that follow, you may perhaps find some examples of how parallel processing influences our world.
Pointer hopping is one method that may be used in the construction of parallel algorithms that operate on pointer structures. Computing in parallel with R In order to save an Euler tour, you’ll need exactly 2*N-1 vertices at your disposal. The following is an explanation of how the DFS (depth-first search) method will be carried out on the tree. In order to do parallel tree traversal, we will be moving the pointer up the tree via the nodes of the tree by leaping to the node that is the grandparent of each child node. Because of this, we will be able to swiftly navigate through the tree’s nodes.