Use Hashing to optimize your
algorithm.(use java)
Write an algorithm to find and complete the labeling of connected components in an image.
Image
|
scan pixel By pixel
|
pixel is not background
|
check neighbour
|
neighbour already labelled neighbour already labelled
|
assign to parent labelled assign new labelled
second to find aggregation
Image
|
scan pixel by pixel
|
get parent labelled
|
add to existing list add to new list
public interface IConnectedComponentLabeling
{
IDictionary<int, Bitmap> Process(Bitmap input);
}
IConnectedComponentLabeling target = new CCL();
Bitmap input = new Bitmap(AppDomain.CurrentDomain.BaseDirectory + @"\Test.bmp");
var images= target.Process(input);
foreach (var image in images) {
image.Value.Save(savePath + image.Key + ".bmp");
}
private Dictionary<int, List<Pixel>> AggregatePatterns(Dictionary<int,
Label> allLabels, int width, int height)
{
var patterns = new Dictionary<int, List<Pixel>>();
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
int patternNumber = _board[j, i];
if (patternNumber != 0)
{
patternNumber = allLabels[patternNumber].GetRoot().Name;
if (!patterns.ContainsKey(patternNumber))
{
patterns.Add(patternNumber, new List<Pixel>());
}
patterns[patternNumber].Add(new Pixel(new Point(j, i), Color.Black));
}
}
}
return patterns;
}
using System;
using System.Collections.Generic;
using System.Text;
namespace ConnectedComponentLabeling
{
internal class Label
{
public int Name { get; set; }
public Label Root { get; set; }
public int Rank { get; set; }
public Label(int Name)
{
this.Name = Name;
this.Root = this;
this.Rank = 0;
}
internal Label GetRoot()
{
if (this.Root != this)
{
this.Root = this.Root.GetRoot();//Compact tree
}
return this.Root;
}
internal void Join(Label root2)
{
if (root2.Rank < this.Rank)//is the rank of Root2 less than that of Root1 ?
{
root2.Root = this;//yes! then Root1 is the parent of Root2 (since it has the higher rank)
}
else //rank of Root2 is greater than or equal to that of Root1
{
this.Root = root2;//make Root2 the parent
if (this.Rank == root2.Rank)//both ranks are equal ?
{
root2.Rank++;//increment Root2, we need to reach a single root for the whole tree
}
}
}
}
}
Use Hashing to optimize your algorithm.(use java) Write an algorithm to find and complete the lab...
Use Java if possible please:
Write an algorithm using pseudo code to determine if an undirected graph has any cycle. Analyze the complexity of your algorithm. Write an algorithm using pseudo code to determine if an undirected graph is connected or not. Analyze the complexity of your algorithm. (i) (ii)
Use java code please not C++ or Python. Thank you.
Write a recursive algorithm that counts the number of nodes in a linked list. Analyze the runtime of your algorithm
write an algorithm by using java code to find the approximate roots of the function using the fixed-point method
1 Objective Build a hashing algorithm that is suitable for use in a Bloom Filter. Please note that while a cryptographic hash is quite common in many Bloom Filters, the hashing algorithm to be implemented is a mix of the the following algorithmic models, specifically, a multiply & rotate hash colloquially known as a murmur hash, and an AND, rolale, & XOR hash colloquially known as an ARX hash. 2 Requirements • Inputs. Read the input file which contains strings...
(java) Write an algorithm that displays all the characters in a stack in the order in which they were pushed onto the stack. After all the characters are displayed, the stack should have the same contents as when you started. In your method, you can only use the stack’s operation, and NO explicit index can be declared to locate the items in the stack. Also, write the main() function to test your algorithm.
USE JAVA, PYTHON OR C TO WRITE AN ALGORITHM FOR THIS EXERCISE: . Chocolate bar puzzle Given an n × m chocolate bar, you need to break it into nm 1 × 1 pieces. You can break a bar only in a straight line, and only one bar can be broken at a time. Design an algorithm that solves the problem with the minimum number of bar breaks. What is this minimum number? Justify your answer by using the properties...
Implement the depth-first search (DFS) algorithm. To make your algorithm complete, write the graph search version of DFS, which avoids expanding any already visited states. Your code should quickly find a solution for tinyMaze.txt (below) %%%%%%% % S% % %%% % % % % %% %% %F %%%% %%%%%%%
Java In your own custom ArrayList<E> class(do not use Java Array List API) use Array algorithm Write a static function called RemoveNullElements() without creating another array. that remove Null elements and shift all the rest of the elements to the left/front (small indexes) of the array without changing the size or length of the original array( this meant the front of the array will have all the not Null elements, and the other haft will be empty/Null. Please provide test...
Explain the space-time tradeoff implemented in efficient hash tables? b) Use hashing to design and algorithm to identify all duplicate elements in an array, e.g., for the following array [ “r6i”, “opd”, “r6i”, “ydg”, “x5s”, “pc1”, “tni”, “594”, “ wi5”, “ip0”, “vvj”, “oad”, “ydg”, “‘opd” ] the elements [“r6i”, “opd”, “ydg”] are duplicates. The time complexity of the algorithm must be O(n)