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
-
0
votes1
answer3451
viewsHow can I compare values in this calculator algorithm
The objective of this algorithm is to be a small calculation game, where it compares the result of the operation informed by the user with the correct value of the same and so say whether or not the…
-
0
votes2
answers559
viewsAlgorithm that reads three numbers and displays the result of the sum of the first two and multiplied by the third
Follow my code below, however does not return correct the result, if I put as input 2, 2, 3 was to appear 12, but appears 6 public class Exercicio2 { @SuppressWarnings("unused") public static void…
-
0
votes2
answers1105
viewsAlgorithm implementation in Visualg
Make a program that receives two numbers and perform one of the operations listed below according to the user’s choice. If an invalid option is typed show error message and end script execution. The…
-
0
votes0
answers47
viewsApply rates according to the number of books sold
I have the following problem: A publisher pays x% to the author and it has several levels. If the author sells up to 1000unid books he receives 10% of the sale. Between 1000unid and 5000unid…
-
0
votes2
answers86
viewsTargeting failure in Mergesort
I tried to recreate the Mergesort algorithm in C++, but when compiling, the error "segmentation fault" appears. Here is the code below. What could I be doing wrong? #include <iostream> using…
-
0
votes1
answer125
viewsHow to verify that all elements of a vector are between - 4 and 4?
I want to compare whether all elements of an array are between -4 and 4, if so, the algorithm will execute the method. for(int i=0; i< j; i++){ if(vet[i] > -4 && vet[i] <4)…
-
0
votes1
answer88
viewsWhy are you not entering the if?
I want to perform an operation if the 2° position of a string is higher, but it is not entering the if, and I think the if is not correct. Example: digital user 4A6 then in this string the 2°…
-
0
votes2
answers1013
viewsGenerate random numbers in java, store in a vector and sort them
I need to generate 100000 numbers, store them in an array and sort them using the Bubblesort algorithm, is appearing the error "Exception in thread "main" java.lang.Error: Unresolved Compilation…
-
0
votes1
answer1573
viewsCounter in PHP
I would like to be making a contactor in PHP in which I may be setting a time to be appearing the next number. For example, the number 1 appears and then the number 2 replaces the number 1. It would…
-
0
votes0
answers174
viewsEXCEL: Form filled in specific places
In this image I have 7 "blocks" to be filled via form, they are side by side. As I do in vba a function that fills these blank fields of TM1 and TM2 automatically, I want to include this function in…
-
0
votes1
answer71
views -
0
votes0
answers55
viewsMonitor treadmill running, with mobile phone
Context: Using the sensors of the mobile phone, need to set a running pattern on the treadmill, to know the average speed and distance traveled. I created a program to print sensor values on the…
-
0
votes2
answers467
viewsCalculation of word similarity with Java
For two string A and B, we define the similarity of these strings is the length of the prefix that is common to both. For example, the similarity of strings abc and abd is 2, while the similarity of…
-
0
votes1
answer294
viewsBubble Sort in Python3
def bubble_sort(list): for i in range(len(list)): for j in range(len(list)-1): if list[j] > list[j+1]: list[j], list[j+1] = list[j+1], list[j] else: continue I just made this Bubble Sort, but I…
-
0
votes1
answer235
viewsCode problems from a C priority list
I am creating a priority list in C (topological ordering) using vectors and within these vectors a chained list pointing out who has to come before whom. It’s just that there’s a glitch in the…
-
0
votes4
answers261
viewsSequencia Fibonacci
I’m doing a selection process, and they’re asking me to create a Fibonacci sequence, only I don’t know how to create, I even tried (code below) but I didn’t get any results. I have to return element…
-
0
votes1
answer1026
viewsPrinting binary tree graphically in C
Last week I was working on this code that prints binary tree graphically but I didn’t understand very well its way of using or if there is a bug because I type in the amount of nodes and the…
-
0
votes2
answers109
viewsCalculation of T(n)
Could someone explain to me how to calculate the T(n) of this algorithm being n >= 0? I’ve seen videos and classes and I can’t understand how this calculation works. T(n) of an algorithm is how…
-
0
votes1
answer2659
viewsC++ program error: "[Error] expected Primary-Expression before 'F1'"
Hello, good evening everyone! I have a problem in my occurrence function of a number in the vector. The mistake: [Error] expected Primary-Expression before 'F1' Could someone help me solve this…
-
0
votes1
answer152
viewsImage Majority Algorithm Analysis
Algorithm help A vector with n images A= [1...n] has a majority image I if more than half of the vector images are equal I. You can use A[i] = A[j] to verify that the images at positions i and j are…
algorithmasked 7 years, 1 month ago Matheus Francisco 650 -
0
votes2
answers1041
viewsHow to optimize plot calculation on "broken" values
I have an application that, depending on the format of the portion that the user selects, the system will return the amount of that portion. For example: Assuming an order of R $ 50.000,00 in two…
-
0
votes0
answers570
viewsAlgorithm Shellsort C++
Good afternoon, you guys! Can anyone help me by explaining this code in c++: #include < stdlib.h> #include < stdio.h> #include < ctime> void shellSort(int numbers[], int…
-
0
votes2
answers120
viewsCollecting data from an array
I’m having a workout for college but I’m lost in my logic and how to solve it. I have to collect the game results and set the score for each result. the winner takes 3 points, a draw guarantees 1…
-
0
votes1
answer266
viewsAlgorithm for reading multiple numbers in PHP
I have a question about how to do the following exercise in PHP using HTML forms: Make an algorithm that reads a sequence of integer numbers. If the user type a negative number the algorithm should…
-
0
votes3
answers98
viewsError returning lower value
I’m trying to return the lowest value using the va_args, which supports several arguments, but it always returns the same number: -13227; #include <stdio.h> #include <limits.h> #include…
-
0
votes1
answer469
viewsHow complex is the algorithm?
I’m learning how to calculate the complexity of algorithms using Big-O notation, but I’m having difficulties with the algorithm below: a=0 for(int i = n; i>0; i -=2){ for(int j = i+1;…
-
0
votes1
answer278
viewsIn R, how to find out if two vertices are adjacent from an adjacency matrix
This is the adjacency matrix, how to find out (implement an algorithm) if the vertices 2 and 3 are adjacent using R?…
-
0
votes1
answer307
viewsA vector in C, which updates the values in real time, according to the numbers reported
#include<stdio.h> #include<stdlib.h> #define tamanho 5 struct test { int vetor5; }casa[tamanho]; //funcão para o vetor da struct void recebe (void) { for (int p=0; p<tamanho; p++) {…
-
0
votes2
answers45
viewsContent of the array is not being printed, but reference to the object
Hello, I’m making an algorithm that prints only the repeating elements, e.g.: {2,2,3,4,5,5} -> {2,5} I don’t know if my algorithm is correct, but I can see the array itself, it appears something…
-
0
votes2
answers3022
viewsRepeat number check on matrix in C
I am not able to find the error of this code. I did it to check if in a 4x4 matrix the number being inserted already exists. For some reason that I do not know he accepts the times repeated values…
-
0
votes1
answer72
viewsProblem with weighted average logic
According to all the sources I have consulted, several to be sure, the weighted average is calculated as follows:: Add up all the values that have the same weight, then multiply this sum by the said…
-
0
votes1
answer796
viewsRead file and sort words alphabetically (with removal of special characters)
I’ve been trying to find the mistake for a while, but I’m not getting it. The program consists of reading a . txt file with the contents below, for example: home-orange, otolaryngologist flower…
-
0
votes1
answer132
viewsPreorder Iterative - Binary Search Tree
I have a function that runs through BST (Binary search Tree) recursive pre-order. The function is the following: public Iterable<Key> preOrder() { Queue<Key> queue = new…
-
0
votes1
answer531
viewsLoop repetition in programming logic algorithm
I have doubts about this: Write an algorithm that asks for the age of several people (USE REPEAT). Please report the total number of people under 25 and the total number of people over 50. The…
-
0
votes1
answer422
viewsList inside JS list
Hello, good morning! I’m making an algorithm in JS where I take all the paragraphs of a text and put it in an array, after I take every word of that same paragraph and put it inside another array,…
-
0
votes1
answer108
viewsDoubt regarding the Minimax algorithm
The Minimax, by definition, is great if both players act great, right? However, can we say something when one of them plays great and the other doesn’t? In the case of the game of old, as the space…
-
0
votes2
answers80
viewsProblem with neighboring positions in C++ arrays
#include <iostream> using namespace std; int main(){ int myVector[] = {2,6,4,1,9,5,7,3,8,0}; int tamanhoVetor = sizeof(myVector)/sizeof(myVector[0]); //Imprime for (int i=0;…
-
0
votes1
answer98
viewsRemoval of Duplicate Elements : divide and Conquer
I’m having trouble getting an algorithm that removes duplicate elements in an array (can only be integers), which uses the method Divide And Conquer. I am in need for a college job, and…
-
0
votes1
answer72
viewsI need to return in % the value of how many numbers are positive, the amount of zero and negative numbers, in this order, but my code is wrong
function maisMenos(valores){ var qtd = valores.length; var neg = valores.filter(nr=> nr < 0).length; var pos = valores.filter(nr=> nr > 0).length; var zer =…
-
0
votes1
answer197
viewsI want to enter a number and it’s multiplied from 1 to 10
package exercicio5; import java.util.*; public class Exercicio5 { public static void main(String[] args) { int i,n1,x; Scanner ler; ler = new Scanner(System.in); for(i=1;i<=10;i++){ x=n1*i;…
-
0
votes1
answer274
viewsProblem creating Minimax in chess game
I am coding a chess game only in pure C. The game itself is ready, I am for some time trying to develop the algorithm of Minimax. Currently the algorithm is almost ready, but it is not returning and…
-
0
votes1
answer406
viewsVariable never reaches zero using Randi
Could I show you Life: 0 in the Visualg console output? I tried to put Ate(life = 0) but gives infinite loop. If anyone can help me, I’d appreciate it. The version of my Visualg is the 2.0 algoritmo…
-
0
votes2
answers381
viewsAverage input data algorithm
package ifal2; import java.util.Scanner; public class Lista3Questao4 { public static void main(String[] args) { Scanner entrada = new Scanner(System.in); int idade=0, contM=0, contF=0; double…
-
0
votes0
answers23
viewsValue of n in Malba Tahan Chess algorithm
I am in doubt about the value of n in the code, in the "for" below 1 is assigned to the value of n, so it would not be for the first iteration the value of n to be 2? #include <stdio.h> int…
-
0
votes3
answers503
viewsSum of geometric progression terms
I need to do a show that fits a1, q , n (number of geometric terms) to calculate the terms and then calculate the sum of those terms. I was able to calculate the terms, but I have no idea how to…
-
0
votes1
answer42
viewsNumber of co-occurrences in a matrix
I have a question more mathematical than computational. Suppose we have a square matrix M of dimension n², where n is any integer greater than zero. Traversing this matrix, assigning j as an index…
algorithmasked 6 years, 3 months ago Francisco Sobrinho 33 -
0
votes1
answer296
viewsHow do I use the "Math.Max" method in C# without creating a lot of variables?
I’m trying to solve an exercise that’s like this: Make an algorithm that reads the height and enrollment of ten students. Show the enrollment of the highest student and the lowest student And my…
-
0
votes0
answers19
viewsError with multiple IF conditions
The if only proceeds if it’s’m' the person’s sex, if it’s the others with || that I put will not, can anyone take away this doubt? char sexo; float altura, pesoideal; printf("Qual o sexo da pessoa?…
-
0
votes1
answer126
viewsCapicua’s algorithm is not printed as it should
Program to find all Capicua numbers (a number that is read in the same way backwards and forwards) between 10 and 500. I tried to do this but the figures are not being printed. #include…
-
0
votes1
answer133
viewsI’m trying to show 1 up to 10 in visualg,but is giving error in 1 line where theoretically everything is right
Algoritmo "SUPER CONTADOR" // Var N1,cont : Inteiro Inicio repita escreval ("===================") escreval("| MENU |") escreval…