- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Berkeley’s Algorithm in C/C++
Berkeley’s Algorithm is an algorithm that is used for clock Synchronisation in distributed systems. This algorithm is used in cases when some or all systems of the distributed network have one of these issues −
A. The machine does not have an accurate time source.
B. The network or machine does not have a UTC server.
Distributed system contains multiple nodes that are physically separated but are linked together using a network.
In this algorithm, the system chooses a node as master/ leader node. This is done from pool nodes in the server.
The algorithm is −
An election process chooses the master node in the server.
The leader then polls followers that provide their time in a way similar to Cristian’s Algorithm, this is done periodically.
The leader then calculates the relative time that other nodes have to change or adjust to synchronize to the global clock time which is the average of times that are provided to the leader node.
Let’s sum-up steps followed to synchronize the clock using the Berkeley algorithm,
Nodes in the distributed system with their clock timings −
N1 -> 14:00 (master node) N2 -> 13: 46 N3 -> 14: 15
Step 1 − The Leader is elected, node N1 is the master in the system.
Step 2 − leader requests for time from all nodes.
N1 -> time : 14:00 N2 -> time : 13:46 N3 -> time : 14:20
Step 3 − The leader averages the times and sends the correction time back to the nodes.
N1 -> Corrected Time 14:02 (+2) N2 -> Corrected Time 14:02 (+16) N3 -> Corrected Time 14:02 (-18)
This shows how the synchronization of nodes of a distributed system is done using Berkeley’s algorithm.
- Z algorithm (Linear time pattern searching Algorithm) in C++
- Angular Sweep Algorithm in C++
- Bellman Ford Algorithm in C++?
- Elo Rating Algorithm in C++
- Tim Sort Algorithm in C++
- Kruskal's Minimum Spanning Tree Algorithm-Greedy algorithm in C++
- Stein’s Algorithm for finding GCD in C++
- Convex Hull Monotone chain algorithm in C++
- Alexander Bogomolny’s UnOrdered Permutation Algorithm in C++
- Mid-Point Line Generation Algorithm in C++
- Point Clipping Algorithm in Computer Graphics in C++
- C++ Program to Implement Johnson’s Algorithm
- C++ Program to Implement Kadane’s Algorithm
- Flood fill algorithm using C graphics
- Convex Hull Jarvis’s Algorithm or Wrapping in C++