floyd’s algorithm with negatives
This code searches for the shortest paths in a graph using Floyd’s algorithm. It works great for positive numbers. But when negative ones appear, it begins to make cycles and loops. How to fix it?
What’s the WCTC of this algorithm?
void M3(int N, int M){
Time Complexity of Super Simple GCD
When I need to calculate the greatest common divisor of two integers, instead of using Euclid’s algorithm or the binary GCD algorithm, I will sometimes use this super-simple algorithm:
Heavy-light decomposition algorithm modification
Let the weights in the tree be not on the vertices, but on the edges. Show how you can solve problems using HLD in this case
.
Maximum valued expression of operands and operators, where expression respects order
Operands and Operators are arrays containing a sequence of numbers and a sequence of
mathematical operations such as addition, multiplication. Expressions are formed by using
all operators and required amount of numbers, in their original order. They are evaluated
by bracketing from the right end.
Example expression: (3*(5+9)) which evaluates to 42. Invalid
expressions: (3+(5×9)), ((3×5)+9), (1x(3+5)) .
Is there an efficient algorithm for this problem? If yes then what is it?
Smaller exicographically sequence of advertisement that can be formed from given pairs of advertisements
Recently I gave Flipkart Online assessment and I was stuck at a question for a very long time. The question goes like this. An advertisement company has array of pairs of advertisements and each advertisement should be played one after another. It will be beneficial for the company to start from “ABC” advertisement if given. We have to find the sequence in which all the advertisements should be played for once. If multiple such ways are possible give Lexicographically smaller one.
Algorithm to distribute text
Im trying to replicate a algorithm of a game, basically the method should take a text and a number. The method is expected to return an integer array with the number of elements specified by the second argument. The sum of all elements in the integer array should exactly match the length of the text string argument. The challenge lies in the logic, as each element in the array represents a portion of the text string, and the sum of these portions should equal the length of the text string but not orderly.
Lay out paper as square as possible
Given a sheet size, say 210×197 and a number of sheets to lay out, let’s say 12 what is the algorithm that would lay them out in a way that the total width and height are as close as possible? in other words so that the sheets form a shape that is as square as possible?
What ist the difference between n and n-1 in algorithms?
enter image description here
I need help coming up with an algorithm for this problem
You are given 4 parameters