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
6
votes
3answers
84 views

Counting the triangles that can be formed from segments of given lengths

Problem Statement: Given an unsorted array of positive integers. Find the number of triangles that can be formed with three different array elements as lengths of three sides of triangles. ...
1
vote
1answer
29 views

LeetCode #1066 - Campus Bikes II

The following code implements the Hungarian algorithm. The algorithm is used to find minimum cost perfect matching on a bipartite graph. Looking for comments on correctness, efficiency, clarity and ...
4
votes
2answers
78 views

Calculate the rates at which users get stuck at each stage

I completed an algorithm problem just as a personal study, and I can't help but feel like my solution is a bit needlessly complicated, although I can't figure out a better way to do it. Here's the ...
8
votes
4answers
674 views

Expanding powers of expressions of the form ax+b

I solved the following problem: Write a function expand that takes in an expresion with a single, one character variable, and expands it. The expresion is in the form ...
-1
votes
0answers
23 views
4
votes
1answer
53 views

Count words with given prefix using Trie

I have been trying to solve this HackerRank problem: We're going to make our own Contacts application! The application must perform two types of operations: add name, where is a string ...
1
vote
0answers
44 views

Python script converts a subset-sum instance into a unary-ssum variant

I am done with my amateur project for subset-sum. This python script is meant to simulate a poly-time (or actual poly-time) conversion from binary into unary. ...
-4
votes
0answers
27 views

The Randomized algorithm Parody [on hold]

I was reading CLRS and I was stuck at question 5.1-2. Describe an implementation of the procedure RANDOM(a,b) that only makes calls to RANDOM(0,1).What is the expected running time of your procedure, ...
1
vote
0answers
78 views

DFS cycle-detecting algorithm in Swift language [on hold]

I'm reviewing my algorithms fundamentals by writing them in swift. I was able to get this version of the Detecting Cycles using the iterative DFS algorithm to work for a number of test graphs but am ...
7
votes
2answers
106 views

Document distance in Python

I wrote a script to calculate document distance. It seems working but I couldn't be sure. (I tried for the small strings and it seems working) Also I am not sure that its fast enough for large texts. ...
-2
votes
0answers
69 views

Numerical Euler method

I made an Euler method(an taylor of order one numerical method) in which you can plot different parameters, and see how this affects the method. It works, but I have the sensation that it's horribly ...
-2
votes
0answers
22 views

code to find first day of given year with respect to Gregorian Calendar [closed]

I want to know is it safe or accurate if I use following method to find first day of given year, using GCC with Code block ...
2
votes
2answers
62 views

How to make my backtraching sudoku solving algorithm in Python faster?

I wrote a backtracking Sudoku solving algorithm in Python. It solves a 2D array like this (zero means "empty field"): ...
1
vote
0answers
68 views

Custom Knight dialer solution's time and space complexity

I recently solved the Knight Dialer problem but I'm not quite sure if I got the time complexity right; hence I'm requesting the following: 1) Time and space complexity review and explanation on why ...
2
votes
2answers
68 views

LeetCode #1120 Maximum Average Subtree (Python)

This code snippet shows 2 common patterns I see a lot in Python that I don't really like: Arbitrarily-named, narrowly-scoped recursive function Inappropriate data type (in this case, an array ...

15 30 50 per page