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
-
2
votes1
answer3712
viewsHow to scroll through a 2-dimensional matrix in C and display?
In this code, I have a two-dimensional array(array), I started and I want to print with the printf, but I don’t know how: #include <stdio.h> #include <stdlib.h> int main() { int i; int…
-
2
votes5
answers11991
viewsHow to validate and calculate the control digit of a CPF
How does the algorithm that calculates the digit of a CPF (Cadastro da Pessoa Física Brasileiro) work? And how is this calculation used to validate the CPF? If possible, I would like examples in…
-
2
votes3
answers161
viewsHow can I make this code more functional in Javascript?
This code solves the problem of finding the in anth prime between 0 and 10,000: function PrimeMover(num) { var counter = 0; var primes = []; for (var i=2; i<=10000; i++){ for (var j = 2; j<i;…
-
2
votes2
answers1768
viewsAlgorithm in C - Primes
The program has to do a check of prime numbers, where the user type a number and the program finds the largest prime number before it. the problem with my program is that it doesn’t check until the…
-
2
votes1
answer1494
viewsRemove odd numbers from a stack
In C how is it done to remove only odd numbers from a stack? I was thinking of removing item by item and moving to an array, but the stack size is not given.
-
2
votes1
answer709
viewsAdd typed values without using array
Prepare a program that asks the user to enter 10 values, add this results and present on the screen. I could only do it with one array whole. #include <stdio.h> #include <stdlib.h> int…
-
2
votes1
answer233
viewsAlgorithms and programming
What I need to learn before I go to classes?
-
2
votes1
answer114
viewsavoid stackoverflow while reading and popular relationships
I’m making a library that populates any model with random values, to be used in tests, but it turns out that when I have a relation like below, I get a StackOverflowException Author @Entity public…
-
2
votes1
answer623
viewsDecomposition into primes
Hello folks I’m learning C++ for Data Structure subject and there is some error in the code that is creating an infinite loop. #include <stdio.h> int fatores(int a[], int n, int *x) { int…
-
2
votes2
answers6996
viewsProgram that sums/multiplies 2 numbers and what’s between them and prints
I believe the logic of this programme is right, but the result is wrong. Make a program that receives two X and Y numbers, being X < Y. Calculate and show: the sum of the even numbers in that…
-
2
votes1
answer464
viewsPartial sum of elements of a vector in O(n) or O(log n)
I have an A vector of size n. I have to calculate the partial sum of each element and write in the matrix B[i,j]. Pseudo-code shows a solution O(n 2); For i = 1, 2, . . . , n For j = i + 1, i + 2, .…
-
2
votes2
answers1818
viewsSearching for a matrix within another matrix in Java
I need to compare two two-dimensional matrices (int[][]) of different sizes, the two being formed by integer values (1 or 0), to verify if there is the smaller matrix within the larger matrix.…
-
2
votes1
answer1846
viewsHow to calculate NPL (NPV) and IRR (IRR) using Javascript?
I am with a TCC project of economic viability using PHP + Javascript, because well, I can calculate all the indicators I need, except the VPL (NPV) and the TIR (IRR), I saw a library called…
-
2
votes4
answers16229
viewsHow to add entries to a dictionary?
How to add user-provided entries to a dictionary? For example: Entree: 1 abcde 2 adecd 3 aaabb The created dictionary would be: dicionario = {'abcde' : 1, 'adecd' : 2, 'aaabb' : 3} or dicionario =…
-
2
votes1
answer4199
viewsHow to stop a loop using the input provided by the user?
I’m writing a program that receives entries and creates a dictionary from them. I need the loop I use to insert the entries in the dictionary to be broken when the entry is "9999", but it is not…
-
2
votes3
answers425
viewsHow to define a function that calculates the lowest speed?
The program must have a function that calculates the lowest speed among those calculated from the data provided. The user must provide as input, 9 values, of 3 in 3, which correspond to speed,…
-
2
votes2
answers581
viewsDifference and sum of DATETIME column
I have a table called chamado_processos with the following structure and data As you can see one of the columns of this table called dt_processo is a field DATETIME and the column tp_processo…
-
2
votes1
answer504
viewsCalculation of Time Estimate
I am making a calculator for calculating Time for any distance on my site, but my question is in the execution algorithm. The formula is as follows:: tempo previsto = tempo real x distância prevista…
algorithmasked 8 years, 5 months ago IvanFloripa 637 -
2
votes1
answer238
viewsWhat happens to variable i in this algorithm? Sequence inversion algorithm
Good evening. I started to study data structure in support of the book Data Structure and Algorithms 2nd ed (SZWARCFITER/MARKENZON). The first algorithm of the book deals with reversing the elements…
-
2
votes1
answer1158
viewsUsing LOG in VISUALG Functions
When using visualG LOG there is a problem, I need to divide a value typed by the user, by log 2 in base 10. Only he doesn’t make it he’s wrong. funcao menu_8():inteiro var logaritmo :real inicio…
-
2
votes0
answers535
viewsDynamic Javascript date mask
Recently I had to perform a mask for dates with automatic filling, I searched a lot and did not find answers that solved my doubts. When typing '4' in the first field, the '0' should already be…
-
2
votes1
answer195
viewsSearch text in a String as a "like"
I want to do a text search, like the ones I do in Mysql. Ex: LIKE "9%4" I tried to implement a find_if(), but without success. #include <iostream> #include <string> #include…
-
2
votes2
answers776
viewsVisualg - Boolean result
I built this algorithm into Visualg: algoritmo "semnome" var inicio se 3 = "a" entao escreva("igual") senao escreva("diferente") FimSe fimalgoritmo And I don’t understand, why the condition is…
-
2
votes1
answer559
viewsIs there an insertion method for binary tree search faster than trivial?
I’m trying to solve this problem in an online Judge. The problem provides N integers that must be inserted, in the given order, into an insertion algorithm of a binary search tree. After Q queries…
-
2
votes1
answer350
viewsProblem in C language, issue with prime numbers
I am solving exercises, in C language, on vectors. The exercise is as follows: Make an algorithm that uses a menu with the following options: sort an ascending 5-position vector, sort a descending…
-
2
votes2
answers116
viewsWord problem with same letters
I’m solving a problem where I get one array of strings with different words, I have to find out for each word (string) which are your friends. Friendly words are those that have the same letters in…
-
2
votes2
answers153
viewsPrint number of nodes in a list
This code below does not work properly, I type 5 knots and was to return the number 5 (total amount of knots entered). It happens that returns me 4. int qtd_no_lista (tipo_lista * recebida) {…
-
2
votes1
answer419
viewsImplementation of ANSI C queue
I have a code (end of question) that allows manipulation of a queue in ANSI C, my question is as follows: The code declares a data type of its own to store the data of the queue and has a function…
-
2
votes0
answers45
viewsAlgorithm to match department, category, and subcategory of a BD with a received string?
From a non-standard string, I sometimes receive the equivalent of department/category, sometimes equivalent to category/subcategory, sometimes equivalent to department/subcategory, sometimes…
-
2
votes1
answer183
viewsSelection Sort - Is that correct?
I implemented a logic of Selection Sort and would like to ask if it is correct. Because at the end of the process the result is expected, but went to make a real proof and found several algorithms…
-
2
votes1
answer92
viewsAlgorithm for AST
I’m creating a programming language in C++. I’ve made a simple lexer, which works perfectly for now. out 5 + 7 * 3 My lexer turns it into: kw: out num: 5 op: + num: 7 op: * num: 3 nl Now I need to…
-
2
votes2
answers156
viewsAlgorithm simulation of taximeter
I’m creating a Javascript algorithm to make the calculation similar to that of a taximeter, where you have the time of flag 1 and of flag 2. function test(hora,bandeira1, bandeira2) { if (hora >=…
-
2
votes1
answer555
viewsBacktracking in Python
I’m trying to find a subset, of size M, of binary strings of length n, where any string has a distance greater than 2 for any other string in the subset. Where the distance between two strings is…
-
2
votes1
answer562
viewsCalculation of Shannon entropy in network traffic (saved in CAP file) using Python
I have a dump file (CAP format) of a network traffic capture made with Ubuntu’s tcp dump. Until a certain time, it is a traffic free of attacks. Then, begin a series of attacks of type TCP SYN…
-
2
votes3
answers314
viewsHow to count the number of candidates on this page ? Python 3.6
Simple thing. I need to count how many candidates there are in the table of this page, for example : http://www.ufjf.br/cdara/sisu-2/sisu-2017-1a-edicao/lista-de-espera-sisu-3/?…
-
2
votes1
answer6506
viewsHow to put string and variables together in Portugol?
Hello, I am learning English for academic purposes and I am having problems in a code I am doing. But when I run it, it rotates until it’s time to average. Then he says he hasn’t found the student…
-
2
votes1
answer790
viewsWhat is the best way to work with java queues?
In which scenarios is a queue required? What is the advantage of using this algorithm?
-
2
votes1
answer106
viewsIs there any sort algorithm that actually runs on O(n)?
If such an algorithm exists, how is it possible for an algorithm to sort a data collection in linear time even if it falls in the worst possible case (reversed)?
-
2
votes2
answers3541
viewsAlgorithm to calculate lifetime in days
He wanted to know how many days I have lived between the date I was born to this day, including leap years. This is how I’m doing, but I don’t know how to finish: #include<stdio.h>…
-
2
votes1
answer771
viewsFibonacci sequence
I need to do an exercise on the Fibonacci sequence: Each new term in the Fibonacci sequence is generated from the sum of the previous 2 terms. If we start with 1 and 2, the first ten numbers will…
-
2
votes1
answer269
viewsEliminate cycles in graph by removing fewer vertices
I wonder if anyone knows if it is possible to eliminate all cycles of an undirected graph (n vertices) weightless, removing the smallest number of vertices, in time O(n²)? Note: The graph can be…
-
2
votes2
answers2462
views -
2
votes1
answer4559
viewsDivisible - Portugol (VISUALG)
I have the following question and below what I have tried but it is not just showing the divisible numbers that is my intention. I’m doing the test by typing the number 8, the correct one was for…
-
2
votes6
answers7179
viewsSimple Solution for Fibonacci Algorithm
I have this statement in hand: Given the Fibonacci sequence 1 1 2 3 5 8 13 ... n, write an algorithm to generate the sequence to the nth term, which must be provided by the user. For example, if the…
-
2
votes1
answer183
viewsQuicksort vs Radix-Sort
I’d like to know why Quicksort is more diffuse than Radix-Sort. Since the quicksort uses the comparison and Radix-Sort not the second can be faster than the(nlog(n)), and actually it’s O(Mn) where m…
-
2
votes1
answer565
viewsFunction to check that all elements of a variable array are null
Suppose I have one array in which each element of this array is a variable that stores a string within it. Example: error{ [nome] : null; [sobrenome] : "sobrenome inválido"; [estado] : null; } I’d…
-
2
votes2
answers6394
viewsSum of even numbers and multiplication of odd numbers in a range
Read two numbers being y greater than x, calculate the sum of the numbers pairs of that range of numbers, including the numbers typed; calculate and show the multiplication of the odd numbers of…
-
2
votes1
answer6600
viewsHow to calculate the use of a football team in a championship?
I’m looking to do a media calculation of a football team in a certain league, for example, my team played two matches and won one. He would have 3 points from 6 points played and a 50%. public final…
-
2
votes1
answer253
viewsFind position in an array by position in the array?
If I have an array, ex: [1, 2, 3, 4, 5, 6, 7, 8, 9] and I transform this array into an array, e.g.: y[0] y[1] y[2] x[0] = 1 | 2 | 3 --------------- x[1] = 4 | 5 | 6 --------------- x[2] = 7 | 8 | 9…
-
2
votes1
answer50
viewsAlgorithm C. Why does the string "Why" return and does not return numerical values?
I wrote an algorithm in C to write on the screen ordered pairs of a function, with input of x integer numbers. int main(int argc, char *argv[]) { int x,i; x = -1; do{ system("cls");…