Category "algorithm"

Tweaking Dijkstra's Algorithm to detect minimum length cycle in directed graph

I am trying to find the minimum length cycle in a directed graph but this time using a greedy algorithm. I think the smartest way to do it is using Dijkstra's A

python: what is a best way to find paths with x length in 2d array?

Assume that I have an array like this [[0, 1, 0, 0], [1, 0, 2, 5], [0, 2, 0, 0], [0, 5, 0, 0]] each index is a node index so [0, 1, 0, 0] means node0 has a edge

How to implement Modular Exponentiation Code

Please I was learning from the book Introduction to algorithm (Chapter 31 page 957) and came across this pseudocode. This pseudocode is how we can implement the

Peak and Trough of Numeric Data

Can anyone help me please. I need to find the peak and troughs in a data series but with 2 conditions which are: Peak or trough is peak for minimum of n(days) L

Find the nth character of an increasing sequence

Recently i saw a competitive coding question, the bruteforce approach doesn't meet the time complexity, Is there any other solution for this, Question: An expan

Latex algorithm cross-column typesetting

How to use latex to implement the multi-column algorithm in the link below, thank you very much. multi-column algorithm

determine if the shortest path in a graph is unique

Say I have a cyclic graph containing bi-directional and parallel edges e.g. Assume all edge weights equal 1. How would I determine if the shortest path is a un

Power of 3 in mod 1000000007

Let k be a positive integer. Is it possible to find out the value of 3^k in mod 1000000007? I have written a C program code to do this but it gives a message on

O(log n) algorithm in theory runs much slower in practice

The algorithm is for calculating 2^n recursively. I have used the Master theorem to determine that the time complexity is indeed O(log n) which seems to correct

minimum number of jumps dynamic programming

I wrote this code to solve a problem called minimum number of jumps which basically asks what are the minimum number of jumps it takes to get from the beginning

Python - Conditional 2D Permutation

Question: How might it be possible to calculate the permutations on a 2D array, but such that the sum of the indicies cannot exceed a certain number? E.g: maxsu

Tweaking Floyd-Warshall Algorithm to detect cycles

Cheers, I am trying to solve the problem of minimum length cycle in a directed graph, and I came across a solution that suggested that I should tweak the Floyd-

Getting Segmentation Fault in the problem "Maximum Rectangular Area in a Histogram" on GFG

Problem: Maximum Rectangular Area in a Histogram link: https://practice.geeksforgeeks.org/problems/maximum-rectangular-area-in-a-histogram-1587115620/1 Website:

Hwo to change dynamically the last two parameteres?

I have the followng string https://picsum.photos/id/1025/4951/3301 I need to replace here the last two numbers 4951 and 3301 with 200 so at the end i will have

Simple shape recognition and classification by algorithm

I'd like to classify simple shapes (see the attached "sample resource of shapes") algorithmically (automatically). Does anyone know how to do that? The intended

Algorithms to find shapes among random points

Let's assume we have: A) a large set of random 2D points, and B) a small set of 2D points representing a simple geometric shape of choice, e.g. a triangle (3 x

Which sorting algorithm has the best asymptotic runtime complexity?

It's a choice problem between heap sort, merge sort and insertion sort. However the best case for insertion sort is O(n) and the worst is O(n^2) Which complexit

sum up an array in the special style of reduction | (i * 2)

I am currently sitting on a java problem I've found online. We have an array which has several thousand, if not millions, of entries. the goal is to efficiently

Apply Swap Operation at Most Once to get a Strictly Increasing Sequence

I am doing some of these DS&A questions on various sites online for practice and I ran into this one: Given an array of non-negative integers numbers,

Stack balanced Parentheses build log show :- Process terminated with status -1073741510 (0 minute(s), 2 second(s))

When I try to implement parenthesis problem using stack (array representation) it showing above problem. Here I use dynamic memory allocation in array. When I