# algorithm

## Data retrieval service with exponential backoff

Here we will create Data retrieval service with exponential backoff that we covered in the previous post. Implementation   package com.rms.blueprint.data;   import java.util.Date; import java.util.Objects; import java.util.concurrent.TimeUnit; import java.util.function.Function; import java.util.function.ObjLongConsumer; import java.util.function.Supplier;   import org.slf4j.Logger; import org.slf4j.LoggerFactory;   public class DataRetrievalWithBackoff implements Runnable { public final Logger LOGGER = LoggerFactory.getLogger(DataRetrievalWithBackoff.class);   private final …

## Calculating partial Hausdorff Distance

struct Point { Point(int_t _x, int_t _y) : x(_x), y (_y) {   }   int_t x; int_t y; };     typedef std::list<Point*> points_t;   double euclideanDistance(const Point& lhs,const Point& rhs) { double p1 = std::pow((float)(rhs.x – lhs.x), 2); double p2 = std::pow((float)(rhs.y – lhs.y), 2); double vd = std::sqrt(p1 + p2);   …

## HashTable implemented using quadratic probing for collision resolution

Using quadratic probing for collision resolution #define ERROR_TABLE_FULL -1 #define ERROR_RECORD_NOT_FOUND -1 #define ERROR_DUPLICATE_RECORD -1   class HashTable{ public: HashTable(int table_size); int insert(const string &record); int retrieve(const string &record); private: int hash(const string &record); int hash_size; int record_count; string* table; };   /** * Constructor accepting table_size */ HashTable::HashTable(int table_size){ hash_size = table_size; table = …

## Level order traversal – Breadth-first

Here is implementation of level order traversal of a binary tree. Level order traversal is nothing more than traversing each level at a time 10 Lev 1 / \ 9 15 Lev 2 / / \ 7 12 17 Lev 3 Output 10 9 15 7 12 17 AVL Tree example ++++++++++++++++++++++ 69: 29 77 …