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
11 views
List comparison algorithm
I am attempting to create an efficient algorithm to pull all of the similar elements between two lists. The problem is two fold. First, I can not seem to find any similar algorithms online. Second, ...
-1
votes
0answers
16 views
performance of nCr%m? [on hold]
I'm trying to find nCr%m.
I have tried Euler's Modular Inverse method but It also happens to be slow.
then I came across this implementation of Lucas Theorem:
...
2
votes
0answers
10 views
Strongly connected components, component graph, semiconnected graph and new graph from SCCs
I have written a program in C to do the following:
Read a matrix (in file format, first line you have the size, then next are the entries). This is done by the "input" function.
Find the strongly ...
2
votes
1answer
28 views
Graph adjacency list implementation in C++
I have been playing around with an adjacency list implementation of a graph class, on which I'd like to be able to run a build and test several graph algorithms. The code I have below works and I have ...
-1
votes
0answers
16 views
Deleting a node with two children in a binary search tree [on hold]
The basic Idea would be to exchange the node's inorder successor value with node value . Now the node to be deleted is
...
3
votes
1answer
75 views
Calculating harmonic sum
The problem is that I have executed the program for the last hour and it hasn't returned a value till now for input 1022. How can I make the program a bit faster? How can I increase the efficiency of ...
-1
votes
0answers
15 views
1
vote
2answers
60 views
Find non duplicateTriangle Triplets from a list of given numbers
I implemented an O(N^2) algorithmic solution but not sure it is better than my previous implementation Find Triangle Triplets from a list of given numbers
in case of performance. I adapted almost ...
4
votes
1answer
75 views
Find Triangle Triplets from a list of given numbers
If a triplet of segments A, B and C are triangle triplets if and only
if
A + B > C
A + C > B
B + C > A
Is there a better implementation for this problem?
...
1
vote
0answers
7 views
Ascii85 in Elixir
I'm a complete newbie to Elixir, but I managed to bang together this working example of Ascii85 for a project I'm working on in my spare time.
I find some awkward repetition in here which I have ...
1
vote
1answer
30 views
Selection sort implementation in Java
Here's an implementation of selection sort, that sorts an array in ascending order.
Please let me know of any improvements/optimisations that can be done.
...
1
vote
0answers
17 views
Insertion sort in Java
I've written a stable implementation of insertion sort, that sorts an array in ascending order.
Please let me know of any improvements/optimisations that can be made.
...
6
votes
1answer
57 views
Finding Pattern score
You are given 3 strings: text, pre_text and post_text. Let L be a
substring of text. For each substring L of text, we define
pattern_score as follows:
...
3
votes
1answer
135 views
Find minimum element in a rotated array
Here's an implementation of finding the minimum element in a rotated array using binary search (one that is sorted in ascending order, and all elements are distinct).
Please let me know of any ...
5
votes
3answers
208 views
Find common characters
Given two strings, find the common characters.
Is there better implementation for this problem?
...
3
votes
2answers
69 views
Airline seating algorithm: how to seat a passenger in mirror image to previous allocated seat
I have a seat allocation algorithm for an airplane 30 x 6 seats.
The plane is 'split' front (1 - 15) and back (16 -30), right (A,B,C) and left (D,E,F). I am placing passengers in window seats front ...
3
votes
2answers
67 views
Simple string hashing algorithm implementation
I thought of a simple way to hash a string. By taking the ASCII decimal value of each character, multiplying it by 10, and adding all of the values computed together for each character in a string. Is ...
2
votes
1answer
34 views
Create ranges from an array of integers
Given an array of ints, return a string identifying the range of numbers
Example
Input arr - [0 1 2 7 21 22 1098 1099]
Output - "0-2,7,21-22,1098-1099" .
Is there any improvement possible in this ...
4
votes
2answers
53 views
Fast way to count the numbers that are divisible by their own sum of digits inside a range
Inspired by this question on Stack Overflow, I wrote a function that returns the length of a list made of numbers that are divisible by their own sum of digits inside a range:
...
2
votes
2answers
97 views
QuickSort in Java
I've written my first implementation of quicksort in Java 8. Please let me know of any improvements that I can make (e.g. whether I'm creating any Lists ...
1
vote
1answer
41 views
Swapping Elements in a list
Challenge:
Swap positions in a list
Specifications:
Your program should accept as its first argument a path to a filename.
The file contains several test cases, one on each line.
Each ...
19
votes
7answers
3k views
Checking if a number is divisible by 9
I tried to develop a new way to check if a number is divisible by 9. I have written my code and it is working fine. I'm not allowed to use *,...
4
votes
1answer
35 views
Implementation of the FNV-1a hash algorithm for 128-, 256-, 512- and 1024-bit
A little over a year ago, I asked this question. Since then, I've implemented the larger bit variations and am looking for any and all feedback - performance is obviously key when talking about ...
-1
votes
0answers
14 views
Reverse of linked list not working with argument [closed]
These are the reverse and display functions of the linked list.
Correct output :
...
2
votes
1answer
67 views
Determine the index where two lists diverge
Background
A class provides an API to determine the index where two string lists diverge.
...
3
votes
2answers
71 views
Check is_permutation on a pair of same sized arrays
After considering the suggestions of my previous question Check whether given a pair of arrays are permutation of each other, I changed the code.
Resolved the bug reported earlier
In place of ...
6
votes
3answers
168 views
Stack with getMin method
This should implement a stack that has a \$O(1)\$ getMin method. I used an auxiliary stack. Please provide comments on my solution.
...
5
votes
1answer
36 views
Update on Weave Merging n lists into single list
This is a follow up to my previous post from 7 months ago. I changed up the algorithm a little. Instead of inserting items into a new list, each item's final place is calculated up front. Sort of like ...
3
votes
3answers
215 views
Check whether given a pair of arrays are permutation of each other
Check whether two given arrays are permutation of each others.
Does this implementation guarantee execution of \$O(n)\$ time? What is the additional space utilization for this implementation by ...
2
votes
1answer
66 views
Object pool with linked list of available objects implementation
I was reading some gameprogrammingpatterns (awesome book, by the way, would recommend) and was very excited when I learned that unions are a thing that exists, so I decided to implement an object pool ...
2
votes
1answer
52 views
Generating a triangle from integers
I've put together an algorithm for an assignment. I've done my best to try and keep it to a professional and readable standard. I'm posting it here so that I can get some feedback and suggestions on ...
1
vote
1answer
36 views
Returning Function Calls from an Array within a JavaScript Function
I'd like to use JavaScript to generate HTML.
I've made a JavaScript function object that has two parameters; a string and generic object. The string is used to specify the type of HTML element you ...
5
votes
1answer
40 views
Sort a stack in ascending order
Sort a stack in ascending order. You may only use one additional stack to hold items.
Any comments on my solution?
Worst case complexities:
Memory complexity: O(n)
Runtime complexity: O(n^2)
Also, ...
1
vote
0answers
65 views
Create pairs from a set of numbers
Problem here is to list all pairs from a set of integers. We need 2 versions. In the first program, the order matters — pairs (a,b) and (b,a) are considered distinct. In the second program, (a,b) and ...
7
votes
1answer
74 views
Calculating 24 from 4 numbers (math Poker game)
This is a game of math in Poker. Two people each have a pile of cards. They then each place 2 cards on the table at the same time. Every card is treated as a number. The players need to find a way to ...
3
votes
1answer
148 views
Shortest path using Breadth First Search
I have sample graphs like the following(Un-directed un-weighted cyclic graphs). My goal is to find shortest path between a given source and destination.
...
4
votes
1answer
143 views
Finding whether there exists a pair of numbers in a set having a given product
Devise an algorithm that will operate on a number x and a set of n
distinct numbers such that in \$O(n \lg n)\$ time, the algorithm indicates
whether or not there are two numbers in the set ...
2
votes
1answer
49 views
Implementation of quicksort algorithm
I'm currently doing an algorithms course and implemented this version of the quicksort algorithm. I would like to know if it is an efficient implementation. I've seen a couple others where there is a ...
0
votes
1answer
42 views
Generate all permutations
I have written this Java snippet to generate all permutations of a given array of integers. Can somebody review it and give some pointers as to how to make it more generic? I.e. instead of dealing ...
3
votes
2answers
84 views
Cook and Felderman analysis to perform data reduction on heated surfaces
This is a "pain", but I wonder if I can get any real speedup with the follow Python script - it is taking well over 10 minutes to calculate the way it is written now. (And that's only when feeding ...
8
votes
2answers
326 views
The 3n + 1 algorithm for a range
Essentially the Collatz Conjecture.
Challenge requirements are here.
And here is my implementation in Java:
...
1
vote
1answer
51 views
String reverse function
Are there more optimization possible in this code to achieve better performance and minimal memory usage?
...
3
votes
2answers
78 views
Improving the efficiency of my FizzBuzz algorithm [closed]
I worked on an exercise from codewars, which is a variation of the popular fizzbuzz game. (If the link doesn't work, you may need to reload the page.)
In this variation, I'm supposed to find the sum ...
5
votes
2answers
68 views
Knuth's Word Wrap Algorithm in Haskell
I put together a Haskell function for Knuth's word wrap algorithm. A simplified version of the algorithm is described here.
I've already been told that there are certain aspects of my style that are ...
2
votes
1answer
62 views
Finding the common prefix in a list of strings
Given a list of strings, my task is to find the common prefix.
Sample input: ["madam", "mad", "mast"]
Sample output: "ma"
...
3
votes
1answer
46 views
Find the highest number satisfying a condition in an infinite range
I wrote the below function for doing a variation of bisection search that I came up with. This can be useful when the higher bound is not known. It assumes that as number increases the result of the ...
10
votes
4answers
150 views
Get random direction based off of location and previous direction
I've recently implemented a Wilson's Algorithm for maze generation. This problem however could also be extended to things such as snake, or some other simple AIs.
The problem is as follows:
Blue ...
2
votes
0answers
47 views
Classic sorting algorithms [closed]
I implemented the classic Sorting Algs in JS for practice. I come from a C++/Java background. Just wanted to make sure I didn't miss anything or if there was a 'better' JS way of doing it.
Also, I ...
1
vote
0answers
53 views
Naive Grouping for Factorization
I have a naive grouping method for factorization. I am curious as to its novelty and aspects of the code below that will increase its efficiency.
The method is best described with an example:
For n ...
4
votes
0answers
37 views
filter function implementations using copy_if Algorithm vs. For Loop
I have the following method of some class, which also defines the method isAllowed:
...