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.
algorithm
121,068
questions
0
votes
0
answers
6
views
Traverse a graph with multiple stops from a starting point? [duplicate]
I have an undirected weighted graph I need to traverse from X node to a list of nodes. The list is unordered by default, meaning that the order of which nodes are traversed is not important. What's ...
0
votes
0
answers
14
views
The model(DecisionTreeClassifier) gives wrong results
I'm taking a machine learning course with an assignment to implement a fit method for DecisionTreeClassifier. Here are the links for more information:
https://stepik.org/lesson/333977/step/8?auth=...
-7
votes
1
answer
50
views
WiggleSort: giving wrong output? [closed]
I am trying to solve LeetCode problem 324. Wiggle Sort II:
Given an integer array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]....
You may assume the input array always ...
1
vote
3
answers
79
views
Fast integer sqrt using Math.Sqrt
I'm trying to calculate the square root of integer values. It doesn't need to be very accurate, but it should be fast and deterministic across platforms. I'm using this for a RTS game with lockstep ...
0
votes
0
answers
44
views
How can I estimate the difference in performance of a HashMap lookup vs List iteration in Kotlin?
I am working on an application that needs to map pdf documents to corresponding json data files (see: Kotlin data structure for efficient lookup of nested data for more details). In trying to ...
-1
votes
0
answers
41
views
What is the time complexity of list1==list2 operation in Python? [duplicate]
It was my understanding that a condition equating operation would always be O(1) as we are simply checking if LHS is same as RHS.
But this scenario got me thinking.
if list1 == list2:
print("Hi&...
0
votes
1
answer
41
views
Kotlin data structure for efficient lookup of nested data
I am currently working on an application that needs to create a mapping between document pdfs and corresponding JSON data files. The files are coming from a third party so I have no control over their ...
0
votes
2
answers
55
views
How is my algorithm for stock span problem incorrect?
The question :
The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate the span of stocks price for all n days.
The span Si of ...
-1
votes
0
answers
22
views
What should I focus while learning DSA? [closed]
So basically I am learning DSA for the first time and I dont want to overlearn or learn things that aren't neccessary. Can anyone tell me what I should focus on?
DSA learning I am learning quick union ...
-8
votes
0
answers
42
views
Did Everyone know about Netflix game downloading algorithm on IOS? [closed]
We try to build a Games centre App that allow user can download game from our app. but in IOS we can't download directly like Andiron so try the other way like following Netflix game downloading flow ...
0
votes
1
answer
62
views
How to store row-position in a database?
I am looking to emulate a feature in Excel/Google Sheets where there is a table of data, but someone may move a row up or down. Here is an example of the interaction:
My first thought as to how to ...
0
votes
2
answers
89
views
Finding if strings can be anagrams
I have String s1 and String s2. I want to check whether it is possible to make s1 an anagram of s2 by removing a single character zero or more times from s1, and removing a single character zero or ...
-1
votes
0
answers
15
views
Cloud sim/cloud analyst
LB Policy
I have implemented more than 5 algorithms but only default 3 algo is showing up on the option.How to fix it?(Honey bee etc )
Also mention through code in constants.java
How to fix this issue ...
0
votes
3
answers
112
views
Join texts and optimize formatting
I have text objects (text1, text2, etc) with formatting information (eg. [bold, italic]). Now I want to concat these texts and format them in HTML.
For a simple case it would transform the following
...
2
votes
0
answers
52
views
Neigbor-sum graph coloring algorithm
I've been able to generate a Python program that generates a sigma labelling of a graph. A sigma coloring is a vertex-coloring $f: V(G) \Rightarrow \mathbb{N}$ such that the color sums of the ...
2
votes
3
answers
100
views
How to determine an overlapping sequence of words between two texts
In one of our digital assignments, I had asked my students to read an article and write a few things they learned from that article. Students were told that they were supposed to write using their ...
-3
votes
1
answer
78
views
Create a recursion function to respond with a different object [closed]
I'm a receiving the following data from a HTTP request to get all menus available:
[
{
"ID": "2",
"Name": "Home",
"ParentID": "1&...
-1
votes
1
answer
72
views
Shuffle the Array - LeetCode problem. 2 pointers approach fails [closed]
I am trying to solve LeetCode problem 1470. Shuffle the Array:
Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn].
Return the array in the form [x1,y1,x2,y2,...,xn,...
2
votes
1
answer
47
views
Struggling with Shortest Path Calculation in Graph with Special Edge Weights
I've been working on a problem where I need to find the shortest path in a graph considering two types of edge weights: normal and special. Check Problem Here.
I have constructed an adjacency list and ...
0
votes
0
answers
39
views
Implement unique enrollment mechanism between endpoints and remote server
I'd like to design an enrollment mechanism between Win/Linux/MacOS endpoint and a remote server with the following characteristics :
enrollment should be seamless with no user intervention.
well ...
2
votes
1
answer
57
views
segment tree with range intersection
Recently I came up with a range problem when thinking about a hobby project.
Consider a big binary array indexed from 0 with size A("[0, A)"), I want to support 3 range (the ranges are ...
0
votes
1
answer
53
views
Understanding Time complexity of nested sorting
I am solving this LeetCode problem 1636. Sort Array by Increasing Frequency:
Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple ...
3
votes
2
answers
105
views
A more efficient algorithm in finding the number of distinct decompositions a number has using only repdigits
This is a problem from a previous semester that I am trying to upsolve. I am trying to solve a problem involving the total number of ways of decomposing a number using only repdigits. A repdigit is a ...
-1
votes
0
answers
21
views
How to optimize fetching and caching grid data [closed]
I'm developing a hypothetical cloud spreadsheet application. The spreadsheet is your typical two dimensional sheet of cells. Whatever range of cells a user is viewing will be fetched and cached. The ...
0
votes
4
answers
97
views
Why is multiplication of integer O(n^2)?
I was wondering why multiplication of integers is O(n^2)? I've been taught addition and multiplication is considered 1 operation. Hence if I multiply an integer of n-digits with another integer of n-...
0
votes
3
answers
55
views
Time complexity analysis of data structures
I got a bit confused about analzsis of data structure basic operation like inserting or deleting.
when I am asked about creating an data structure that support deleting operation, or inserting in O(1),...
1
vote
1
answer
55
views
Java DepthFirstSearch Algorithm not working
I have tried to code a depthfirstsearch algorithm to solve a maze. This is what I have so far. I have tried to add as much detail so the logic is understandable:
//Upgraded dfs algorithm that creates ...
-2
votes
1
answer
44
views
Given a number N find the number just smaller than N such that it has a given digit x present in it x times [closed]
You will receive an input number N in string format and also a number x. Your task is to find the largest number that is smaller than N and contains the digit x exactly x times.
For example: N = ...
0
votes
0
answers
19
views
OCR app on mobile so good and more accurate than OCR PC software. Why?
As above, I have tried some Image-to-text apps on mobile as well as software on PC and I wonder what make mobile superior PC at this process ?
What i have done : Search through internet and create ...
-1
votes
0
answers
40
views
How can I optimize my program using a hashmap? [closed]
import math
from collections import defaultdict
from fractions import Fraction
n = int(input())
f_nums = list(map(int, input().split()))
s_nums = list(map(int, input().split()))
f_counts = ...
-5
votes
0
answers
41
views
How to calculate CRC32 of strings longer than 3 characters? [closed]
I try to calculate CRC32 of strings as described in this website
In that website, example string is Hi\n which has 3 characters length.
String is converted to binary format and then inverted. Then it ...
0
votes
1
answer
50
views
Dafny simple proof about giving change not working
I want to prove that the following code returns a given amount (money) in 5 and 3 bills/coins:
function sum(ns: seq<nat>): nat
{
if |ns| == 0 then
0
else
ns[0] + sum(ns[1..])
}
...
0
votes
0
answers
30
views
Calculating a list of voxels within multiple overlapping Axis-Aligned-Bounding-Boxes, without looping over the same space
I have a method that returns a list of voxel coordinates within an AABB. Let's say a voxel is 1x1x1 cm, and a bounding box is 2x2x2, then it will return 8 voxels by looping over the dimensions of the ...
1
vote
3
answers
113
views
In-Place Reordering of Doubly Linked List Nodes to Ensure Memory Contiguity
I am working on a program that deals with doubly linked lists that are allocated within a bounded memory region:
constexpr std::size_t numNodes = 15;
Node* block = new Node[numNodes];
I would like to ...
0
votes
0
answers
19
views
Modified accel asc algorithm
I wanted to make an accel asc algorithm that only outputs partitions that only have terms that are smaller than or equal to n. For example: if I want the partitions of 4, and n = 2, the wanted ...
1
vote
2
answers
87
views
Parse every k-element subset of an n-element vector
My goal is to perform an operation on every k-element subset of n elements stored in a vec.
My current approach uses this bit-manipulation to generate integers with k set bits in lexicographic order. ...
2
votes
1
answer
66
views
Having issues calculating APSP for matrix size n >= 4
I'm having issues finding the problem with the following implementation of Floyd-Warshall APSP Algorithm.
Currently working on a vjudge exercise and I'm having issues figuring out what's the problem ...
0
votes
0
answers
25
views
trilateration algorithm for calculation of real time location (flutter app) (BLE beacons used)
I am trying to implement a real-time location system in which I can upload a map (image) and pinpoint certain things such as the location of beacons, destination, and so on. I am trying to calculate ...
-1
votes
0
answers
66
views
How to determine if a node in graph is connected to another node efficiently? [closed]
Now I know some people will suggest DFS or BFS etc etc, but I am looking for other faster approaches. The graph I'm working on has "mixed" directions - some edges are directed but some aren'...
0
votes
0
answers
21
views
DGE Analysis using Limma on DSP GeoMx Data: Handling Multiple ROIs per Core
I am performing differential expression analysis using the limma package on DSP GeoMx data, and I have a question regarding the handling of multiple ROIs per core. Below is a snippet of my sample ...
1
vote
2
answers
47
views
Fast way of detecting outliers in 2D space
I have hundreds of millions of point clouds like the following:
I want to remove outliers 1, 2, 4, 5, 6, 7. The safest bet is to build a minimum spanning tree connecting all the points and remove ...
-1
votes
0
answers
18
views
How to create an algorithm with melody and chords as input, and tight parallel 3 part harmony as output [closed]
After not finding the app I'm looking for and speaking to a friend who programs:
I'm looking to develop algorithmic rules which can be used to program an app such that you input a melody and ...
0
votes
2
answers
123
views
Finding minimum value in given range efficiently
I have function that takes a number n that represents number of servers and another parameter represents a list of requests
Initially servers will hold values 0 of size n.
For each request, requests[i]...
-1
votes
1
answer
68
views
Algorithm help: given n sets of integers and a target integer, find a set of one element from each set that adds to the target integer
I have multiple sets of integers, let's call them K_1 through K_N. Each set is finite and not necessarily the same size. I have a target integer, C.
Is there a way to select one element from each ...
0
votes
1
answer
47
views
Checking a candidate majority element: Does my simplification work with all cases?
Here are the details of the problem:
Given a sorted array arr of N elements.
A majority element in an array of size N is an element that appears more than N/2 times.
The task is to write a function ...
-1
votes
0
answers
85
views
How to explain the logic of the pairing of the 2018 FIDE World Chess Candidates Tournament? [closed]
Update-2
This is indeed a standard ‘circle’ schedule with players renumbered from 1:7 to ‘2’, ‘8’, ‘4’, ‘5’, ‘3’, ‘6’, ‘1’. Rounds 6 and 7 are swapped.
To reproduce:
# ---------------------------------...
2
votes
2
answers
82
views
Finding the subarray with the least median given a size K and an array of length N
I have been struggling the past month with this problem that was given to us on our course while I was upsolving it. The task is to find the window of size K with the least median in an array of ...
1
vote
1
answer
66
views
Why is this algorithm O(n*n) - Manacher algorithm implementation?
So I was recently doing leetcode problem number 5 - longest palindromic substring, which outputs the longest palindromic substring out of a string. I have studied Manacher's algorithm but I didn't ...
1
vote
1
answer
179
views
Permutation summation in Pandas dataframe growing super exponentially
I have a pandas dataframe that looks like
import pandas as pd
data = {
"Race_ID": [2,2,2,2,2,5,5,5,5,5,5],
"Student_ID": [1,2,3,4,5,9,10,2,3,6,5],
"theta": [8,9,2,...
0
votes
0
answers
50
views
Design a Data structure ~(simple rate limiter) [closed]
I'm studying DSA for my interviews && university exams and kinda stuck right now.
There is a problem statement: given n(limit of request) and m(window time), design a data structure that ...