An algorithm is a sequence of well-defined steps that defines an abstract solution to a problem. Use this tag when your issue is related to algorithm design.
5
votes
4answers
73 views
Big O - O(log(n)) code example
Like the Big O notation "O(1)" can describe following code:
O(1):
for (int i = 0; i < 10; i++) {
// do stuff
a[i] = INT;
}
O(n):
for (int i = 0; i < n; i++) {
...
0
votes
0answers
45 views
get match percentages between two objects by parameters
I want to create a program that will automate a process that i am doing manually today.
I apologize if the solution seems to be easy i just don't want to think about new algorithm specially for my ...
2
votes
1answer
49 views
How to count co-prime to n in a range [1,x] where x can be different from n?
I want to count co-primes of n in a range [1,x]. I have tried using euler phi funtion but it gives for [1,n].Can anyone suggest a modification to euler phi or any other approach to do this?
I have ...
0
votes
2answers
30 views
Parsing the recursive Hanoi Tower algorithm
I am sorry to ask this question, but I didn't find any of the other existing threads useful. I have to say I have a difficulty wrapping my head around complex topics, maybe I am just dumb. I am deeply ...
3
votes
1answer
38 views
How many ways can you insert a series of values into a BST to form a specific tree?
This earlier question asked how many ways there were to insert the values 1 - 7 into a binary search tree that would result in the following tree:
4
/ \
2 6
/ \ / \
1 3 ...
1
vote
2answers
32 views
How many permutations of a given array result in BST's of height 2?
A BST is generated (by successive insertion of nodes) from each permutation of keys from the set {1,2,3,4,5,6,7}. How many permutations determine trees of height two?
I been stuck on this simple ...
3
votes
2answers
42 views
Determine distance between two random nodes in a tree
Given a general tree, I want the distance between two nodes v and w.
Wikipedia states the following:
Computation of lowest common ancestors may be useful, for instance, as part of a procedure ...
5
votes
2answers
71 views
How to find insertions/deletions by comparing hashes quickly?
I want to create a hash of a file such that if the file is changed I can determine what parts of the file changed. The problem is that if a byte is removed or added, all subsequent hashes change too, ...
5
votes
2answers
59 views
Find the unduplicated element in a sorted array
Source : Microsoft Interview Question
Given a sorted array, in which every element is present twice except one which is present single time, we need to find that element.
Now a standard O(n) ...
-2
votes
2answers
35 views
Explination of Mersenne Twister algorithm [closed]
I am looking to implement the Mersenne Twister random number generator in a project. However, since this is for an embedded application, I will be later optimizing the code for my architecture. ...
4
votes
1answer
42 views
Creating a stitched scene using glFrustum
I have a program in which I can make a scene render on a screen as per the user's position. As the user changes position, the frustum changes to give off-axis projection. I want to utilize the ...
2
votes
9answers
178 views
Divisiblity of 5 without using % and / operator
how to check whether a number is divisible by 5 or not without using % and / operator.
I want a quickest algorithm for this problem.
1
vote
5answers
101 views
Multithread C++ program to speed up a summatory loop
I have a loop that iterates from 1 to N and takes a modular sum over time. However N is very large and so I am wondering if there is a way to modify it by taking advantage of multithread.
To give ...
7
votes
5answers
60 views
How can I find the center of a cluster of data points?
Let's say I plotted the position of an airplane every day for the past year and came up with the following map:
Any human looking at this would be able to tell me that this airplane is based out of ...
0
votes
0answers
47 views
Strange execution time results - comparing bubble and shell sort
I'm comparing execution times of bubble sort and Shell sort. The second obviously should be quicker, so let's see:
time_start(); for(int i = 0; i < 100000; i++) numbers = shell(numbers); ...