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.
0
votes
0answers
13 views
Is there anything wrong with this merge sort approach?
I'm working my way through a book on algorithms. One of the first challenges is the merge sort. I've seen this implemented before, but as the book suggested I coded one from just the method without ...
1
vote
1answer
38 views
My own algorithm to sort integers
I'm studying the C language with a Harvey Deitel book.
Trying to solve an exercise that asked to write a good sorting algorithm, I did this:
...
0
votes
0answers
18 views
Speed up Magic square program
I have written a Java program to calculate magic squares with recursion and backtracking. A 3*3 Magic square is calculated in about 1 sec, but a 4*4 needs about 50 minutes on my laptop with Intel i5. ...
0
votes
0answers
40 views
Huffman Coding API in Swift
This question is a follow up question to: this post
I'd love some advice on my implementation and the API of the Huffman class.
I'm also not sure how to test if ...
2
votes
1answer
70 views
Robot Block Command
Problem
We have a robot that can pickup blocks from a stash, move them
horizontally and lower them in place. There are 10 positions available
to lower blocks number 0 to 9. Each position can ...
-1
votes
0answers
16 views
Dijkstras algorithm implamentation for tsp in java [on hold]
This is a working implementation of Dijkstra's algorithm to solve a TSP problem (I understand that this is not the "best" solution for the problem, but for educational purposes, I've looked into this ...
1
vote
0answers
24 views
Maximize product of sum of subsequences
Code Chef Problem description
You are given a sequence of \$N\$ powers of an integer \$k\$; let's denote the \$i\$-th of these powers by \$k^{A_i}\$.
You should partition this sequence into two ...
1
vote
0answers
33 views
Sorting cards by suit and value using Shell Sort
The question description: put a deck of cards in order by suit (in the order spades, heart, clubs, diamonds) and by rank within each suit, with the restriction that the card must be laid out face down ...
1
vote
1answer
69 views
Huffman Coding in Swift
I’m learning Swift and decided the Huffman Coding algorithm would be a good exercise while learning this new language. Below is a working version that encodes a ...
2
votes
2answers
87 views
Substrings search (Aho-Corasick algorithm)
I have a code where the goal is to give score to strings based on how much score certain substrings are worth (including repeating substrings).
The way my code (which is based on the Aho-Corasick ...
2
votes
2answers
77 views
Find kth smallest element in binary search tree
I was faced with below interview question today and I came up with below solution but somehow interviewer was not happy. I am not sure why..
Given a binary search tree, find the kth smallest ...
2
votes
2answers
62 views
Given some integers, find triplets where the product of two numbers equals the third number
I am trying to solve a coding challenge:
Given N integers A1, A2, …, AN, count the number of triplets (x, y, z) (with 1 ≤ x < y < z ≤ N) such that at least one of the following is true:
...
0
votes
0answers
48 views
Verify binary search tree with duplicate keys
Given a binary tree with integers as its keys I need to test whether it is a correct binary search tree. Duplicate integers allowed. Smaller elements are to the left, bigger elements are to the right, ...
3
votes
1answer
93 views
“Counter Game” Powers of 2 Game
I have been working on this hackerrank problem:
Louise and Richard have developed a numbers game. They pick a number (1 ≤ n < 264)
and check to see if it is a power of 2. If it is, they divide ...
1
vote
0answers
23 views
Dijkstra Implementation: Comparing my program with widely available Internet Java program
I wanted to discuss Dijkstra's implementation that I generally find on Internet, and then compare it with my own implementation.
On Baeldung and on Vogella (Thanks to both and many others, that I ...