Example of too complex algorithm?

As much as i've searched online, I cannot find examples of algorithms that aren't solvable in practice due to the amount of time that they'd take to compute. I was trying to think of an example such as counting the number, size, and location of each

The fastest way to generate a double random number in java

In a project in which I'm working for, I'm required to either generate n random double numbers (depending from what the input file says) or converting them to doubles if I have them from my input file. Those numbers should have only 2 decimals after

How to find the position of the nodes in the binary trees?

4 0 2 0 1 0 3 2 3 0 3 I'm trying to find effective solution to the above problem. Given input first line is: number of nodes in binary tree=4, root=0, depths=2 Edges or nodes on the edge are not given in any specific order, but edge that connects nod

Complexity of a greedy assignment algorithm

The assignment problem asks to find a set of n elements with maximal possible sum in distinct rows and columns of a given n-by-n matrix. It can be solved optimally by the Hungarian algorithm in O(n^3). However, let us consider the following suboptima

Call one of the many functions until we get a specified result

I've got this ugly bit of code that looks a bit like this ... TestResult GetFirstTestResult() { var result = TestMethod1(); if(result is EmptyResult) { result = TestMethod2(); } if(result is EmptyResult) { result = TestMethod3(); } // ... if(result i

The program takes too long for a large entry

I am using an equation in which we have to find the maximum value that x can take given the value of b. Both x and b can take only nonnegative integer values. The equation is: x^4+x^3+x^2+x+1≤b I have written the following code(apparently dumb) to so

Speech Break in Python Does Not Work

I have a string with a list of words. I want to get all the keywords in the list that exists in the string. But it doesn't work with more than 1 keyword ks = ['Voices', 'Home'] def find_tag(long_string, size, result): for idx, s in enumerate(range(0,

Algorithm to add implicit parentheses in a Boolean expression

I have a string such as "A and B or not C and D". The atoms are all simple uppercase letters A,B,C... and the operators are only { and, or, not }. I would like to devise an algorithm that can add parentheses that are implied by the usual rules o

The algorithm of division and conquest in linear complexity?

This question already has an answer here: Maximum single-sell profit 16 answers We have an array of numbers representing prices over time. For example, we have [10, 4, 6, 8, 2, 5, 3, 9, 1]. We want to know when would be the optimal time to buy and to

Find a better way to search the data structure string compare

I have a question which data structure is the best for particular situation. we have one string "AAAAAAAAAAA", and we want to know this string contain in one data base column or not. For example below database there is two column. 1. ID 2. Name

find a similar subsequence in a very large sequence

Imaging that sequence is Pi 141592653589793238462643383279502884197.... the Pi is stored in a text file. I want to locate a similar sub-sequence in the Pi with for example 80% similarity. for example I want to locate 33384 in Pi, so 14159265358979 32

How to link different nodes in the linked list and browse

I am beginner to linked list. I have a situation that to take the size of link is taken at terminal and then read all the data to be kept in freq (In my code it is "freq" but generally called data/info), and create a linked list using them. What

Generate coordinates at random in a defined area

I have a list of longitudes and latitudes which forms boundary for a geographical area. I would like to generate some random co-ordinates inside this geographical area . Could you suggest some approaches I can take in any language?Like any problem, t

The complexity of the time of a special DFS

its known that DFS time complexity is O(|V|+|E|) . Suppose each vertex v has a positive weight w(v). I want to change the DFS algorithm such that when we have "exertion" of which vertex we need to add to the empty stack-we will add the most weig

A * vs trees in the longest path

Let T be a tree in which each node represents a state. The root represents the initial state. An edge going from a parent to a child specifies an action that can be performed on the parent in order to change state (the new state will be the child). E

What is the latest and best facial recognition algorithm?

am doing my final project that includes face recognition and am trying to implement it on matlab. can anybody help me on getting some resources on each algorithms and their pro's and cons. plus if i get their matlab implementation i would be glad. i'

Inplace quick sort implementation

I am trying to implement the inplace quick sort as explained in the http://en.wikipedia.org/wiki/Quicksort Below is the python code, The partition function does not work as expected. def swap(array, index1, index2): tmp = array[index1] array[index1]

in Java, how to get all possible amounts in a table

All the possible distinct sums mean that the sums of any one, two, three to n(the length of the array) number in an array. For example, if the given array is [2,2,3] the sums of one number in the array is the array itself [2,2,3] the sums of any two

In situ transposition of a matrix

Is it possible to transpose a (m,n) matrix in-place, giving that the matrix is represented as a single array of size m*n ? The usual algorithm transpose(Matrix mat,int rows, int cols ){ //construction step Matrix tmat; for(int i=0;i<rows;i++){ for(in

Why does the hashtable have a constant access time on average?

I don't understand this explanation which says if n is the number of elements in the hash table and m is the total number of buckets then hashtables have constant access time in average only if n is proportional to theta(n). Why does it have to be pr

Find a mode with decreasing accuracy

I feel like there should be an available library to more simply do two things, A) Find the mode to an array, in the case of doubles and B) gracefully degrade the precision until you reach a particular frequency. So imagine an array like this: double[

Generate an encoding string in the order of creation

I need to generate encoding String for each item I inserted into the database. for example: x00001 for the first item x00002 for the sencond item x00003 for the third item The way I chose to do this is counting the rows. Before I insert the third ite

How is the Photoshop cut filter implemented?

Photoshop has a lot of cool artistic filters, and I'd love to understand the underlying algorithms. One algorithm that's particularly interesting is the Cutout filter (number 2 at the link above). It has three tunable parameters, Number of Levels, Ed