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
1 vote
0 answers
5 views

Much more efficient trisexual genetic algorithm for TSP in Java

This time, I have made the previous version of the GA for TSP run faster by around the factor of 6+. The idea is to cache the tour costs with the actual tour objects and cache the hash codes of each ...
user avatar
  • 25.1k
2 votes
0 answers
47 views

Genetic trisexual algorithm for TSP in Java

(A more efficient version of the GA.) This is my the very first take ever on GA: GeneticTSPSolverV1.java: ...
user avatar
  • 25.1k
2 votes
1 answer
53 views

Golang solution to CTCI 1.2: Check whether two strings are permutations of each other

Just started learning Go recently. Did some questions from Cracking the Coding Interview book. Wrote the solutions in Go. Let me know what you think. https://github.com/samjingwen/ctci Below is ...
user avatar
3 votes
1 answer
90 views

The shortest path between airports

Airlines need to provide their customers with flights to every corner, so they need an app that allows them to do so. The customer must be able to transfer when there is no direct connection. The ...
user avatar
0 votes
2 answers
67 views

Encryption and Decryption in C

I have written a program in C, which encrypts and decrypts a c-styled string (const char *) and print the result to stdout. It ...
user avatar
2 votes
1 answer
40 views

Algorithm Challenge: Fuzzy Search

I recently took part in an algorithm challenge to create a Fuzzy search with the following criteria: Given a set array, create a function that receives one argument and returns a new array containing ...
user avatar
1 vote
1 answer
41 views

Genetic TSP in Java with graph expansion

This post presents my take on TSP (travelling salesman problem). The idea is to: Take an input node i, Compute the entire graph ...
user avatar
  • 25.1k
2 votes
1 answer
58 views

Leaky Bucket Algorithm with no Queue

Basic implementation of a leaky bucket, the idea is you call it by saying I will allow e.g. 5 login attempts per 60 seconds. ...
user avatar
2 votes
0 answers
55 views

Rijndael Cipher in C++ (128bit AES)

I am a hobbyist and do not work in the industry but do have an interest in programming an cryptography. I decided to have a go at writing a 128bit implementation of AES in C++. This is my first ever C+...
user avatar
3 votes
1 answer
60 views

Traditional vs. bidirectional Dijkstra's algorithm in C

I have this CLion project on GitHub. It constructs a directed, weighted graph consisting of 100 thousand nodes and 500 thousand directed arcs, picks two random nodes, and computes the shortest paths ...
user avatar
  • 25.1k
3 votes
1 answer
43 views

Percolation threshold simulation using C++

I am studying Algorithms by Princeton University. The first week assignment is to simulate percolation by using Java. https://coursera.cs.princeton.edu/algs4/assignments/percolation/specification.php ...
user avatar
  • 135
1 vote
1 answer
42 views

Group a list of objects by property and remove the first value from each group

I have a list of Students and I want group this list by the property NAME, to sort each group ASC by the property ...
user avatar
  • 143
1 vote
1 answer
39 views

Comparing two general LCA algorithms in Java

Now I have two algorithms solving a problem: given a general (multi-way) tree, and any array of node names, find the the node that is the deepest common ancestor. ...
user avatar
  • 25.1k
0 votes
0 answers
27 views

General (multiple nodes) LCA queries in Java

I have an algorithm for computing multiple node LCAs (lowest common ancestor): TreeNode.java: ...
user avatar
  • 25.1k
0 votes
1 answer
35 views

Sorting in linear time using Trie Data Structure

I have written an article on a new way of non comparison sorting and I want it to get peer reviewed. The sorting algorithm uses Trie data structure to store digits of numbers as nodes and iterating ...
user avatar
3 votes
1 answer
107 views

gradient descent implementation

I am attempting to implement my neural net for a fully connected network configuration. I don't know much about neural networks and ai, so the implementation is not great and may contain errors ...
user avatar
3 votes
1 answer
182 views

Update user's experience points

I have a private method in my class to update user experience. First of all, I create giveExp based on contentLength (...
user avatar
1 vote
1 answer
34 views

Synchronization \ backup of directories and files (Python)

stackexchange members. I'm just learning to write. I set myself a task a few days ago and today I completed its implementation. The task was to create a "backupper" (I was inspired just by ...
user avatar
2 votes
1 answer
473 views

Most frequent element in an array, return lowest if multiple

I have been learning C++ for the past 2 weeks. Following is a problem I solved from Hackerrank. I am somewhat unsure if it's the correct way to solve this, even though I got the desired output. How ...
user avatar
  • 89
3 votes
3 answers
70 views

Replace string with another string in C

I have written a program that replaces a given c-string with another c-string. My code works well with small files but takes too much time while working with large files (50 Megabytes and larger). ...
user avatar
0 votes
1 answer
44 views

Time complexity of several methods of reversing a domain name string

Note: I'm aware of this existing post which is similar. However, it does not address all my questions sufficiently. I have the following three functions, all of which do the same thing: reverse a ...
user avatar
6 votes
1 answer
369 views

LFU Cache implementation in Python 3

Need some feedback on this implementation of LFU cache in python3. Original problem : https://leetcode.com/problems/lfu-cache/ Would really appreciate some feedback on readability, understandability ...
user avatar
  • 63
0 votes
2 answers
92 views

Sequential Search - Recursion

I have written this program to search for a value in an array using sequential search. And well, I've been trying to implement the same algorithm using recursive structure. is this a good ...
user avatar
4 votes
1 answer
81 views

Karatsuba's multiplication

I am working my way through an algorithms course online, and the assignment is to implement Karatsuba's multiplication algorithm. I am also trying to practice C++, so I wanted to implement it in that ...
user avatar
  • 135
2 votes
1 answer
47 views

Priority Queue for D* Lite

So, I needed a priority queue for D* lite and I wanted to know whether this is an acceptable implementation or not. ...
user avatar
  • 57
0 votes
2 answers
99 views

Finding the largest value in array - Recursion

I know this may be a silly question (I'm just learning about recursion, and I think there are still things that are still not clear to me.), but... is this a good implementation of a recursive ...
user avatar
9 votes
3 answers
771 views

C++ merge sort implementation (looking for advice)

I am trying to practice C++, so I decided to implement canonical algorithms in C++ as a way to learn best practices and idioms of the language. I started with merge sort. How could I improve this ...
user avatar
  • 135
4 votes
2 answers
82 views

Binary Search Tree - My own version of delete function

Well, I am recently learning data structures and algorithms and I came across the Binary search tree and decided to first time use my own logic to make the delete function. I have not come across a ...
user avatar
4 votes
2 answers
954 views

Algorithm to find the sequence of bits that makes up to a given number

...
user avatar
  • 1,353
1 vote
1 answer
45 views

Manacher Algorithm in Haskell

Please review the manacher algorithm in haskell. Find the longest Palindrome in a String. ...
user avatar
  • 237
6 votes
1 answer
344 views

Count lengths of constant subarrays

I have an array assuming discrete values. For each value, I am interested in how often it is assumed in a row. For instance, if my array is ...
user avatar
5 votes
2 answers
510 views

Guessing game - Too high. Too low

I will post 2 scripts that are doing (supposedly) the same thing. First one is the script i created, second one is the solution from the course. What would you consider wrong (if anything) with the ...
user avatar
  • 59
3 votes
1 answer
438 views

Which fruit fall onto my house?

I am following a question on a programming challenge website (here's the original reference). What I have is a house (start & endpoint) and some types of trees at their respective location points. ...
user avatar
  • 33
0 votes
0 answers
19 views

Array of values determine if they vary wildly (or not) using z-score

Determine how 'spikey' graph data would be I want calculate if a list of random set of unsorted numbers present themselves as varying greatly over the one value to the next. The thought is to be able ...
user avatar
  • 113
4 votes
1 answer
119 views

Searching for a performance bug in a C++20 pathfinding algorithm (NBA*)

(See the next iteration.) I have this pathfinding algorithm: DirectedGraph.hpp ...
user avatar
  • 25.1k
2 votes
0 answers
21 views

Maximum length of a row made up from given dominoes

Given a set of dominoes, find the maximum length of a row that can be made using some of those dominoes. Rotating the dominoes is allowed. Recall: A domino piece consists of 2 numbers from 0 to 6 (e....
user avatar
6 votes
2 answers
349 views

Wordle color algorithm in JavaScript

A lot of Wordle clones get the tile-coloring algorithm wrong: for example, if the word is BURNT and you guess TOAST, the colors should be ----G (not Y---G) if the word is MAXIM and you guess MAMMA, ...
user avatar
  • 18.9k
4 votes
1 answer
63 views

Optimizing Code for Spectral Gradient algorithm in Python

I am building an algorithm to run proximal spectral gradient for research purposes. The code is almost in its finalized step, but the runtime of the code is slow. I hope to seek your professional ...
user avatar
2 votes
2 answers
111 views

Create a custom split method that keeps the delimiters in Swift

I have implemented a custom split method that replicates the original functionality of the collection's split method in Swift and keep the delimiters (element separator). After a lot of trial and ...
user avatar
  • 155
1 vote
1 answer
49 views

Is this implementation of the First Come First Served algorithm the most appropriate? How can it be improved?

I have developed a program that implements the First Come First Served scheduling algorithm. The total number of processes is read directly from the input standard, and for each process the arrival ...
user avatar
  • 483
3 votes
2 answers
119 views

Encoded string algorithm with given rules

Looking for general feedback and if there is a solution that can reduce the time complexity from the current O(n2)? Thank you. Problem Statement Consider a string that consists of lowercase English ...
user avatar
2 votes
1 answer
75 views

Python functions that calculate first n terms of a given order of Fibonacci sequences

I have written two functions that calculate the first n terms of a given order o of Fibonacci sequence, and return the result as ...
user avatar
3 votes
1 answer
131 views

Huffman coding implementation in java

I wrote a simple huffman coding algorithm for learning and practice. I just used the technique given on the wikipedia page. Could you tell me my missing points and mistakes? Node.java ...
user avatar
7 votes
2 answers
441 views

Median cut algorithm

I have implemented a simple version of the median cut algorithm. It takes a vector of Color structs representing pixel in an image. I also use the ...
user avatar
0 votes
0 answers
43 views

How to optimize `push` and `pop` in this tree list algorithm?

So based on this question and answer, which is based on this answer, I have abstracted it out into a reusable module. Basically it is the TLList class, with a ...
user avatar
  • 279
3 votes
0 answers
48 views

How to remove duplication in this array/tree generating function?

Here we have the following code. ...
user avatar
  • 279
2 votes
1 answer
109 views

Related to DSA: Find longest common prefix

The objective of below code is find longest common prefix from trie DataStructure which is written in Java. Code: ...
user avatar
  • 23
2 votes
0 answers
57 views

Dijkstra's Shortest Path Algorithm

Is there anything I could do better in this Dijkstra's Implementation. This is my implementation of Dijkstra after understanding the concept. I used hash table wherever possible to have faster access <...
user avatar
1 vote
1 answer
54 views

How can I avoid duplicate processing of vertices in the priorityqueue with Dijkstra?

So everytime a neighbors is discovered with an improved distance, it is added to the priorityqueue with the new distance (so it can be used in the right order). This means however that the old entry ...
user avatar
  • 143
5 votes
1 answer
90 views

Greedy number partitioning algorithm

I have two functions in Python that do the same thing: they partition a set of items of different sizes into a given number of subsets ("bins"), using an algorithm called greedy number ...
user avatar

1
2 3 4 5
98