# LaVOZs

The World’s Largest Online Community for Developers

'; Newest 'algorithm' Questions - LavOzs.Com

# Questions tagged [algorithm]

An algorithm is a sequence of well-defined steps that defines an abstract solution to a problem. Use this tag when your issue is related to algorithm design.

• ### Quadratic formula outputting 0 and -0 regardless of the terms given

I am trying to make a program to find the zeros of any given trinomial, the formula seems right but I don't know why the output is always -0, 0. I thought it was a compiler or IDE error but nope, same ...
• ### Algorithm for necessary / sufficient conditions

I have a set of conditions each of which can be one of Optional, Necessary or Sufficient. Clearly the set is met if any of the sufficients are true. And if all of the necessaries are true. (Optionals ...
• ### Maximum weight independent set on non-tree representations

When attempting to derive the maximum (largest size) independent set on a graph of nodes, a solution can be arrived when the graph is a forest/tree structure. The general pseudocode for this ...
• ### binary search recursive returns none

I was trying to write binary search in python. What i write is : arr = [6, 13, 14, 25, 33, 43, 51, 53, 64, 72, 84, 93, 95, 96, 97] def binarySearch(arr, low, high, key): if(low <= high): ...
• ### Algorithm to find the shortest time needed to solve problems in order to get the given total points needed [closed]

In a competitive environment, there are different types of questions available. Easy, medium, hard. And each of these questions have a pre determined point for the questions for that level. Also each ...
• ### Find all word combinations from a dictionary which can spell a given word

Dictionary = ["an","out","per","former","for","mer"] String = "ANOUTPERFORMER" RESULT = ["an-out-per-former","an-...
• ### Creating regions polygons matrix from 2D set of points

I have a set of points in 2D P(x,y) in Matlab that divide unit circle into regions. I want to create matrix with regions R(r1, r2, ...,rn) that cover unit circle area. Regions that divide unit circle ...
• ### Your New Year Chaos Challenge Solution in Python

This is a practice question, so it is not part of an actual test. I'm trying to understand the structure of the algorithm and I have developed a logic so far, however, I'm missing something somewhere ...
• ### What is the time complexity of computing the Nth fibonacci number with dynamic programming?

I recently solved the time complexity for the Fibonacci algorithm using recursion. This is a standard solution with a time complexity of O(2^n). I was wondering if you were to use a DP algorithm, ...
• ### Verilog bug inside of non-restoring division module

I wanted to make a non-restoring Division algorithm. Everything compiles, but there is one issue, my Testbench says, that the simulation has failed in my attempt. But watching the waveform data it ...
• ### How binary search is faster than linear search?

We need a sorted array to perform a binary search in that case the time complexity already became greater than the linear search, so isnt linear search a better option in that case?
• ### Swap method fails to swap two adjacent node (single Linked List)

The following is my console log output... The user inputs the integers to add, and the index of the element they wish to switch: enter integer to add: 4 enter another integer to add: 5 enter another ...
• ### Determine whether there is a path from vertex u to v passing through w

Given an undirected graph G = (V, E), with three vertices u, v, and w. Describe an algorithm to determine whether there is a path from u to w that passes through v. Don't comment if this is from some ...
• ### I am getting Null Pointer error in my Java code [duplicate]

Please check in the code there is silly issue I guess and it is not working properly. I used codechef to do my work and it really bangs my mind now, Please check in the code there is silly issue I ...
• ### Matching array indices in Arraylist with Python

I have a arraylist. I want to matching arrays and add last column uuid. To do this, the 2nd and 3rd indices in the array must be the same. They can be equal to 2 -> 3 or 3-> 2. I want to explain ...
• ### Why is the space complexity for this algorithm to check if an array has all unique characters O(n)?

In the book "Cracking the Coding Interview", first exercise says "Implement an algorithm to determine if a string has all unique characters (not using additional data structures)". ...
• ### How can you improve the space and time complexity Big(0) of when nested loops are needed?

The objective is to create a function that accepts two arguments: and array of integers and an integer that is our target, the function should return the two indexes of the array elements that add up ...
• ### Python “Meeting Finder” algorithm giving wrong output

Im working on an application in python that finds free days in given bounds, with given persons times in which they aren't free. It works by creating a list of possible days and then removing the days ...
• ### How to write a power function in Lisp(scheme)? What's wrong with my program here?

(define (pow b n) "YOUR-DOC-HERE" (cond ((= n 0) 1) ((even? n) (pow (pow b (/ n 2)) 2)) ((odd? n) (* b (pow (pow b (/ (- n 1) 2)) 2))))) (define (pow b n) &...
• ### I want to extract out all the <link> tags from this XML tree using java

I have an XML file which has a 3 level deep XML tree. I want to extract all the <link> tags from that tree. The challenge here is that tree is dynamic and can be any level deep. I have already ...
• ### How a std::unordered_map search algorithm is implemented?

I understand that if it is necessary to implement a search in an ordered set, then we compare the data of each "cell" of the binary tree, which is the structure of the ordered set using the &...
• ### A-star search. Sliding tile puzzle. Which heuristic is this?

I am currently trying to learn how to code a sliding tile puzzle with 8 tiles in Python 3. In one of the resources I've found, the person explains the Manhattan distances heuristic, but then goes on ...
• ### Optimal algorithm for a solution vector that minimizes its own matrix-vector product with a given sparse matrix

Given A, a sparse matrix of binary values with 36 columns and n rows (where each row is random with the only constraint of each having at least 1 one and at most 12 ones), is it possible to find an ...
• ### Finding the longest path in a network based on vector edge weights

I have this road network with elevation data for every POINT and a calculated grade value for every LINESTRING: Note: points plotted on graph are my own they do not represent the nodes on the graph ...
• ### Running Hackerrank code locally besides online [closed]

I run the following code in Hackerrank, but I also want to debug and test code locally using Eclipse, etc. So, what is the shortest way to run a Hackerrank code without modifying least? In the ...
• ### Why do we have double hashing function as [(hash1(key) + i * hash2(key)) % TABLE_SIZE] but not simply as [(i * hash2(key)) % TABLE_SIZE]?

I learned the notation of double hashing [(hash1(key) + i * hash2(key)) % TABLE_SIZE] couple days ago. There is a part I couldn't understand after thinking about it and searching for answer for days. ...
• ### Count unique users in last 60 mins per page with Redis HyperLogLog

I’m designing an algorithm to count unique users on a set of pages, based on a 60min sliding scale So it needs to find unique IPs (or tokens) that have hit a particular page and total up those hits ...
• ### How would you break this problem into subproblems and use dynamic programming?

I'm working on an old contest problem from 2019 from this page: https://dmoj.ca/problem/ccc19s4 You are planning a trip to visit N tourist attractions. The attractions are numbered from 1 to N and ...
• ### Running code in Hackerrank and Eclipse using input values [closed]

In Hackerrank I cannot make the code work that I run in Eclipse. I also look at Using STDIN for inputs and STDOUT for outputs, but not found a corresponding page for Java (there are some examples for ...
• ### Import existing users from custom auth system (algorithm argon2i)

i tried to import our users from a symfony Mysql app to firebase auth with the auth:import feature. Our application use the argon2i hashing algorithme and it's not listed in the support list. I can't ...
• ### Which algorithm(s) solves this optimal assignment problem?

I am looking for an optimal assignment algorithm for the following problem. There are n students and there are m mentors (m <= n) and 5 research topics. Each student have preferences(0 <= some ...
• ### Euler project problem #1 with Recursive JS

I recently decided to try my hand at the Euler project and already having issues with the first problem: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9....
• ### How can I recover a differed time series or some data to original?

So when I was training a LSTM network with Keras, in order to decrease the MAE, I differed the data for several times， and the output was already exact enough. However, the output was still differed ...
• ### Unreachable statements during recursive function call C [closed]

#include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <math.h> int function(int n); int main () { int i = 0; int n = 0; n = function(i); printf(...
• ### What's The Best Logic For Sort an Array?

Let's Say We Have an Array Of Int : int[] array = new int; and inside of this array we have a 5 randomly numbers.. array = {10,5,7,0,3}; What Would be The Best Way To Change That array To This ...
• ### Minimum Possible Integer After at Most K Adjacent Swaps On Digits

Given a string num representing the digits of a very large integer and an integer k. You are allowed to swap any two adjacent digits of the integer at most k times. Return the minimum integer you can ...
• ### How to calculate line from a set of polygon points?

Let's say now I have an array that used to describe the shape of a polygon: [ [0.0, 1.0], [0.5, 1.0], [0.5, 0.3], [1.0, 0.3], [1.0, 0.0], [0.0, 0.0] ] As shown on diagram above, the blue ...
• ### Guys I want the implementation of a problem “k-nearest distance from a point” [closed]

Guys I was having issue in implementing a problem using java. Problem called as "k-nearest distance from a point x". Here I want to solve the problem in nlogk and not nlogn so I have decided ...
• ### Algorithm - Fomula Reading

I am trying to find out what is the meaning of these two following lines N + M log N (M + N) lg* N Can someone suggest me what is the meaning and where to learn to read this ? Thanks. Updated content ...
• ### Recursive function works, but unable to memoize

I am solving this dynamic programming question on LeetCode.com: https://leetcode.com/problems/target-sum/ You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have ...
• ### Working through pseudocode to make functional code, bad sorting algorithm

I am working on a practice problem called sortBad. Here is the pseudocode: sortBad(A[0···n − 1]) { if (n = 2) and (A > A) swap A and A else if (n > 2) m = ⌈𝛼 ...
• ### How write this code without function and make more simple in C++? [closed]

how can i write this code in a simple way, without function and write all in int main() ??? I need find the sum of two elements of the array as close to zero as possible in C++... Examples: Input: 5 1 ...
• ### Using sorted() to find the unique value in a list

I have a list of integers and I am trying to find the unique value of a list. I can't use count() because it exceeds the time limit so I figured that using sorted() and see if the element i is not ...
• ### Find number of steps to reach end of cave?

Input 8 ######## 1 2 Output 3 Explanation N=8 length of the cave.# means its safe to enter. * means not safe to enter. r1 = 1 and r2 = 2 Lets start from i=1. There are 3 ways to reach the end of N. ...
• ### How to calculate the sum of dice whose value combined amounts to an input number

I am supposed to do a score calculator in Java for a dice game that rolls 6 dice (with 6 faces). The score is supposed to be calculated according to a list of options that the user has available. ...
• ### Is my postorder traversal of this graph correct?

I am trying to implement an algorithm that requires a post-order traversal. Here is my graph (taken from here, pg. 8): When I try to do a postorder traversal of this, the order I get is: [3, 2, 1, 5, ...
• ### Haskell Quick Sort implementation (how to obtain the best performance?)

I am currently reading about functional data structures and algorithms and I tried different quick sort implementations. I noticed, however, that there is a lot of variation in their performances. ...
• ### How to print only once from all the parallel processors?

I'm running a parallel program in Fortran and using MPI. There is an algorithm that is executed by only certain parallel processors which contain a flag. I want to print a statement only once but I ...
• ### Master theorem for worst case quicksort

I know how to calculate the master theorem and I managed to calculate it for best and average case. T(n) = 2T(n/2) + Theta(n) The worst case equation is T(n) = T(n-1) + Theta(n) If I am correct a is 1,...
• ### Algorithm to extract subgraph of graph induced by a set of nodes?

I have an undirected graph G=(V,E) and I want to extract a subgraph of G induced by a set of nodes which is subset of V. Now I am looking for the algorithm to do this in Python?