Tagged Questions
An algorithm is a sequence of well-defined steps that define an abstract solution to a problem. Use this tag when your issue is related to algorithm design.
0
votes
0answers
7 views
Tetris Random Piece Generator
Was just wanting some general feedback on the below code regarding
1. Readability
2. Structure
3. Efficiency
...
-1
votes
0answers
5 views
Could someone please provide an example of LARS algorithm via R program?
Could you tell me the best recourse about Least Angle Regression with implementation in R program, because, there is nothing on YouTube.
0
votes
0answers
8 views
Palindromic prime search using the Sieve of Atkins
I am working on a project that deals with prime numbers and am currently looking for a way to make the function max_palprime() work faster and possibly simpler.
...
3
votes
1answer
46 views
A String.prototype.diff() implementation (text diff)
I just had the idea to develop an algorithm to calculate and highlight the difference between two strings. I know that there are already some libraries to do the job but i just tried to make my own. I ...
3
votes
3answers
49 views
Find maximum value of Point represented by an Array of values for each coordinate
Suppose there is an array A = {3,2,5}, then points for this array correspond to indexes (i,j) where ...
2
votes
1answer
31 views
Split string into 160-character chunks while adding text to each part
The send_sms_message method takes text as an argument. The length of text is unknown and can ...
1
vote
1answer
52 views
C++ Prime Number Library
This prime number library is one of my first programming projects I've done in c++. My goal is to create useful functions that deal with prime numbers in an efficient way.Note: (Most of the functions ...
-3
votes
0answers
24 views
Google Sheets IF statement logic [on hold]
I'm trying to write a formula for a column of cells that checks if the value in the 2 left column cells are < 1, and then send a message respectively. Here's an example:
I'm given some coworkers ...
3
votes
2answers
97 views
Poisonous Plants
I have solved the following problem. My code works but Hackerrank says that I can do faster:
There are plants in a garden. Each of these plants has been added
with some amount of pesticide. ...
0
votes
0answers
27 views
9
votes
2answers
129 views
Dijkstra's algorithm for computing the GCD of two integers, translated from C to x86 assembly
This is the x86 version of a C file assignment (I have included both). We were to convert the C code to assembly. I am rather new at assembly and would really appreciate suggestions and help for ...
2
votes
1answer
73 views
Iterative solution for generating all permutations of a string
I know the runtime for generating all permutations is supposed to be \$O(n!)\$. I'm not sure if the code I wrote for it runs in \$O(n!)\$ though. I'm having trouble analyzing its runtime.
The ...
-2
votes
0answers
10 views
Saving a list of ids in database sql [on hold]
I am working on an App where client can shortlist a person.I am using flask framework with sqlalchemy.I have add a column where shortlisted person names are appended to the columns.
Here's the code ...
-3
votes
0answers
18 views
Count Inversions Issue - Python [on hold]
I am not what is wrong with this algorithm to count the number of inversions. Please can someone look at this and point the issue
...
2
votes
0answers
29 views
SPOJ GENERAL: sorting by swaps of distance k
I have been trying to solve this simple problem on SPOJ for quite some time now, but I keep on getting TLE (Time limit exceeded) for some reason.
Since the problem is in Portuguese, a brief ...
2
votes
2answers
35 views
Text font size adapting to space
In order to practice my programming skills, I am trying to implement a Button class, to use in pygame. I know there are libraries like PGU, I do this to improve in programming.
I spent a bit of time ...
5
votes
3answers
161 views
+50
Flatten an array
I have got this interview question which has asked me to write a production level code which flattens the arbitrary nested array of arrays.
Code
...
1
vote
1answer
25 views
A simple Insertion Sort implementation in Java
I've written a InsertionSort algorithm in Java and I want a review on these:
Performance improvements.
Code conventions.
Algorithm design improvements.
Cleaner approaches.
I would highly ...
3
votes
3answers
46 views
A simple bubble sort implementation in Java
I've written a Bubble Sort algorithm in Java and I want a review on these:
Performance improvements.
Code conventions.
Algorithm design improvements.
Cleaner approaches.
I would highly appreciate ...
12
votes
9answers
2k views
Given three numbers, find the second greatest of them
I've just coded this for my country's programming Olympiad. I want to know if this method is a good approach in terms of readability and performance. I would also like to know how to improve it.
Note:...
4
votes
1answer
60 views
Max difference between two array elements
Can I get feedback on below code? Problem statement is Maximum difference between two elements such that larger element appears after the smaller number
Would this solution be still considered O(n) ...
1
vote
0answers
33 views
Glueing Java collections into a heap
I have implemented this heap (priority queue) data structure using java.util.TreeMap and java.util.ArrayDeque. The operations ...
3
votes
1answer
83 views
HackerRank “Save Humanity”
The "Save Humanity" problem on Hackerrank asks us to:
... find all substrings in the patient DNA that either exactly matches the virus DNA, or has at most one mismatch.
For example: ...
2
votes
2answers
65 views
0
votes
0answers
39 views
Generating a random ObjectID
We want to ensure that certain documents in our DB get distributed well across the shards. Currently the documents are sharded by their _id, but they are often ...
3
votes
1answer
82 views
Minimum window substring
The minimum window substring problem from leetcode.com asks:
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity \$O(n)\$.
...
3
votes
0answers
54 views
Subtraction in a spreadsheet column numbering scheme
The idea of the algorithm is to decrease a number from a word.
Is there a better way to write this algorithm?
limitiation:
it is important to decrease with a limit, if BB is the word we
decrease ...
-1
votes
2answers
66 views
Finding consecutive occurrences of a value in an array
Given an array, return True if the array contains consecutive values:
...
-1
votes
0answers
31 views
1
vote
1answer
112 views
Winning logic for Tic Tac Toe and OO design
I'm a Java beginner and I've just started learning about GUI. However, I'm not sure about GUI coding conventions and whether I'm getting the object orientation part of it right. I feel like I'm ...
8
votes
1answer
101 views
Naive parallel Sieve of Eratosthenes in Java
My naive version now is too slow. I think setting/accessing concurrent atomic bit is way slower compared to access/modify an array of boolean. Second, the parallel execution only happens on the ...
-1
votes
0answers
25 views
Algorithm to draw the shortest path in grid
I want to find the shortest path between two points in the grid, and than mark the path with '+' sign. I found the shortest path using BFS algorithm, but now I'm not sure how can I mark it using ...
3
votes
1answer
41 views
Implementing the Barabási–Albert model
I am writing a code for Barabási–Albert(BA) model with specific node and edges.
The algorithm is almost like [1] as follows:
...
1
vote
1answer
136 views
Random iteration over an array using divide and conquer
I have created a utility class which allows random iteration over an array.
The idea is pretty much a divide and conquer approach.
...
4
votes
1answer
44 views
Bottom up (iterative) mergesort in C
I have this C implementation of the bottom-up (iterative) mergesort:
mergesort.h:
...
5
votes
1answer
78 views
High performance triangle - axis aligned bounding box clipping
Implementation of a Robust (i.e. with a finite plane thickness) Sutherland–Hodgman algorithm for clipping polygons against an axis-aligned bounding box. I use the following code only for clipping ...
5
votes
3answers
118 views
Bubble Sort in Objective-C
Following is Objective-C method implementation I did for one of the most simplest sorting algorithms, Bubble Sort to sort an array of integers.
Note:- I have defined it as a static method in the ...
3
votes
3answers
867 views
Making as many unique strings as possible by removing two characters
I'm attempting a programming challenge type task in C#, where the goal is to determine how many unique strings can be obtained by removing two characters. The prompt for the task implied that I should ...
2
votes
1answer
34 views
DisjointSet with O(1) find and O(1) amortised union
Does this code outperform the common implementation with path-compression and union-by-rank? I'm still okay with a review.
GitHub
...
7
votes
3answers
383 views
Algorithm to compute the n-th derivative of a polynomial in Python
As a personal exercise, I'm trying to write an algorithm to compute the n-th derivative of an ordered, simplified polynomial (i.e., all like terms have been combined). The polynomial is passed as an ...
1
vote
1answer
58 views
Moving MP3 files from one directory to another using regex
This is a simple script for moving my MP3 files from one directory to another. I'd like to know if there is a more efficient way to handle my task in the script. I analyzed the algorithm to be \$O(n^2)...
0
votes
0answers
8 views
Selection Sort trouble with indexes [migrated]
Actually I'm dealing with CodeAbbey problem, so I don't want answer as code, but explenation about that, what I am doing wrong. http://www.codeabbey.com/index/task_view/selection-sort
My Selection ...
4
votes
1answer
64 views
Tic Tac Toe algorithm using itertools
I'm looking for feedback on the readability of my code and opinions on the pick_best algorithm. I do this stuff for fun when I have time, and never get a chance to have anyone else look at it. ...
0
votes
0answers
34 views
Finding shortest paths in a Wikipedia article graph using Java - second attempt
I have improved Finding shortest paths in a Wikipedia article graph using Java.
Now I have this:
AbstractWikipediaShortestPathFinder.java:
...
0
votes
1answer
48 views
Partitions of a number (backtracking) - time efficiency
I had to write an algorithm that prints the partitions of a natural number in lexicographic order. Example of I/O:
If the algorithm reads from ...
6
votes
2answers
93 views
Find number of plus in a 2d array
Problem
CharGrid
The CharGrid class encapsulates a 2-d char array with a couple operations.
int countPlus()
Look for a '+' pattern in the grid ...
4
votes
1answer
88 views
Basic Internet banking application
I programmed in Java before, but I feel that I lack the "true way" of programming (OOP concepts, design, algorithm), so I started to learn all of these but I need your opinions and suggestions so I ...
1
vote
1answer
51 views
Javascript Parallax Scrolling Text
I built a 404 page which involves parallax scrolling text. The program updates the position of 100-200 text nodes at each animation frame called with ...
4
votes
1answer
119 views
Number of divisors of a factorial
I was solving the DIVFACT problem from Sphere Online Judge:
Given a number, find the total number of divisors of the factorial of the number.
Since the answer can be very large, print the answer ...
2
votes
0answers
40 views
Implementation of the Minimum Stop Algorithm in Javascript
I started taking the Algorithm design class from Coursera. So into the third week they talk about Greedy algorithms and walks through a sample problem.
This is the Problem Statement that I could find ...