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

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

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

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

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

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

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

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

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