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.

0
votes
0answers
17 views

How to get the pivot point in a sorted rotated array with duplicate elements iteratively?

Finding the pivot point in a rotated sorted array with duplicates using loop. Though I found a solution in suggestion but that was using recursion. I need a solution using recursion. I am stuck with ...
-1
votes
0answers
16 views

How to create an auxiliary data structure to keep track of heap indices in a minheap for the decrease_key operation in c++

I think this is probably a trivial problem to solve but I have been struggling with this for past few days. I have the following vector: v = [7,3,16,4,2,1]. I was able to implement with some help ...
0
votes
0answers
41 views

decision tree implementation in JAVA

I'm trying to implement decision tree in JAVA from scratch based on the following dataset. I am struggling to think of how to represent a decisionNode and leafNode, like which properties to have and ...
-1
votes
0answers
23 views

Is there an algorithm similar to A* that connect to every node?

I'm working on a really irritating piece of code at the moment, and pathfinding seemed to be the best way to get to the next stage of the project. It involves an example of the following matrix: ...
-3
votes
0answers
17 views

Convert postfix expression to expression tree [on hold]

I want this postfix expression to be converted to expression tree using stack data structure 3 4 * 2 / 11 + 5 5 / - 1 - I tried to solve this question but I’m not one hundred percent sure, Help ...
0
votes
3answers
20 views

How to sort ListNode (linked) by its value?

How do you sort nodelist by value without using any library. Example: * Input: 3->1->5->4->2 * Output: 1->2->3->4->5 ListNode.java import java.util.List; public class ListNode { public int ...
0
votes
1answer
27 views

How to group/club elements in a 2D list based on the 1D elements belonging to another 2D list?

I'm new to Python and I have a question on involving data structures and algorithms(which are essential skills that a programmer should have) There are two lists L1 AND L2. L1= [[0.0, 0.22],[0.0, 0....
-1
votes
0answers
19 views

Lowest Scrabble Score Automated Program

I want to develop a program that tries different combinations of words in Scrabble to get as close as possible to the lowest possible total score: https://puzzling.stackexchange.com/questions/80939/...
0
votes
0answers
17 views

How to find the relative Text Size

I am trying to draw text on images with varying sizes. The image is displayed in an ImageView and then drawn on the Canvas. While the Canvas retains the image's original height and width, the image ...
0
votes
1answer
51 views

can anyone tell what's the bug in my quick sort code

can anyone tell what's the bug in my quick sort algorithm? I am using two point 'left' and 'right' to compare with the pivot, and swap nums[left] and nums[right] if when nums[left] > nums[right]. when ...
-1
votes
0answers
29 views

What is the best way to visually display the graph for the Ford Fulkerson algorithm in java [on hold]

I have implemented the Ford-Fulkerson Algorithm in Java now I want to visually display that by using a graph. I have added the capacities of each and every edge to a Two Dimensional array as a matric ...
0
votes
1answer
23 views

Recursion runtimes complexity

I am a little confused about the time complexity of recursive functions. I listed two different functions bellow, they are both doing a functionName() + functionName() recursive call but they do have ...
3
votes
2answers
37 views

Algorithm for Validation of Reference File with Wildcards

I have a file like below, which I want to validate for correctness. The file is used as a reference file for processing some data. I match my input data with ColA, ColB and ColC of this file and ...
-3
votes
0answers
25 views

what is a good knowledge in patterns, data structures and so on? [on hold]

I would like to apply for a position and among 7-8 aspects, there are two I'm not sure how to answer: Very good knowledge in algorithms and data structures Good knowledge of modern programming ...
-1
votes
0answers
32 views

How to calculate exponent of BigInteger?

I'm trying to implement a homomorphic algorithm. For the equality test, I need to do some exponent operation on some BigInteger number. My code for calculating the exponent is: BigInteger g1,...
0
votes
1answer
22 views

Translate recursive function calls into cost-efficient representation

I am trying to use some static analysis tools to check a program with extensive usage of recursive calls. Conceptually, it is something like this: int counter = 0; int access = 0; extern int nd (); ...
-1
votes
1answer
31 views

what is the algorithm that will give me O(logd)

the question is " Suggest an algorithm that takes a sorted Array and X , and it will return the index of X in the Array if it's not found in the array return -1 , the Time Complexity of the algorithm ...
0
votes
2answers
66 views

Is there a way to improve this code in order to avoid a timeout with large arrays?

I am working with this problem: https://www.hackerrank.com/challenges/fraudulent-activity-notifications/ My code works almost fine, but for some test cases it fails, because of the large array (over ...
0
votes
1answer
30 views

Finding winner and second winner

I was going through this post about the complexity of finding winner and second winner in least comparisons. The post says that it will take n + log(n) - 2 comparisons to do so. I understand that it ...
0
votes
0answers
35 views

Finding closest possible coordinates

I have x,y coordinates board like this: the board is up to 100x100. Where myPosition is gold, destinations is green and collisions is red. myPosition is object destinations and collisions are array ...
0
votes
3answers
57 views

Kth smallest Element and Kth Element?

I am really confused about what exactly the differences between Kth smallest Element and Kth element. Kth element = kth element is an array = array[k-1] but, what is a kth smallest element? I have a ...
0
votes
2answers
35 views

JavaScript: performance improvement to find the common elements in two array

I have a function for search the longest common elements in two array: /** * Return the common elements in two array */ function searchArrayInArray(array1, array2) { var result ...
1
vote
1answer
30 views

Find largest ones after setting a coordinate to one

Interview Question: You are given a grid of ones and zeros. You can arbitrarily select any point in that grid. You have to write a function which does two things: If you choose e.g. coordinate (3,4)...
-1
votes
1answer
37 views

Finding k largest elements in an array in O(1) time

Is it possible to have O(1) time complexity in find the k largest or smallest numbers in an array, by making a stack class with an auxiliary data structure to track k largest/smallest in every push() ...
-3
votes
0answers
15 views

DP Problem finding optimal time to sell home [on hold]

Steffen would like to sell his house. At the beginning of each month he receives an offer, which must be accepted or declined immediately. Once the offer is rejected, it is lost forever. Assume the ...
0
votes
0answers
38 views

Receiving updated value from recursive call

I have a DFS function which collects entry and leave times of vertices. Unfortunately, I am unable to receive a proper value for leave time, because it is not connected with the value from recursive ...
1
vote
0answers
30 views

implement hermite interpolation - multiplayer game

I am trying to make a client-server architecture. I am stuck at the interpolation part. Right now, I have a very naive implementation of the interpolation algorithm. I have every player given a ...
-6
votes
0answers
57 views

Minimum cost of deletion

I recently encountered a problem in an online contest. The question goes like this: You are given an array of size "n". You need to delete all elements from array except the first and last element. ...
0
votes
2answers
25 views

Non-linear movement of element relative to another element

I'm moving an element relative to another element. Let's call them Element A and Element B. For the simplicity of the quesiton, I kept only X axis. var element_a_container_width = 200; var ...
-3
votes
0answers
60 views

unable to figure out error in below program [on hold]

I stuck at a problem https://codeforces.com/contest/546/problem/C I tried to understand the solution https://codeforces.com/contest/546/submission/11223358 I tried to implement exactly like above, ...
-2
votes
1answer
39 views

Count number of subsets having a particular XOR value

I came across a XOR related algorithm problem in geeksforgeeks and trying to understand what its doing but unable to understand it. Problem link ( Given an array arr[] of n numbers and a number K, ...
-1
votes
1answer
33 views

“Primitive Calculator” - Problem with creating division loop

I am trying to create a calculator that uses loops instead of the '*' or '/' operators. I am having problems in computing the result within my division loop below that takes in two positive numbers as ...
0
votes
1answer
43 views

find one same element among several object

Currently I am doing a work related to polygons. Polygon can be described as several vertices. struct Polygon{ vector<Point2D> vertex; Color color; }; Now, I have some polygons already ...
0
votes
1answer
27 views

Netlogo - find the closest agent based on Manhattan distance

I am modelling a big warehouse operations (see below pic). I have implemented a vertex on each patch (green dots) and link them so that I could compute the shortest path (using dijkstra algorithm) ...
-1
votes
0answers
48 views

C language implementation of Prim's algorithm [on hold]

Need help debugging the code for prim's algorithm. The Structures used in the program. typedef struct { int y; // the value of data int weight; // the weight of the edge from it's previous ...
0
votes
1answer
37 views

Suggest a course to a student according his qualifications [on hold]

This is my course class public class Course { String qualA; String qualB; String qualC; public Course(String qualA, String qualB,....) { this.qualA = qualA; this....
1
vote
1answer
45 views

Refactor a hash table solution to twoSum problem

I try the most to solve a twoSum problem in leetcode Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input ...
1
vote
1answer
71 views

What design pattern is suitable for handing many conditional branching

I have a a bunch of rows in a table which store some variables and associated values. I have to fire a task depending the values of the variables from different rows. Multiple values from multiple ...
1
vote
2answers
42 views

Divide image into rectangles information in Python

I have a series of images that are nothing more than a series of colored rectangles in a black background Example:. How could I (using PIL in Python 3.7) make a program that would identify these ...
0
votes
0answers
4 views

Using LTREE type when the final node has ~1000 descendants, which exist under other final nodes?

Is it inappropriate to use LTREE type when the final node has ~1000 descendants, which exist under other final nodes? My data is essentially a directory tree, with the final level containing text ...
-1
votes
0answers
24 views

Support and Resistance algorithm technical analysis [on hold]

I have spent some time looking for an algorithm to identify supports and resistance in technical analysis. I found something similar on this topic. Support Resistance Algorithm - Technical analysis ...
-1
votes
1answer
39 views

How to know if algorithm is big O or big theta

Can someone shortly explain why an algorithm would be O(f(n)) and not Θ(f(n). I get that to be Θf(n)) it must be O(f(n)) and Ω(f(n)) but how do you know if a particular algorithm is Θf(n)) or O(f(n)). ...
-2
votes
2answers
42 views

Median Algorithm for 4 sorted arrays

I need to write an Algorithm for my course, to find the middle value of 4 sorted arrays different sizes in O(n), and i'm not allowed to create an array to store the data. how should I approach the ...
0
votes
0answers
21 views

FD-SCAN algorithm

My professor asked me to implement FD-Scan disc scheduling algorithm. However, I can't find any informations about this in the Internet. How does this algorithm work? Or maybe my professor has ...
0
votes
1answer
42 views

bottom-up minimal-change algorithm issue

Im trying to get all the permutations of the number 4 so like 1,12,21,123,132,...1234,1243,1423,4123,...ect (there are 24) and we have to use the bottom-up minimal-change algrothem but in my code ...
0
votes
1answer
34 views

Minimum string with certain properities

Let's say i have a string of N positive integers containing K different integers.For example this string:1 3 1 3 1 3 3 2 2 1.For this string N=10,K=3(1,2,3).What i want is to find the smallest ...
1
vote
1answer
67 views

Splitting an array in equal parts

I am looking for a Javascript Algorithm to split an array into chunks, but avoiding any small left overs. For example: _.chunk([1, 2, 3, 4, 5, 6, 7], 3) // [[1, 2, 3], [4, 5, 6], [7]] But I want ...
-1
votes
0answers
58 views

Car Fueling Algorithm in Python [on hold]

The problem is the following : You are going to travel to another city that is located d miles away from your home city. You can travel at most m miles on a full tank and you start with a full ...
1
vote
1answer
20 views

Python: Iterate through every pixel in an image for image recognition

I'm a newbie in image processing and python in general. For an image recognition project, I want to compare every pixel with one another. For that, I need to create a program that iterates through ...
1
vote
0answers
29 views

Classification problem that uses ant-miner algorithm (MYRA package) in java with decision tree

I am using MYRA package that applies Ant Colony Optimization miner algorithm to discover rules: It reads the file using ARFFReader class where the method read reads only a file of type Configuration ...

http://mssss.yulina-kosm.ru