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
4
votes
2answers
88 views

Improving quick sort algorithm (Python)

I'm learning algorithm and this is my implementation of quick sort, please guide how can i improve it further and what are other more optimal ways to implement quick sort? ...
2
votes
2answers
72 views

Python - Hexadecimal to Decimal conversions

I have written a python 2 program for a school project to convert from hexadecimal to decimal without using built-in functions and vice versa in python. I would like to know how I can make my code ...
3
votes
1answer
85 views

Matrix Transpose in Golang

I have write a normal programm "Transpose the matrix" in go. Suppose input are always correct. I also read the article An Efficient Matrix Transpose in CUDA C/C++. So I keen to know how I can use Go-...
1
vote
1answer
56 views

Shortest distance between two words in the list [closed]

Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list. Example: ...
1
vote
0answers
18 views

Minimum router Peripherality Breadth First Search (BFS) Algorithm performance

I have solved the MinRouterPeripherality task in codility using javascript using Breadth First Search(BFS) approach. However time complexity is O(N^2). I am really ...
4
votes
0answers
34 views

Rust Iterative and Recursive Merge Sort Implementation

I'm in the process of learning both Rust and algorithms after primarily focusing on web development. As such I've had a go at implementing merge sort both iteratively and recursively. I've looked for ...
-2
votes
0answers
33 views

Maximise value of goods in a triangular container [closed]

In this task I should find the best solution to the given problem. You are given M - capacity of the ship where you can store elements with heights smaller than i-th height for example on the 1st ...
4
votes
4answers
195 views

Finding the number of longest contiguous increasing subsequences in a given array

This is different from classic LIS problem. Here I want number of contiguous longest increasing subsequences! For example: ...
2
votes
1answer
41 views

Rust dynamic programming : word break

I've solved this problem: https://leetcode.com/problems/word-break Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into ...
2
votes
2answers
67 views

Designing a stack such that getMin() is both constant time and constant space

I'm attempting the SpecialStack problem on GeeksforGeeks. Design a data-structure SpecialStack (using the STL of stack) that supports all the stack operations like push(), pop(), isEmpty(), ...
4
votes
0answers
47 views

Opinion on a small app I created using JavaScript

Recently I created a small app using JavaScript, and I would love for some JavaScript developers if they have the time of day, to tell me their opinions so I can grow and improve. I'm mostly working ...
3
votes
1answer
34 views

Flash Memory block write counting & thresholding

I am trying to solve this question: In a block storage system, new data is written in blocks. We are going to represent the flash memory as one sequential array. We have a list of block writes ...
-1
votes
0answers
27 views

Floyd's algorithm to finding duplicates [closed]

It has been recommended to use Floyd's algorithm for finding duplicates in the array. (Previously I have used this algorithm to solve cycles in Linked list and it works fine.). In java, it is many ...
4
votes
1answer
53 views

Rust Spelling corrector

It's been about a day since I've started writing some Rust, and I'm looking for some code review on a simple spell checker I've written up ...
6
votes
1answer
85 views

Animation of sorting algorithms

I have created a visualisation of sorting algorithms using tkinter and matplotlib. Please let me know what you think and if you have any suggestions or find errors. The aim of this code is to create ...
3
votes
2answers
37 views

Reducing time complexity of weighted grid pathfinder

For school, I made a pathfinder for a weighted grid, but anything beyond a 7x7 grid takes a significant portion of time. I was wondering if I can improve my code at all, or if there is a way to reduce ...
2
votes
1answer
22 views

python segment tree - count of smaller numbers after self

I am trying to solve this question https://leetcode.com/problems/count-of-smaller-numbers-after-self/ You are given an integer array nums and you have to return a new counts array. The counts ...
0
votes
0answers
49 views

Python Sudoku Solver

I have created this code for a Sudoku solver in Python with a tkinter GUI and uploaded it to GitHub. Please can you have a look and let me know of any ideas or improvements you think I should make? <...
4
votes
2answers
207 views

Pandas - 3 iterations per second on simple conditional

The function removes rows from a pandas df if that row doesn't have the value of important_1 inside of important_2. For example ...
3
votes
0answers
34 views

Is this breadth-first search correct?

I wrote a program that is supposed to be a breadth-first search algorithm, but I'm very new to search algorithm so I don't know if my method is very effective or if there is a simpler way to do this. ...
2
votes
2answers
79 views

Find all pairs of numbers such that the number of binary 1's in their OR is maximum

So, I tried to solve this question and my code did not execute within time-limits. https://www.hackerrank.com/challenges/acm-icpc-team Here's my code, ...
1
vote
1answer
41 views

Python Fenwick Tree

I am trying to solve this question: https://open.kattis.com/problems/fenwick A Fenwick Tree (also known as a Binary Indexed Tree) is a data structure on an array which enables fast (𝑂(log𝑛)) ...
5
votes
2answers
107 views

More ergonomic / convenient STL algorithm calls — sort order & member field extraction using std::invoke

While we patiently wait for ranges in C++20, it can still get somewhat frustrating to write begin(), ...
2
votes
0answers
46 views

Kadanes algorithm implementation

I just wanted to ask the following question. I have solved Kadanes algorithm using the recursive approach as shown below. The implementation works ...
5
votes
3answers
137 views

Pythagorean Triple finder

Would like some feedback on a code style exercise motivated by this PythagTriple algorihtm. I started with the Rosetta Code - "efficient C" solution (not the naive one) and refactored it heavily into ...
3
votes
1answer
102 views

Find positive integer with a minimum number of binary 1's such that its bitwise AND with all array elements is not 0

Task You have an array of positive integers. Your task is to find an integer x such that the following are true: Bitwise AND between ...
0
votes
0answers
20 views

Factorial Meta Programming [migrated]

We lately had a lesson about meta programming at our university... So i started to implement my own factorial meta code... this is the result. ...
3
votes
2answers
130 views

Dynamic Array Implementation in C++

I've finished implementing a dynamic array in C++. I'm a beginner in C++ and also in algorithms and data structures, so any constructive feedback about improving the implementation would be greatly ...
2
votes
1answer
38 views

Codewars: Pick peaks

Pick peaks Wrote my "hello world" on Thursday, so definitely a beginner. I know some Python, so not a novice to programming in general. Question For example, the array ...
1
vote
1answer
25 views

My implementation of the Union-Find data structure in MATLAB

I was assigned the connected components labeling (CCL) algorithm and in order to implement the CCL algorithm I first had to implement the Union-Find algorithm. This is my try at it, any review and ...
1
vote
1answer
36 views

Scala graph coloring

i have solved this problem https://leetcode.com/problems/find-eventual-safe-states/submissions/ ...
6
votes
5answers
114 views

Implemented command-line based merge-sort algorithm. How can I make the code efficient, robust, maintainable, secure?

This is follow up question regarding merge-sort implementation to the previous post. Recently I have implemented a command-line argument based merge-sort sorting algorithm. Format for command-line-...
2
votes
1answer
83 views

Maximum sum combination

I am trying to solve this question: https://www.codechef.com/problems/TADELIVE Andy and Bob are the only two delivery men of Pizza-chef store. Today, the store received N orders. It's known that ...
1
vote
0answers
46 views

String parsing algorithm in Rust

I have written a recursive parsing algorithm for strings with nested brackets (I needed it to solve a molecules to atoms task). I would love to see how I could make ...
3
votes
1answer
61 views

Enhance function that justifies text

On Codewars, there is a challenge where the goal is to justify an str into a certain len. Here are the rules: Use spaces ...
0
votes
2answers
70 views

Implementation of the Selection Sort Algorithm

I have tried to implement the Selection Sort Algorithm in two different ways, and I was just wondering if that is considered to be a valid implementation of that algorithm. Would that be also ...
2
votes
0answers
56 views

Traverse materialized path hierarchy for children nodes

I have a sorted list of materialized hierarchy paths: ...
5
votes
2answers
409 views

Output the top N toys mentioned most frequently in the quotes

This question was asked during an interview as a software developer: Task: You work on a team whose job is to understand the most sought after toys for the holiday season. A teammate of ...
2
votes
3answers
161 views

Adding two n and m bit binary numbers

Recently I was studying bitwise operators and bit-manipulation algorithms and I found out an algorithm to add two binary numbers. Pseudocode is as follows: ...
5
votes
1answer
62 views

Total number of non overlapping subsets

I am trying to solve this question. The essence of the problem is this: Given a list of school classes with start and end times, find the total number of non-overlapping subsets. I've written up a ...
2
votes
1answer
56 views

Getting a compound words list in suggestions using jazz spell check

This little program was written for an assignment in a data structures and algorithms class. I'll just note the basic requirements: Given an inputted string along with mode (0=spell check, 1=...
2
votes
3answers
100 views

Check if there's exactly one match in a vector

The challenge is to iterate over the vector only once and return the value within the range of the zero. However, if there are no matches or more than 1 match, deliver an error. The vector is unsorted ...
2
votes
1answer
53 views

Priority queue with Max-Heap

I'm studying with book "Introduction to Algorithms" and implemented PriorityQueue without existed Class. I made a MaxHeap class with Array and made a PriorityQueue with my Heap class. Actually code ...
8
votes
4answers
129 views

Multi-merge algorithm in C++

As you know there is an algorithm in C++ standard library called std::merge, that merges two sorted ranges into another range. I try to write another merge (called <...
14
votes
5answers
2k views

Advent of Code 2019: Day 4

Advent of Code 2019: Day 4 I'm doing Advent of Code this year. Below is my attempt at day 4: Problem Part One --- Day 4: Secure Container --- You arrive at the Venus fuel depot only to ...
3
votes
2answers
56 views

Get resulting rectangle from two overlapping rectangles

I have a function that creates a rectangle from two rectangles that overlap, I was wondering if there is a smarter way to do it purely mathematically rather than lots of ...
10
votes
6answers
1k views

Intersection of sorted lists

I don't like this function. Looks too imperative. It takes two sorted lists and returns a sorted intersection of the two lists. There is an implicit assumption that there are no duplicate elements in ...
0
votes
1answer
38 views

Python 3 Simple Xor Pipe/CLI Program

I wrote a simple Python 3 program that takes data from either a file or standard input and xor encrypts or decrypts the data. By default, the output is encoded in base64, however there is a flag for ...
4
votes
2answers
1k views

Advent of Code 2019: Day 1

Advent of Code 2019: Day 1 I'm doing Advent of Code this year. Below is my attempt at day 1: Problem Part One --- Day 1: The Tyranny of the Rocket Equation --- Santa has become stranded ...
5
votes
2answers
386 views

Advent of Code 2019 Day 3

Advent of Code 2019: Day 3 I'm doing Advent of Code this year. Below is my attempt at day 3: Problem Part One --- Day 3: Crossed Wires --- The gravity assist was successful, and you're ...