Most voted "algorithm" questions
An algorithm is a sequence of well-defined steps that defines an abstract solution to a problem. Use this tag when the problem is related to the design of an algorithm. Always use specific algorithm tags when the question is more directed to a specific type of algorithm.
Learn more…723 questions
Sort by count of
-
7
votes1
answer765
viewsHow do I search for profiles with characteristics similar to the interests of another profile on a relationship site?
I need to select several clients from a site of relationships that I am developing and sort by compatibility with the person’s profile IE, the more similar characteristics the greater the…
algorithmasked 10 years, 8 months ago RodrigoBorth 4,475 -
7
votes4
answers9003
viewsInvert a 3-digit number in C
I need to make a program that the user type a three digit number and the program reverses that number for example 123 -> 321, I’d like to know the logic to do that, because I can’t think of…
-
7
votes1
answer402
viewsPercentage of Equality of Texts?
Is there any method to know the percentage of equality of two texts (Strings) in Java? An abstract algorithm would also serve.
-
7
votes1
answer4415
viewsRecursive function simulating a number elevated to a power
How to simulate the elevation of a number to a power using the recursion (and Python)?`
-
7
votes3
answers31930
viewsMake an algorithm to calculate the number of days elapsed between two dates in c++
Guys I have this algorithm: Make an algorithm to calculate the number of days elapsed between two dates (also consider the occurrence of leap years), knowing that: a) each pair of dates is read on a…
-
7
votes2
answers767
viewsPath between 2 nos of a graph using smaller number of colored edges
I’m trying to solve this programming problem. In summary, the problem describes several bus lines as an undirected graph and says that a bus ticket costs 1 real. Can someone give me a hint on how I…
-
7
votes1
answer1464
viewsSimple permutation algorithm
I’m trying to create a simple permutation algorithm where you pass any number for example 123 and it should return the largest number without repeating. I tried something like this more when I pass…
-
7
votes3
answers12017
viewsDifference between full and full binary tree
What is the difference between a full binary tree and a full binary tree?
-
7
votes1
answer392
viewsCreate algorithm for fluid simulation?
I want to create a simulation game with Unity and I need to simulate the movement of 2D fluids, I can’t think of a way to create an algorithm with enough performance to simulate a thousand particles…
-
7
votes1
answer861
viewsFill char matrix with random words
I’m trying to develop an algorithm that can get an array of strings, sort by word size downwards, and put them into a char matrix by fitting all the words together if possible. The idea of…
-
7
votes1
answer149
viewsWhat happens if a binary search does not find the element?
What happens if a binary search does not find the element? It goes into loop? What is the best way to finish the execution?
-
7
votes2
answers339
viewsWhy does String hashcode() in Java use 31 as a multiplier?
In Java, the code hash for an object String is computed as s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] using integer arithmetic, where s[i] is the i-nth character of the string, n is the string…
-
7
votes1
answer146
viewsWhat is Tree Depth and height?
I asked the question What is Breadth First and Depth First?. Perhaps a slightly simpler subject matter would be what are the depth and height of a tree structure. And why this matters in the data…
-
7
votes1
answer1023
viewsWhat is a Great Algorithm?
I’m taking classes from Introducing the Analysis of Complexity. I was told that an example of an optimal algorithm is the algorithm for finding the smallest value between elements of an array of…
-
6
votes2
answers182
viewsDoubt about constant-time sorting algorithms
I need to solve a exercise with the following statement: As input we have a vector of n elements, where each element has a value between 0 and k. In addition we have two integer values to and b. We…
algorithmasked 10 years, 6 months ago Gustavo Nunes 167 -
6
votes3
answers261
viewsMathematical combinatorics
I have a list of ex numbers: [1, 2, 3, 4] and I need to know all possible combinations of that list reminding me that the list may contain n elements, someone has some code or could help me? For…
-
6
votes2
answers357
viewsBase62 coding
I wonder where I can get some PHP implementation, similar to MIME Base64 PHP but only with A-Z, a-z and 0-9 characters. The Base64 from PHP is quite versatile, but I need an algorithm that doesn’t…
-
6
votes2
answers1608
viewsInfinite loop trying to calculate if the number is prime
I have no idea how I’m going to determine the condition of for for prime numbers. I always end in looping. #include <stdio.h> int main() { int num = 1, primo; do { printf("Informe um numero…
-
6
votes3
answers4588
viewsAlgorithm with structure PARA and SE
An algorithm that reads the name and sex of fifty-six people and states her name and whether she is male or female. In the end report the total of men and women. I need the show to run on Visualg. I…
-
6
votes1
answer246
viewsHow to prove that the algorithm solution is optimal?
I need to argue that the solution found after running Prim’s Greedy Algorithm is great. But I don’t know how, someone could help?
-
6
votes2
answers40971
viewsProblem using Switch Case in Python 3
print ("ESCOLHA A CERVEJA PELO NUMERO") print ("1-ANTARTICA R$6.00;2-SKOL R$6.50;3-BRAHMA R$8.20;4-SOL R$8.25;") cerveja = input ("5-NORTENHA R$16.80;6-PROIBIDA R$4.80;7-DEVASSA R$5.90;8-HEINEKEN…
-
6
votes6
answers37862
viewsHow to remove characters from a string?
The program must read two strings and remove from the first string all the letters that occur in the second string. Example: Be the strings "chocolate" and "hollow", then the program should print…
-
6
votes2
answers1002
viewsBogosort - what is this?
What exactly does the bogosort sorting algorithm? Because many say he’s inefficient?
-
6
votes3
answers2216
viewsHow to reverse an integer?
Note this statement: /* * Faça um programa que peça um numero inteiro positivo e em seguida mostre * este numero invertido. Exemplo: * o 12376489 * => 98467321 * */ Console.Write("Informe um…
-
6
votes1
answer1224
viewsWhat is the best implementation of 'Mergesort Algorithm'?
I know the Quick Sort algorithm, but at the moment I want to analyze Merge Sort. I found two types of Merge Sort implementation on the Internet. But when I compare them to the Insertion algorithm,…
-
6
votes1
answer259
viewsSorting algorithm, Java stream
When working with Stream I currently use the Sorted method to sort, example: Stream<Integer> stream = Stream.of(3, 2, 1); stream.sorted(); // saida será 123 What is the sorting algorithm for…
-
6
votes3
answers417
viewsCounter of a subsequence of repeated strings in C
Consider a string composed of several subsequences. for example: cccaaaabbbbxdddddddaaannn. The smallest subsequence is the letter x, with only one element; the largest subsequence is the letter d,…
-
6
votes1
answer140
viewsWhat algorithm to use for a diff mechanism?
You know these mechanisms of Difference of content that we use in control of various versions, where can be seen on Wikipedia or on Github, even here on the site? Just as there are algorithms known…
-
6
votes1
answer124
viewsWhy is the "in" method for checking if an element belongs to a collection so slow?
I was having a lot of difficulty executing code efficiently and found that the problem was on a line that used the operator in. Then I created a new function that searches for a match in the list of…
-
5
votes1
answer2096
viewsAlgorithm for cutting plane
I don’t know if this is the best place to ask this question, but I searched the Internet a lot for some algorithm for cutting plan - that informing the dimensions of the pieces it shows the best…
-
5
votes1
answer169
viewsCommon predecessor in a graph of commits
I ran into another interesting problem during an interview. Unfortunately I’m also not sure I found a great (or good enough) algorithm. I thought to share to see if anyone knows a classic solution…
-
5
votes1
answer202
viewsHow does Bitap’s algorithm work?
According to Wikipedia in English: The bitap algorithm (also known as o-shift or, shift and or Baeza-Yates-Gonnet algorithm) is a matching sequence approximate algorithm. The algorithm indicates…
-
5
votes1
answer179
viewsSegmentation fault: branch and bound in c
I have a persistent error in my code. My goal is to find the way in a maze mounted on an array with an algorithm like branch and bound. Follows the code: FILE *ent; FILE *saida; int NL; int temp;…
-
5
votes2
answers899
viewsGraphs: the longest path
Well, as a college job, I have to create an algorithm that, given a certain file with x is able to verify which is the largest sequence of numbers which, on the basis of 6, comply with the following…
-
5
votes1
answer139
viewsPrecedence of operators with pointers
Having, for example, the following instructions: int i=10, j=20; int *pti, *ptj; pti = &i; ptj = &j; What is the meaning of j = pti == ptj; and of i = pti || ptj; ? Also, I read that the sum…
-
5
votes2
answers2528
viewsSearch for tree depth
I’d like to develop an algorithm that searches for depth in a binary tree, but I’m not getting it. When we make the tree we assign to each node the cost (cost to transition from one node to the…
-
5
votes1
answer324
viewsAlgorithm Complexity Analysis
A professor at my college passed an exercise to analyze the temporal complexity of this algorithm, but I’m not getting it at all. Someone knows how to give me a light on how to separate the…
-
5
votes3
answers6933
viewsRotate matrix by 90º
I need to create a C algorithm to rotate a 10x10 matrix by 90 degrees, however I cannot use an auxiliary matrix for this. Simplifying what was asked to try to find some pattern and use it to solve…
-
5
votes2
answers2741
viewsHow to identify a specific number in any numerical value?
For example, my variable valor (whole type) has the value 1354, note that the number 13 appears at this numeric value. How can I identify a specific number at any other numeric value? I’d like an…
-
5
votes1
answer252
viewsComplexity of Algorithms
Every algorithm with complexity involving a "log" has recursion involved? Type: O(n log n). If not, when will you have "log" in some complexity?
algorithmasked 8 years, 6 months ago Rhanyel Rodrigues 51 -
5
votes1
answer983
viewsAlgorithm - How to catch days in a JS week
I have the following situation: I need to set the days of each week within a month, creating an array of JSON objects. Each position would correspond to a week, for example if there were 5 weeks I…
-
5
votes1
answer139
viewsHow to run a loop while waiting for input?
I want to know if you can run a repeat loop while waiting for an input type() and right after receiving the loop input for or while starts processing it immediately. something like: imputs = []…
-
5
votes1
answer2656
viewsHow does a virtual keyboard work for security purposes?
I know you have several posts here citing the pros/cons of virtual keyboards to avoid keyloggers, but I didn’t see any that went into that particular point: How do those virtual bank type keyboards…
-
5
votes1
answer593
viewsHow does seed influence the generation of random numbers?
The doubt is very simple, I would like to know how the class System.Random generates random pseudorandomness numbers from a seed, which I find odd. I know they are not totally random, and so I have…
-
5
votes1
answer105
viewsAverage is not calculated
I need to write a code that reads only 20 integer values, at the end add the positive numbers and average the negative numbers. It normally adds up the positives but when it arrives at the time of…
-
5
votes2
answers328
viewsPrint multiple numbers with a separator between them, but do not put the separator after the last
Make a program that reads two integers, representing the start and end values of a range and print the multiples of 5 between them. My code: valores = input().split() numero1 = int(valores[0])…
-
5
votes3
answers195
viewsList without negative number
The exercise is as follows: a program that reads the values and separates them into a list of pairs or odd numbers. The count only stops when a negative number comes (which should not be on the…
-
5
votes1
answer254
viewsTwo marbles and a 100-story building
Classic question of job interviews... You receive two marbles (marbles), you are told that they will break when they fall from a certain height (and presumably do not suffer damage if they fall…
-
5
votes1
answer88
viewsWhat is the lowest number of irrigators (circles) needed to cover the surface of a foliage (rectangle)? (competitive programming)
I participated in a test and, in one of the problems, I did not get the total score of the question, one of the test cases gave Wrong Answer, but I could not identify exactly my error. The statement…
-
5
votes3
answers123
viewsCompare range of values
The code below compares a value and according to this value generates a percentage and works. But I would like a more practical way, whether function or other structure, because these ranges of…