Click here to Skip to main content
15,879,239 members
Everything / General Programming / Algorithms

Algorithms

algorithm

Great Reads

by Arthur V. Ratz
In this article we'll demonstrate the implementation of k-means clustering algorithm to produce recommendations.
by Igor Ladnik
Automatic generation of optimal control policies for the basic quadcopter flight modes
by Eric Ouellet, Sani Huttunen
Fast implementations of permutation algorithms
by Dmitriy Gakh
Development in C# without care of resource consumption can lead to overloading the system. This article describes a case with large waste of memory and CPU time and how to avoid it.

Latest Articles

by Igor Gribanov
C++ iterators and algorithms work well for containers, but can we sort the Structure of Arrays?
by Henrik Vestermark
The steps needed to build an Interval Arithmetic class in C++
by Ștefan-Mihai MOGA
How to solve real-life problems using B-trees
by Nicolas DESCARTES
How to implement logistic regression in ML.NET?

All Articles

Sort by Updated

Algorithms 

U 2 Apr 2024 by Igor Gribanov
C++ iterators and algorithms work well for containers, but can we sort the Structure of Arrays?
16 Mar 2024 by Henrik Vestermark
The steps needed to build an Interval Arithmetic class in C++
20 Jan 2024 by Ștefan-Mihai MOGA
How to solve real-life problems using B-trees
17 Jan 2024 by Mickey P
Big O notation talks about generalizations. its similar to if you were doing size estimates in lets say economics: such that 1000 and 750 would be both rounded to 1000 and what is interesting is 10K is not in the same ballpark of 100K but 13K is...
12 Jan 2024 by Nicolas DESCARTES
How to implement logistic regression in ML.NET?
8 Jan 2024 by Nicolas DESCARTES
What clustering algorithm should be selected for the clustering task?
8 Jan 2024 by Henrik Vestermark
Ostrowski multi-point method for Polynomial roots
20 Dec 2023 by Henrik Vestermark
Durand-Kerner method for Polynomial roots. A fast and reliable simultaneous method
18 Dec 2023 by pasztorpisti
Have some balls and don't be afraid to choose your destiny for yourself. Do you want us to tell you what to do with your life??? (Hmmm, a few tips from me: go and try working as a makeup artist or a ballet dancer...) If you have no clue about any...
18 Dec 2023 by Intel
This article will take a closer look at the advantages and disadvantages of the Fortran DO CONCURRENT statement and the OpenMP target constructs with respect to accelerator offload.
15 Dec 2023 by Patrice T
Small review of Trial Division algorithm
11 Dec 2023 by Nicolas DESCARTES
What is naive Bayes and how to implement it?
11 Dec 2023 by JorgeLuisOrejel
This article describes the implementation of Dijkstra's Smoothsort as a generic sorting algorithm in C#.
2 Dec 2023 by Nicolas DESCARTES
How to implement a content-based recommendation system in C# ?
29 Nov 2023 by Henrik Vestermark
Laguerre's method for a stable and efficient polynomial root finder.
25 Nov 2023 by Nicolas DESCARTES
What is time complexity in computer science and how do you determine it for a given algorithm?
11 Nov 2023 by Henrik Vestermark
Practical implementation of a fast, robust and stable polynomial root finder using Halley's method
6 Nov 2023 by Rick York
When I run this code I get 1 also. I think the key is your list_results vector. When I run this it has these values : 6 8 12 16 and the answer is obviously 1 because those numbers are factors of only one value : 12. This means you need to...
6 Nov 2023 by lock&_lock
I am back with my hackerrank problem. I am trying to exercise with this question: Between two sets. I need to make two arrays of integers and determine all integers that satisfy the following two conditions: The elements of the first array are...
25 Oct 2023 by OriginalGriff
Just as Richard found, if I copy and paste your code verbatim into an online compiler - OnlineGDB.com[^] - and run it, then enter this text:2 2 3 4 24 48 What do I get? "1", exactly the same as Richard. So ... it's an initialization problem, or...
21 Oct 2023 by Code Artist
Implementation of DynamicX-Largest-Triangle-Three-Bucket for chart data plotting
17 Oct 2023 by Henrik Vestermark
Fast and Stable Polynomial root finder for Polynomial with real coefficients
15 Oct 2023 by Mike Hankey
If you can afford the whole set The Art of Computer Programming by Knuth is an excellent source The Art of Computer-Programming-Volumes-1-4B-Boxed[^] Or you can look through the various volumes and decide which has what you need; Volume 1:...
15 Oct 2023 by oslon
Every aunt and grandma these days know about CLRS and Skiena. I want to know more books specific to the subject. These CLRS, Sidewick and Skiena books are definitely not meant to be read indepedently. They're for classrooms imho. Please...
12 Oct 2023 by tour belitung
To check if a point is inside a triangle, there are several approaches you can use. One commonly used method is the "Barycentric Coordinate System" approach. Barycentric coordinates represent a point as a weighted sum of the vertices of the...
11 Oct 2023 by Henrik Vestermark
Practical implementation of a fast, robust and reliable polynomial root finder using Newton's method
10 Oct 2023 by Mike Hankey
If you google "Traveling Salesman Problem" you get 20,200,000 hits. This is just one of them; Travelling Salesman Problem using Dynamic Programming - GeeksforGeeks[^] This will get you started.
10 Oct 2023 by MD Samiul Islam
The Traveling Salesman Problem (TSP) is a classic optimization problem in computer science. Given a list of cities and the distances between each pair of cities, the goal is to find the shortest possible route that visits each city exactly once...
4 Oct 2023 by Unknown Boy 2023
(Geometry: points in triangle?) Suppose a right triangle is placed in a plane as shown below. The right-angle point is placed at (0, 0), and the other two points are placed at (200, 0) and (0, 100). Write a program that prompts the user to enter...
4 Oct 2023 by OriginalGriff
Do you have any idea how much work explaining code line by line is? Every single line needs a paragraph of explanation! For example: int next = r.Next(); Create a new variable called "next" which can hold a integer value. From...
2 Oct 2023 by optiklab1
Playing with graph traversal algorithms in searching for the way of profitable currencies exchange
30 Sep 2023 by Ujwal Watgule
The Cheetah Optimizer is a nature-inspired metaheuristic algorithm designed to tackle complex optimization problems across multiple dimensions.
29 Sep 2023 by Patrice T
Another approach to Optimize Trial Division Algorithm
21 Sep 2023 by Member 4201813
How to calculate transition matrix for linear pseudo-random number generator manipulating its internal state
20 Sep 2023 by Maniezzo
A couple of lines of code to get the i-j indices of an upper triangular matrix (main diagonal included) from a linerized array.
15 Sep 2023 by optiklab1
I demonstrate with an actual implementation that well-known algorithms BFS, DFS, Dijkstra, and A-Star are essentially variations of the same algorithm.
24 Aug 2023 by Member 16078047
const seatingChart = [ ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'], ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'], ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'], ]; function allocateSeats(numPeople) { //X denotes booked seat if (numPeople...
15 Aug 2023 by Ujwal Watgule
Credit card fraud detection is an important application of machine learning techniques.
2 Aug 2023 by OriginalGriff
Repost: Deleted. Please do not repost your question; use the Improve question widget to add information or reformat it, but posting it repeatedly just duplicates work, wastes time, and annoys people. I'll delete this one.
2 Aug 2023 by Patrice T
How to use bitwise operations on Bitfields as primitive SIMD
1 Aug 2023 by ElMarvinito
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute...
1 Aug 2023 by Graeme_Grant
If I was you, I would do a quick google search as there are many tutorials with code: javascript dijkstra algorithm - Google Search[^]. Here is the first search result: Dijkstra's algorithm in Javascript[^]. If you do not like that one, there...
21 Jul 2023 by Patrice T
Tree Graphs used as support for Top-Down Analyze method
17 Jul 2023 by Member 11356225
Hello, This is my first question here and I hope you will help me . I have to do assignment for tomorrow which looks like this : "You need to implement function that sorts array of numbers using quicksort algorithm.Additionally the function should return count of checks in function...
30 Jun 2023 by altomaltes
This algorithm uses very simple integer math (add and multiply) to render arcs, lines, etc. to CNC machines or a computer surface.
9 Jun 2023 by Jack Devey
Introducing a lossless compression mechanism for data structured in a table or matrix
8 Jun 2023 by Ashley OP
I am attempting to implement the Knuth-Morris-Pratt pattern search algorithm in my code but am having difficulty understanding the concepts of the algorithm. Does anyone have an example of KMP code that I could reference? For my reference, I...
8 Jun 2023 by OriginalGriff
Wikipedia also provides a good explanation: Knuth–Morris–Pratt algorithm - Wikipedia[^] - and it's far to complex for us to improve on those two links in a little textbox like this. And while we are more than willing to help those that are...
7 Jun 2023 by Richard MacCutchan
The link you provided contains the description of the algorithm and the code to implement it. There is nothing much that can be improved upon what is already there.
4 Jun 2023 by GeorgeDS
An anecdotal report describing issues encountered in coding a minimal perceptual hash capability, in plain old C, in to 35 year old rolling development, with the goal of running on a noob Win 10/11 installation.
24 May 2023 by Mirzakhmet Syzdykov
Science and programming on working examples
24 May 2023 by Mirzakhmet Syzdykov
Traveling Salesman Problem using Ant Colony Optimization
21 May 2023 by Shun Huang
Basics of ML and Perception learning algorithm
11 May 2023 by ashan prabath
Problem You are given two non-decreasing sequences A = (A₁, A2,..., AM) and B = (B₁, B2,..., BN). You can choose any two indices i and j, and then swap A[i]; and B[j]. Note that the you can do the operations as many times as you want, and your...
11 May 2023 by Rick York
What I don't understand is what you are trying to do. An output of 4 from those two sequences makes no sense to me. I assumed you want to determine what the formula for the sequence is so something like what is f(x) to get M[x]. With that in...
11 May 2023 by OriginalGriff
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for...
2 May 2023 by Shuvradip Sarma
public static int partition(int array[],int start,int end) ` { int pivot_index=(start+end)/2; int pivot=array[pivot_index]; int i=start; int j=end; while(i
19 Apr 2023 by Gcobani Mkontwana
Hi Team I am experience two errors on my program while running interval map on cplus-plus. Below code is the error gets compile " prog.cc:210:1: error: a template declaration cannot appear at block scope template ...
19 Apr 2023 by Rick York
Those line numbers don't seem to match up because you have only posted 135 lines of code. It is much easier to determine the cause of a problem when ALL of the code in a module is posted so that we can find the relevant line. The following...
19 Apr 2023 by Gcobani Mkontwana
Hi Team I am trying to implement an assign function together with test case for this program using interval map in c++ my program somehow is compiling this below error. " prog.cc:210:1: error: a template declaration cannot appear at block scope ...
19 Apr 2023 by Rick York
The only thing that stands out to me is this line : IntervalMap(V const& val) : m_map({{std::numeric_limits::lowest(), val}}) { } I think the compiler does not like all those curly braces there so it should look like this : ...
18 Apr 2023 by InvisibleMedia
This article describes how to divide two polynomials and shows the source code to calculate this division. There is also code to add, subtract and multiply two polynomials.
17 Apr 2023 by Mark H Bishop
Computational classes and a GUI interface to illustrate usage
7 Apr 2023 by mustafaumaralvi 75
I have two very large text files (more than 1 GB each) and I need to compare them in Java to identify the differences. However, reading the entire file into memory and then comparing line by line is not an efficient solution due to memory...
7 Apr 2023 by Mike Hankey
I don't know Java but appears to be similar to C#. The File.Open does not read in all the data and if you use a StreamReader (C#, don't know the Java Equivalent) for the inputs you can read each input line by line compare and if the lines are...
29 Mar 2023 by Syed Mubashshir Hasan
I'm attempting to create an algorithm to address an issue that I can't categorize, therefore I'll reveal the subject: You have a map divided into parts with a specific area and a specific number of inhabitants. The challenge is to identify sets...
27 Mar 2023 by User 15925593
You are given a city network in the form of a tree(an acyclic graph). There are N cities and each city has a unique ID (integer from 1 to N). There exists a unique path between each pair of cities. There are only N-1 paths in the city network....
27 Mar 2023 by KarstenK
It sounds similar like the Travelling salesman problem. So you might look at this problem and its solution. The best solution may be some heuristic approach by trying each combination and evaluate them. Tip: use structs and arrays to write...
26 Mar 2023 by OriginalGriff
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for...
25 Mar 2023 by Gcobani Mkontwana
Hi Team I want to Write a function that takes as arguments: A string representing JSON graph of the road system The starting intersection (node) The ending intersection (node) And returns a dictionary containing information about the shortest...
22 Mar 2023 by Richard MacCutchan
In order to use the [] operator you need to implement 3. Data model — Python 3.11.2 documentation: __getitem__()[^]. See also 3. Data model — Emulating container types[^] for complete details.
22 Mar 2023 by DosNecro
class Node: def __init__(self, key, value): self.key = key self.value = value self.next = None class LinkedList: def __init__(self): self.head = None def search(self, key): curr = self.head ...
21 Mar 2023 by OriginalGriff
Don't repost your question: it doesn't help you get an answer quicker, it reduces your chances of getting a solution at all. I'll delete this one.
21 Mar 2023 by Member 15957894
ABC decides to constitute a communication team. A communication team consists of employees such that for every employee who is not in the team, there is a person in the communication team that is familiar with her work. Further the management...
13 Mar 2023 by Yor Gurt
I have n sets of two items: ["a", "b"] ["c", "d"] ["d", "a"] ["b", "c"] And I want to find at least one item from this set (if it exists), that passes the following constraints: The first constraints is a sort of exclusion check (= we are...
22 Feb 2023 by Maminiaina Rakotovao
I'm trying to find all possible paths in a MxN matrix starting from the top left to reach the bottom right. Four moves are allowed (up, down, right, left). Example 1: Input: [[1,2,3],[4,5,6]] Output: 1 2 3 6 1 2 5 6 1 4 5 6 1 4 5 2 3 6 ...
21 Feb 2023 by OriginalGriff
Getting your code to run does not mean it is right! :laugh: Think of the development process as writing an email: compiling successfully means that you wrote the email in the right language - English, rather than German for example - not that the...
20 Feb 2023 by OriginalGriff
Sorry, but this is not a software problem - it's a puzzle / logic exercise, and we aren't here to work them out for you! We aren't here to do anyone's work for them, regardless of the subject involved - while we are more than willing to help...
18 Feb 2023 by merano99
Currently, this is C source code. The other programming languages according to the tag are irrelevant. There are several errors: // Str = (char**)calloc(5, sizeof(char)); need space for pointer, use n for size! Str = (char**)calloc(n,...
18 Feb 2023 by Addy__0
#include #include #include char **StringArray(char **arr, int size); int main() { char **Str; int n= 5; int i; Str= (char**)calloc(5,sizeof(char)); Str[0]= (char*) calloc(10, sizeof(char)); ...
17 Feb 2023 by OriginalGriff
Probably because it doesn't compile: you declare StringArray as returning achar** - but the function body does not have a return statement. If code doesn't compile, then it doesn't generate an EXE file - so what you are running is the previous...
17 Feb 2023 by CPallini
Quote: Str= (char**)calloc(5,sizeof(char)); That should beStr= (char**)calloc(5,sizeof(char *)); Might be there are other errors, as well. Anyway the code is not robust against user input.
16 Feb 2023 by Ayat Rakhishev
A walkthrough of dynamic programming
12 Feb 2023 by ronnanteplely
Hi, I have n items, each item has 3 properties. I want to match the second two properties with some values A, and B, and at the lowest property[0]. Below is my best attempt at solving this issue (see "what have I tried") This code, however,...
12 Feb 2023 by OriginalGriff
Compiling does not mean your code is right! :laugh: Think of the development process as writing an email: compiling successfully means that you wrote the email in the right language - English, rather than German for example - not that the email...
9 Feb 2023 by Kenneth Haugland
How to speed up convergence of mathematical series
7 Feb 2023 by George Swan
A .NET7 version of a Rotated Binary Search method
6 Feb 2023 by Yor Gurt
We have n item types, each item type has 3 properties: price, a, b: { price: 4.0, a: 12.0, b: 12.0 } { price: 1.0, a: 2.0 , b: 4.0 } { price: 0.5, a: 1.5 , b: 0.5 } We also have two global a and b values: a: 5.0 b: 7.0 We need to find a...
5 Feb 2023 by Patrice T
Quote: This solution probably doesn't work, since we can't be sure that our last items will be able to cover the last fraction. Difficult to tell if your solution works or not, without seeing your code. As I read the requirement, It makes me...
5 Feb 2023 by OriginalGriff
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for...
2 Feb 2023 by Романюк Надія
I want to write a Markov algorithm that converts numbers such as ||| (3) ||||| (5) and so on into, decimal numbers So I'm studying algorithms for fun and I came over this problem . The tasks says to do it with numbers 1 - 10. It is pretty easy,...
29 Jan 2023 by Graeme_Grant
Below are the changes in my previous solution to get the result that you wanted. Form this: if ((testValue == currentValue || testValue == currentValue - 1) && Math.Max(nextValue, testValue) == testValue) { nextValue = testValue; nextCell =...
29 Jan 2023 by Yor Gurt
The original question can be found here, I've decided to create a new thread, since the old one was getting very confusing for newcomers I have a 2D matrix, that may look something like this: 0 1 2 5 4 3 7 8 9 I'm trying to find a path that...
24 Jan 2023 by Yor Gurt
I HAVE DECIDED TO CREATE A NEW QUESTION, SINCE THIS ONE WAS GETTING VERY MESSY AND CONFUSING. Heya, I have a 2D matrix, where each element holds a height value, an example matrix may look something like this: 1 2 3 6 5 4 7 8 9 I'm trying to...
20 Jan 2023 by Graeme_Grant
You have not specified a language, so I am guessing that you want a pseudo-code solution. It would be something like the following 1. store current value (var_next) 2. check adjacent cells for equal to the (var_next) or less while skipping...
19 Jan 2023 by GalBrot
I have a row of bits: 001111000000000 And i want to flip all of these so that they're false, but I only have a set number of commands to do this, these commands look like this: 3, 5, 7, 11, 13, 17, 19 ... (prime numbers, excluding 2) Each...
17 Jan 2023 by Graeme_Grant
Binary: 00111100000 = Decimal: 480 Find all the factors of 480 - ie: numbers that would divide 480 without leaving any remainder. eg: 480/10 = 48; therefore, 10 is a factor of 480 and 48 is also a factor of 480. Hence, the factors of 480 are 1,...
11 Jan 2023 by Andrea Simonassi
A simple yet powerful multiplication algorithm
10 Jan 2023 by timetraveller1992
I have a bookshelf that looks like this. The measurements of the same bookshelf. Other than the topmost rectangle which has a height of 42cm, the rest of them are equal and smaller i.e. 35.5cm. The width of all rectangles is the same i.e. 55cm...
10 Jan 2023 by FormerBIOSGuy
This article describes a set of batch, AWK, and PostScript files that together allow you to create personalized, 12-page PDF calendars for some year.