Questions tagged [algorithm]

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.

Filter by
Sorted by
Tagged with
4
votes
2answers
155 views

Find all subranges of consecutive values in an array

I was looking at a dataset with a year column. I wanted all the years with matching a particular event. I then get a list of years which is not easy to read: ...
1
vote
2answers
142 views

Possible speed improvements for a Sudoku board validation algorithm?

I tested this algorithm on 9x9 boards and on average, if the board passed to the function is a (valid) solution, it takes 0.13-0.14 seconds for 1 million executions on my machine. I ran my code in ...
1
vote
1answer
85 views

C code in Data structures

Can someone give me any suggestions over my code that I made for this task? Also how much of 10 would rate it ? Suppose a simply linked list whose node is of type node and contains a student's name, ...
1
vote
2answers
66 views

Huffman compressor in plain C

I recently picked up C, because I am getting tired of the hell that is Java Enterprise development. I decided that writing a Huffman compressor will be a great little exercise, and I have always ...
0
votes
0answers
50 views

Object Relational Mapper - improvements to use in production

An Object-relational mapper built using PHP. This question is related to this old question. (Object relational mapper - optimize in memory data representation and code improvements) This was done for ...
4
votes
1answer
648 views

Colour ramp for maps

I'm porting this code to Java and after a few tests all seems ok but I need to know if I'm doing this right. The code takes some colors and create a color ramp for maps and other stuff. You can see ...
2
votes
1answer
111 views

Alpha beta pruning with memorization (transposition tables) and bitboards (5x5 cumulative tic-tac-toe)

This is my first time trying solve a game using these techniques. I've looked at pseudocode of alpha-beta pruning with transposition tables and rewritten it in c++. ...
2
votes
1answer
67 views

How to increase the success rate of my Tic Tac Toe AI that uses the Minimax Algorithm?

this is my first post here! I am working on a Tic Tac Toe AI in Python that uses the Minimax Algorithm to beat either a computer or a normal player. As of now, It has approximately 70% chance of ...
3
votes
0answers
39 views

Extracting Korean text for sentiment analysis

It is quite long so I'm not sure I can ask you to review my code. But I have no choice indeed. What I'm doing is analyzing the Korean language. To do this, first I collect data and loaded the data via ...
0
votes
1answer
36 views

Finding inorder successor of a BST in C [closed]

Please review this code I have written a function to find the successor of BST in c. It takes three arguments, i.e root pointer to the binary search tree, node value of which we have to find a ...
6
votes
2answers
268 views

Improving C++ Connect-four game with little AI

Here is the code for the game : ...
4
votes
2answers
183 views

Codewars: Make a spiral

Link to full problem description: https://www.codewars.com/kata/534e01fbbb17187c7e0000c6 My code: ...
3
votes
1answer
97 views

Find the largest decrease in a sequence of numbers

I have written a function that takes as input a list of 5 numbers, then the program's goal is to return the largest drop in the list. It is important to understand that [5, 3, ...] is a decrease of 2 ...
1
vote
0answers
31 views

81 variations of the rounded rectangle

If we apply outward curving, inward curving, and no curving at all, individually to each of the 4 corners of the rectangle, we get next 81 variations: The code implements next BASIC command: ...
3
votes
1answer
91 views

calculations for values that match specified criteria in a limit search space

I'm developing a RPG game and being blocked by the settings of HP(hit points/health points/health power), attack and defense for the characters - Assassin, Tank and Warrior I'd like to figure out the ...
-2
votes
2answers
61 views

Binary Search Algorithm Difference

As far as I test, there is no any bug point tested. However, I wonder that if there is a problem with the usage of arr.Length or ...
7
votes
1answer
63 views

Optimize K-Mean for large number of clusters

I am writing a Python code for KMeans clustering. The aim of this post is to find out how I can make my below mentioned code optimal when the number of clusters is very large. I am dealing with data ...
3
votes
1answer
74 views

NewPolish - unconventional translator in Python

Hello everyone! In today's assignment I had to complete a rather unusual translator, take a look at my solution, tell me what I can do to make it better and show off yours! Write a function that ...
7
votes
2answers
176 views

Find the first repeating sequence in digits of pi

I wrote a function to return the first n length sequence which occurs twice in the digits of pi. Along with the repeated sequence, I want the indices of the first and second occurrences. For example, ...
3
votes
1answer
52 views

Building a tree containing all permutations of arithmetic expressions given some numbers

Given any series of numbers, for example 1,2,3,4,5 and given the arithmetic operands + - * / including parenthesis, what would be the most optimal way to build a tree that contains all permutations ...
1
vote
2answers
104 views

checking is ellipse is filled or not

following code below works fine but feels kind of a mess. Any one has a better way to do this? I am creating a basic "Enter Pin" to unclick screen on an app. So if the user enters the 1st ...
6
votes
0answers
71 views

Efficiently generate distinct subsets which sum to a particular value

Related: Find all distinct subsets that sum to a given number This code is supposed to efficiently generate all subsets of a list such that the subset's values sum to a particular target value. For ...
0
votes
0answers
27 views

Algorithm for efficient creation of submatrices from original matrix

I wrote this code to simply visualise what happens to an image when it gets put through repeated convolutional filters is a CNN. The code works fine and produces the expected result but the it is also ...
2
votes
2answers
367 views

Box Blur algorithm

This is a challenge from CodeSignal. For image = [[1, 1, 1], [1, 7, 1], [1, 1, 1]] the output should be ...
0
votes
2answers
40 views

Relative Strength Index algorithm for stock values

This is an Relative Strength Index algorithm able to buy and sell stock based on values from basic stock CSVs. It works correctly and well, but I'm not sure if it can be better optimized as it ...
2
votes
1answer
127 views

Implementation of the square root for real time application

For the real time control software I need square root calculation. I have heard that the sqrt function from the standard library isn't good choice due to the unpredictable number of iterations used ...
5
votes
3answers
219 views

Implementing range from_to with step

...
2
votes
0answers
73 views

How to make this algorithm faster. Calculates and searches through large arrays

Ive got this algoritm thats "complex". The comments in code give examples of how large the various data types could be. My cpu usage is less than 10% when running this and ram usage is good. ...
0
votes
3answers
93 views

Finding unique top sums from multiple lists

My question arises from this post on MSE where I have provided an answer to solve the question : There are multiple lists given. The number of lists is arbitrary. Each list contains numbers and is ...
0
votes
1answer
54 views

Finding all pairs of elements in an array that sum to a target value using multiple pointers (follow up)

The previous question was not clear enough so I will try to clarify it more in this follow-up question. I tried the multiple pointers technique to solve the problem that find pair of values that sums ...
2
votes
1answer
88 views

C++ Incredibly Precise Sorter | Efficiency and speed of sorting algorithms

Hey Guys, I'm in the process of building a console program in C ++ that allows users to: sort a sequence of numbers loaded from a TXT file save sorted sequence in a new TXT file measure the sorting ...
1
vote
0answers
80 views

Generating Unique Subsets using Bitmasking

Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets. Link to the judge: LINK Note: Each subset should be sorted. Example 1: ...
1
vote
2answers
97 views

I want reduce the time complexity for this ladder problem to find the minimum ladders required

I was trying to attempt below given challenge. I tried multiple ways to solve the problem but none of them were good enough to pass the time limit. Please advise if you have any idea to improve on ...
1
vote
1answer
46 views

Python Prime Search Slower Optimization

I have these 2 version of code. Both are looking for all primes under a certain ceiling value. The first is testing against the set of all odd numbers. The second in testing against the set of all 6k-...
1
vote
0answers
80 views

Parallel 3D Discrete Cosine Transformation Implementation in Matlab

I am trying to implement 3D Discrete Cosine Transformation calculation in Matlab with parallel computing parfor. The formula of 3D Discrete Cosine Transformation is ...
2
votes
2answers
107 views

Parking places design

I got a question: Design a parking system. There are 3 types of parking spaces: big, medium and small. Implement ParkingSystem class(int big, int medium, int small)....
-1
votes
2answers
108 views

Finding all pairs of elements in an array that sum to a target value using multiple pointers

I was thinking about this problem where you should make a function that takes an array and a target value and then it will find all the pair values that sums up to that target value. Of course there ...
0
votes
2answers
54 views

Flattening a List containing Empty Lists

As part of a text buffer implemented as a piece table, there is an often called procedure to flatten a nested list of character lists. The function is part of constructing substrings of the buffer for ...
0
votes
2answers
137 views

Count the number of arithmetic progressions within a sequence

I have some problems with code for my classes. Even though it works correctly, I run out of time for half of the examples. Here's the task (I really did my best trying to translate it): You have a ...
2
votes
3answers
67 views

Is My Function to Find Triplets in Scala running in O(N^2)

Given the classical problem to find triplets that sum to zero in an array. Is my Scala implementation correct and executed in O(N^2)? If yes, why? Can someone make a running time analysis. What other ...
2
votes
2answers
53 views

Merge Sort for Linked List Criticism in C

I previously implemented a Merge Sort for arrays, so after fixing up my code for the array-based merge sort I have now implemented a merge sort for a basic singly-linked list data structure which only ...
5
votes
2answers
281 views

C : Image Segmentation

My primary coding language is C++, but I occasionally use C. I wrote some simple image segmentation using Union-Find algorithm. Feel free to comment anything! ...
0
votes
2answers
137 views

C++ : Merging two convex hulls

I wrote a C++ program that merges two convex hulls in linear time. The algorithm is based on http://cgm.cs.mcgill.ca/~godfried/teaching/cg-projects/97/Plante/CompGeomProject-EPlante/algorithm.html ...
1
vote
0answers
63 views

3D Non-local Mean Algorithm in MATLAB

This is a follow-up question for GetNeighborhood function for 3D cells structure in MATLAB. Based on the existing 2D non-local algorithm, I am attempting to implement 3D non-local mean algorithm in ...
3
votes
1answer
80 views

Poker Hand Evaluation (speed optimization)

Given a two-card poker hand and a board of 5 cards, I want to evaluate the player's hand strength as listed here. The evaluation of a poker hand was measured to be ~100 microseconds on average. ...
2
votes
1answer
338 views

3Sum - leetcode

Question: Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. Notice that the solution set ...
6
votes
3answers
542 views

Euclidean algorithm to determine GCD (greatest common divisor) in C -- alternative method

Been looking into some simple algorithms, I came up with the following piece of code in C to implement the Euclidean algorithm iteratively (I like to be clear here, I don't want the recursive ...
1
vote
0answers
100 views

Linear conflicts heuristic for 15 puzzle game

I'm trying to solve the 15 Puzzle problem using IDA* algorithm with a Linear Conflicts heuristic. I already implemented the heuristic from what I understood : link Here's my goal state ("snail&...
1
vote
1answer
53 views

Insertion Sort- inserting from the left

I've implemented my own insertion sort algorithm, and here's the code. ...

1 2
3
4 5
96