## How to convert Set containing values ​​in string

public static void main(String[] args) { // TODO Auto-generated method stub String str = "abcdaa"; dups(str); } public static void dups(String str){ HashSet hs = new HashSet(); char[] ch = str.toCharArray(); for(int i=0; i < ch.length;i++){ h

## Data structure / design for product and amplifier Delivery information

I need to store some data regarding items, warehouse, and shipping costs For example my store has some items, and different warehouses stock them, although not necessarily all of items. Then each warehouse may have different costs of shipping the ite

## Merge the vector of nodes to obtain the vector of common nodes

Given that I have the following knots vector U1, U2, U3 U1 = {0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 0.8}; U2 = {0.21, 0.25, 0.3, 0.6, 0.7, 0.8}; U3 = {0.25, 0.3, 0.7, 0.8}; Now I would like to calculate their common knots vector , i.e., a knots vector th

## Why break the link between two list nodes when partitioning a list?

I was trying to solve the Partition List problem on LeetCode. The problem asks to sort an linked list given a target list node, so that all the list nodes having smaller value than the target will come before the target, while their original relative

## Beginner Challenge: Sum all even numbers 1-1000. Is my logic wrong or just my code?

I just began coding the other day and I'm going through coding dojo's free beginner algorithm course. I had no trouble with the intro lesson predicting outputs, but now I am writing code my thoughts don't seem to translate well. The task is to write

## Find the missing number (s) of a table

Written this code, would like to get better approach using any algorithm to find missing numbers from an sorted or unsorted array. If its an unsorted array, i would sort and execute the following. private static void identifyMissingValues(Integer[] a

## Natural number generator that returns the smallest number that has been returned but has not been released yet

I am looking for a known algorithm for the following task: I need an object X which provides me with two methods: take() which returns the smallest natural number which is not taken, i.e. sequential calls of this method would return 1, 2, 3 and so on

## Table with consecutive numbers - Algorithm

I am trying to answer the following question: given a sorted array with some sequenced numbers and some non-sequenced numbers, write an algorithm that obtains a pair {start, end} for each group of consecutive numbers. Consecutive numbers have differe

## Can there be a faster algorithm than a linear search?

I have heard that there is no faster algorithm faster than linear search (for an unsorted array), but, when I run this algorithm (linear): public static void search(int[] arr, int value){ for(int i = 0; i < arr.length; i++){ if(arr[i] == value) retur

## Effective algorithm for finding the cheapest subsets

Subject We have a catalogue of items [{id, prodno, qty, price}] and item bundles [{id, price, items:[{prodno, qty}]}]. We have to find the cheapest subset(s) - result {price, [[{id, qty}]]}, which contains specified items - query [{prodno, qty}]. Exa

## c ++ trying to add Peterson's algorithm to avoid competitive conditions in shared memory

I have written two program (program 1 and program 2) to communicate with each other using shared memory. program 1 reads from a file a sentence and pass it after modification to get first letter of each word and its size to the next program ( program

## using the recursive method for the trinary search

I am writing a recursive method that, instead of carrying out a binary search algorithm, splits an array into three and uses a trinary search algorithm. I am fairly positive that my recursive case is correct, yet there seems to be a problem with my b

## Divisibility by 3

I was reading an article on Writing an Efficient Method to Check if a Number is Multiple of 3. The method explained here is to take the difference between oddsum and evensum of the number in binary representation. If the difference is divisible by 3

## What is & ldquo; if it's not & rdquo; does this mean in this case?

I just started learning python. And here is the Algorithm that I don't quite understand. Connected(A[0..n − 1, 0..n − 1]) //Input: Adjacency matrix A[0..n − 1, 0..n − 1]) of an undirected graph G //Output: 1 (true) if G is connected and 0 (false) if

## Loop in a binary tree represented as an adjacency list

I attained an interview where I was asked a question as below: You are given with parent -----> child relationships i.e. N1 ---> N2 where N1 is the parent of N2. This is nothing but representing a binary tree in adjacency list form. So I had to find

## My algorithm to calculate the position of the smartphone - GPS and sensors

I am developing an android application to calculate position based on Sensor's Data Accelerometer --> Calculate Linear Acceleration Magnetometer + Accelerometer --> Direction of movement The initial position will be taken from GPS (Latitude + Longit

## Is there a specialized algorithm to reduce (aggregate) missing numbers as a whole?

That is an array of integer numbers [3, 4, 5, 10, 10000] to transform into an array / an list like ['1, 2', 3, 4, 5, '6-9', 10, '11-9999', 10000]. This is a small example, but it is clear that the loop through all numbers from 1 to 10000 are not effe

## Vector erasure giving unexpected result

Erase from vector giving different results with lambda function and function object. I'm trying to delete 3rd element from a vector of strings. With function object 3rd and 6th element is getting deleted but with lambda version the code gives expecte

## Find all the matches of a large set of strings in a smaller string

I have a large set of Words and Phrases (a lexicon or dictionary) which includes wildcards. I need to find all instances of those Words and Phrases within a much smaller String (~150 characters at the moment). Initially, I wanted to run the operation

## Given a one-to-many map, an algorithm that indicates whether a subset "one-to-one" and "rdquo; map can cover all items

I'm not sure what the proper terminology is to search by (I've searched "mapping algorithms" and "one-to-one algorithms"), and I can't think of a simpler (more canonical) formulation. I have two sets, say A B C D E and L M N O P and I

## Profiling Algorithm

I need to implement execution time measuring functionality. I thought about two possibilities. First - regular time() call, just remember time each execution step starts and time when each execution step completes. Unix time shell command works this

## Temporal complexity of Prim's MST algorithm

Can someone explain to me why is Prim's Algorithm using adjacent matrix result in a time complexity of O(V2)?(Sorry in advance for the sloppy looking ASCII math, I don't think we can use LaTEX to typeset answers) The traditional way to implement Prim

## Maximum simple path with a budget on the edges

This is a part of a self formulated question, and hence I have not been able to "Google" it and my own attempts have been futile till now. You are given a graph G(V,E) each Node of V has a profit wi, each Edge of E has a cost of ci. We are now g

## Given a binary search tree and a number, find a path whose node data was added to be the given number.

Given a binary search tree and a number, find if there is a path from root to a leaf such that all numbers on the path added up to be the given number. I know how to do it by recursively. But, I prefer an iterative solution. If we iterate from root t

## What is the name of the Traveler Commerce Traveler (TSP) problem without considering returning to the starting point?

I would like to know what is the problem name for TSP w/o considering the way of going back to starting point and what is the algorithm to solve this. I looked into Shortest path problem but that is not what I am looking for, the problem only find th

## Question about the implementation of the Dijkstra algorithm on Wikipedia

function Dijkstra(Graph, source): for each vertex v in Graph: // Initializations dist[v] := infinity ; // Unknown distance function from source to v previous[v] := undefined ; // Previous node in optimal path from source end for ; dist[source] := 0 ;

## find all numbers less than x in a BST

how would i do this? I am not sure when I would stop the bst search.If each node of your tree has a field numLeft that tells you how many nodes there are in its left subtree (counting itself too), then you can do this in O(log N) Just keep adding num

## Help with the object of the mouse algorithm

I wasn't sure what to call this. I'm building a tile based game where the user can click on a tile. it is a 2d c++ vector of tiles. right now I have an algorithm that positions them like this: [][][][][][][][][][][] [][][][][][][][][][][] [][][][][][

## The best way to solve a distance problem

There are a set of point that are collinear. The problem is to add a new point that lies in the same line so that sum of distance from the new point to existing points is minimum. (Assume that the point lies in a horizontal line). The solution I thou

## How would you improve this algorithm? (C inversion of chain)

Working through some programming interview challenges I found online, I had to write an algorithm to reverse a const char * and return a pointer to a new char *. I think I have it, but to make it work properly I had to do some wonky stuff - basically