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
-
3
votes4
answers814
viewsRepeat alphabet similar to excel columns
I am creating a function that returns the alphabet to me in an array according to the size of columns passed. At first I was only making a loop using the range("A", "Z"); but when I had more than 26…
-
3
votes1
answer736
viewsYou can access the key through the value:
In dictionaries, in Python, is it possible to access a key through the value? Is there any method that inverts key/value?
-
3
votes1
answer2225
viewsAdjacent values
I need to create an algorithm that calculates the minimum distance value between the indexes of a matrix that contains adjacent values. But what are adjacent values someone could give me examples?…
-
3
votes1
answer854
viewsHow to calculate test scores?
I’m writing a code that prints a student’s grade according to the number of questions he gets right. But I need the program to do the calculation in a specific amount of times. The program must…
-
3
votes1
answer91
viewsRecombination algorithm
Imagine the following scenario: a gas station is fined for tax evasion for issuing tax coupons already issued - what happens is that each vehicle of the companies contracted to the station supplied…
algorithmasked 8 years, 7 months ago Allyson de Paula 205 -
3
votes1
answer259
viewsWhat algorithm is that?
Knowing that: [] denotes an array [A|B] extracts the first element of the array in A and the rest of the array in B [X, Y] ++ [Z] creates a concatenated array [X, Y, Z] [ X || X <- [1, 2, 3, 4],…
-
3
votes1
answer3270
viewsStep by level in binary tree
Description of the problem I need to solve: "A level walk on a tree, first list the root, then all nodes that are at level 1 then all nodes of level 2, etc. Write a procedure to list the nodes of a…
-
3
votes1
answer252
viewsSearching graphs to solve Euler’s theorem
Hello, I would like a help to do a search on a graph and check if it satisfies the theorem of Euler. The theorem says: "A connected graph will contain an Euler cycle if, and only if, each vertex has…
-
3
votes1
answer79
viewsCode works sometimes yes and sometimes no
This is my code: #include <iostream> #include <cstdlib> #include <ctime> using namespace std; void exchange (int *arr, int i, int j) { if (i == j) return; int aux = arr[j]; arr[j]…
-
3
votes2
answers1275
viewsHow to use the Graph Cycle Verification Algorithm?
Hello, I would like to know how to use the Graph Cycle Check Algorithm to find a cyclic condition, if you can put me the use of the algorithm in this graph below:…
-
3
votes1
answer101
viewsAlgorithm for popular tables in Postgressql
I am writing an algorithm to popular all tables in a database in Postgres. I already get popular all tables who have no relationship, as follows: I get all tables with the following query: SELECT…
-
3
votes2
answers13376
viewsGenerate Nfe Key
I have a closed source software that validates the Nfe key in the invoice entry by the stock module. I need to generate some Nfe keys for testing. So far I know that the Nfe key validates the…
-
3
votes3
answers309
viewsFibonacci sequence does not work
I’m having trouble exiting the Fibonacci sequence and I can’t identify where the bug is. Here’s the code: #include <stdio.h> #include <stdlib.h> int main(){ int i, Fib[100], n;…
-
3
votes2
answers13835
viewsAlgorithm to calculate the sum of the numbers typed in portugol
I’m using Portugol Studio to study algorithms in Portuguese. And I’m having a hard time with a question that the teacher passed. the question is as follows: Develop an algorithm that requires the…
-
3
votes2
answers233
viewsBinary search tree (Binary search Tree) and binary search (Binary search)
From what I understand, the binary search tree algorithm works at the end of the day, in the same way as the binary search algorithm, with only a few changes, correct? More directly: the binary…
algorithmasked 6 years, 8 months ago Strawberry Swing 177 -
3
votes1
answer1365
viewsBig O notation - Complexity O(log n)
I have some questions about this complexity, which base is used in this logarithm, 2 or 10? and why? Searching Google I saw some comments saying that the base didn’t matter.. The logarithm is deeply…
-
3
votes1
answer365
viewsHow to store vector values?
I’m a beginner in C and I’m 2 days into this exercise, I was able to do it so that if you increase the vector with the function realloc, it will increase everything right, but I need him to keep the…
-
3
votes3
answers4140
viewsFunction that calculates the factorial of a number
int fatorial(int n, int f){ int resultado; while(n>1){ f=1; resultado=(n*f); f=f-1; } return (resultado); } int main(void){ int resultado; int n; int f; printf("Digite o numero a ser…
-
3
votes1
answer531
viewsCycles in graphs
I am creating an algorithm that identifies whether a graph contains cycles excluded from the sources recursively, returning the graph for later verification of the edge quantity, so create the…
-
3
votes2
answers1405
views -
3
votes1
answer1775
viewsHow to turn a context-free grammar into a stack automaton?
I have a grammar, like for example: Or else: Or even that: Or this grammar, which represents the boolean logic for three variables: How to turn these grammars into stack automata? Would have some…
algorithm computer-theory automata formal-languagesasked 7 years, 1 month ago Jefferson Quesado 22,370 -
3
votes2
answers565
viewsImproper Infinite Loop no while
I made a program to calculate within a sequence the sum of the positive numbers and the sum of the negative numbers. When I use the command while, the idea is that it is within a sequence of 7…
-
3
votes3
answers2862
viewsChanging data from a List<>
Hello I have a collection like this made on top of a class: public class Produto { public int Id { get; set; } public string Descricao { get; set; } public int Quantidade { get; set; } public…
-
3
votes1
answer912
viewsAutocorrelation function in Python
Hello, everybody! I have a file . txt of data with two columns (in X I have the values in days of observations and in Y the Measured Flow of a sample) I intend to calculate the Period with which…
-
3
votes3
answers214
viewsJava Mergesort sorting algorithm error
I was doing the Mergesort sorting algorithm in Java for study purposes and every time it runs it gives error. I’ve already revised the logic of the algorithm, already replacing the array of integers…
-
3
votes2
answers373
viewsJava square (geometric figure)
I have an exercise that is to form a square with the number we are given. Here’s the code I made: int altura=5; int largura=5; for(int i=0; i<altura; i++) { for (int j=0; j<largura; j++) {…
-
3
votes1
answer221
viewsAlgorithm for connecting dots on a graph with curved lines
I need to develop an algorithm that connects dots in a way nonlinear, that is, with smooth curves, as in the image below: The problem is I can’t find the best solution, whether using Bezier curves,…
-
3
votes1
answer485
viewsExercise Algorithm Given the values of x real and n natural positive, calculate
Given the values of x real and n natural positive, calculate: S = (x+1)/1! + (x+2)/2! + (x+3)/3! + ... + (x+n)/n! So far what I’ve done is this: leia x leia n nFatorial = 1 contadorFatorial = 0…
-
3
votes1
answer776
viewsWhen and where to use the terms: time complexity, space complexity?
I’m using the book Data Structures: Algorithms, Complexity Analysis and Implementations in JAVA and C/C++ as it helps with practical implementation examples. In chapter 1 there is the following…
-
3
votes1
answer408
viewsDepth Search with Prolog - how to limit depth?
I am implementing an in-depth graph search in Prolog, I already have the following: %arestas: edge(c4,b4). edge(b4,b3). edge(b3,a3). edge(b3,c3). %determina que o grafo é nao direcionado edge(V1,…
-
3
votes0
answers470
viewsMonte Carlo methods in C++
This is the code I created to calculate in C++ using the Monte Carlo methods, the average distance between the points evenly distributed in a cube. I don’t understand why in the output file…
-
3
votes1
answer2536
viewsHow to increment a variable in Python?
I’m trying to make a show where he throws a letter on the screen you press it and supposedly you should get a point so I know this is probably a really stupid question, but I tried it in a lot of…
-
3
votes2
answers4333
viewslist, max/min in python
Hello, I need to make a python algorithm that reads a text file .csv which contains literally 5 million numbers and I need this algorithm to tell me which is the smallest and which is the largest…
-
3
votes6
answers2258
viewsExercise: loop and for
Run a function called passandoPor printing on the console "here I have the value of x" where x will be the value of i for each iteration, for each value from 0 to 3. The code I made was this below!…
-
3
votes1
answer77
viewsConfirmation code
I wanted to make a scheme to confirm a question. If the answer was Yes to the question, an ok message would appear. If it was No or different from Yes, I would ask if the person would like to…
-
3
votes1
answer77
viewsCopy and split a List in Python3, Merge Sort
I was trying to write the merge sort in python on my own, but returned a list nothing to do with several repeated numbers. When checking the solution code online, I was left with doubts about how to…
-
3
votes1
answer73
viewsIdentify accented letters and print a warning
I need to make a program that accepts only letters without accent, and for that I’m trying to do something that identifies a letter with accent and then print a warning about the error, but when I…
-
3
votes1
answer169
viewsReturn function of the next ASCII character in C
Do a function: strShift() that receives a string with alphabet letters and returns a new string with letters replaced by their successors in the ASCII table. For example, "Ana" returns "Bob" and…
-
3
votes2
answers194
viewsCondition to continue loop while invalid value
I wanted to know about this code: Algoritmo "Brincadeira2Ou1 " Var A, C, P: inteiro Inicio A <- 0 C <- 0 P <- 0 escreval ("(=====================2===OU===1=====================)") escreval…
-
3
votes1
answer93
viewsCHALLENGE: Spline algorithm(s) with derivative continuity(s)
It is known that a polynomial fn:x->y=c0+x*c1+x²*c2+x³*c3+...+x^n*cn can meet the N=n+1 conditions and from n=1 there is convenience to use in Spline formulas, for example f1 can meet the…
-
3
votes1
answer510
viewsBest worst case sorting algorithm
I want to know which algorithm has the best performance when dealing with its worst case compared to others dealing with each with its own worst case, all applied in array ordering. To better…
-
3
votes1
answer66
viewsVisualg G Algorithm
Ask for a person’s name and sex. Present at the end how many people are male and how many are female. The program terminates when user type ORDER in person name. Can someone help me? Every time I…
-
3
votes2
answers116
viewsHow to get the only different value inside an array in Javascript?
I saw many questions showing how to get unique values in an array, but none solved my problem. I get an array like this: [ 1, 1, 1, 2, 1, 1 ] I want to determine the unique value within it, which,…
-
2
votes2
answers110
viewsSorting does not work
I had to implement my own Sort, using Selection Sort. However, the simple code (I analyzed several times, and for me it is correct) gives strange results. template <typename T> void…
-
2
votes1
answer130
viewsInput bugging for no reason
I made a program that computes (by a DB itself using fstream) patients of a hospital. It has functions to output (one only for ostream using the iomanip and another to ofstream and fstream) and…
-
2
votes1
answer139
viewsDoubt in the complexity analysis of an algorithm
I need to know how to compute the complexity of this algorithm using the recurrence equation. public int qdr(int x, int n) { if(n == 0) return 1; else return x * qdr(x, n-1); } It is a recursive…
-
2
votes1
answer2887
viewsHow to make an algorithm to turn capital letters into lowercase letters?
I need an algorithm that accepts a string or literal expression in uppercase or lowercase. Example: leia(nome) Independent of entry: So-and-so, so-and-so or SO The output of the code escreva(nome)…
-
2
votes1
answer1859
viewsRead each existing Line in Stringbuffer or String
I have a text with the following format: Data Valor 20140901 278 20140902 248 20140903 458 20141004 545 20141005 125 20141106 1020 20141207 249 It is stored in an object of the type StringBuffer and…
-
2
votes0
answers816
viewsPhilosophers' Dinner in Python
I wonder if anyone has implemented the python Philosophers' Dinner algorithm. I need to do it, but only find examples with implementation using thread and need to do without using thread.…
-
2
votes1
answer196
viewsConverting a. NET algorithm to JS
Fellas, I’m having a little problem converting an algorithm. In the algorithm in .net i have the following conditional structure: if (')' == caracter){ String item = pilha.Pop().ToString(); while…