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

(Feedback) Finding bridges in an Undirected Graph implementation in C#

I am implementing fundamental data structures in C# while trying to learn techniques in the language to make my code cleaner, more concise while using good programming practices. I have implemented ...
1
vote
1answer
13 views

Brute-force electronic component selection space search

Yesterday I hacked up a simple component selection program. An example is shown at the bottom for the application, though this can be used generally for a lot of different simple circuits I come ...
2
votes
2answers
78 views

Sorting an array using a Binary Search Tree with C++

Given an array of integer (all different from each other), this program creates a BST with the array elements in order to sort them and put them back into the array, using the BST properties. ...
7
votes
3answers
195 views

Refactor the code which performs “cross-product”, “reduce”, “product of list” and “sum of list”

I have come up with a sequence of steps to find the maximum product of y positive numbers which add up to x. But the program is ...
4
votes
1answer
21 views

Is this an optimal implementation for the knapsack algorithm?

I have implemented a solution for the knapsack problem while breaking an item is allowed. I've used the dictionary data structure where I used weight as a key and value per weight as a value. After ...
3
votes
1answer
30 views

I need to know that if everything okay in my BTS put and get method

I implement BinaryTree (K extends Comparable, V) concept to binarySearchTree and I have written get and put method. As far as I check, there is no problem in my code. So now I wonder that are there ...
2
votes
0answers
32 views

How to define UDP connection sessions more correctly?

Listening to messages from the udp socket, I would like to somehow determine where packets come from and scatter in sessions to get a more detailed report on the received data, I just did it forehead, ...
5
votes
2answers
141 views

Create a matrix with all elements having the value of the shortest path to a given position

You're given the number of rows and columns and the indices for the reference point. Reference point is = 0. i.e: 3 4 3 3 output: 4 3 2 3 3 2 1 2 2 1 0 1 I managed to solve the problem using the ...
3
votes
2answers
93 views

Implementation of a Smart To-do List Algorithm

This is a small program to implement the FVP algorithm (outlined here). I'm still quite new to C++ and don't have a strong grasp of basically any concepts. Concepts I tried to use in this program: ...
1
vote
2answers
63 views

Find an Element in a Linked List

The find function is designed to start at the given node and return the index of the node with the value valueInput (indices start at 0). Return -1 if valueInput does not exist. How can this code be ...
1
vote
2answers
63 views

integer log base 10 function without using java.lang.Math?

I am assigned to a task of creating a function int logBase10Estimate(int n) that returns the log of a number base 10. The answer is integer part only.(w/o using the Math class) Is this okay? ...
0
votes
1answer
21 views

naive suffix tree construction in Python

I'm not certain if my implementation is correct, it appears to be, but looking for any feedback as far as readability and efficiency goes. Obviously using dictionaries isn't particularly efficient ...
1
vote
0answers
19 views

Python put from txt file into array(multiple line) [closed]

Im kind new to programming and I'm working with STL files (in ASCII format). Basically I need to create an array of several lines, and in each line of that array I need to insert 12 positions of a ...
0
votes
0answers
32 views

ROT(ation) by Index

I have written a few C++ functions that should: take in a string transform it based on index transform it based on number of alphabetic characters seen return the transformed string I am ...
3
votes
1answer
56 views

System generated Social Network

In a particular social network friends are automatically allocated to users by the system and users cannot add friends of their choice on their own. There are currently N users on the social network, ...
5
votes
2answers
213 views

A job sequencing solution

I have written this code as a college assignment fot the famous job sequencing problem. Please tell me any improvements if possible. Oh, for algorithms.h header ...
4
votes
1answer
220 views

A simple Decryption Program using Python

This is a program that can decrypt the codes that have been encrypted using the algorithm that my previously posed encryption program follows, you just need to enter the encrypted text from that ...
2
votes
0answers
21 views

Traversing a tree with two types of nodes, while keeping track of all ancestors

I wrote code that stores an AWS Organization tree in a tree data structure in Rust. From the tree, I use a slightly modified preorder traversal algorithm to print all of the accounts in the ...
1
vote
0answers
52 views

Checking if a user exists on the database and return user in JSON format

below code takes data (email,password,user type) from $_POST[] and use them to search whether a user exists on the database. If yes sends a JSON object to the ...
12
votes
3answers
1k views

A simple encryption program using Python

I made this encryption program in Python. I don't have much experience (or any experience at all) about encryption (since I just gave my 9th grade finals), but I had this idea about an algorithm some ...
3
votes
1answer
58 views

Splitting a list so the two resulting lists have the same average

Problem Description: The purpose of this function is to take a list of sorted numbers and split it into two evenly balanced lists. By evenly balanced I mean the numbers in the two lists have as ...
2
votes
1answer
53 views

Bathroom stalls in Python 3 (Google Code Jam 2017)

This problem is tested against 3 sets of input data to see if the submitted solution gives an incorrect answer, if the solution exceeds the time limit, or if the solution exceeds the memory limit: ...
1
vote
1answer
73 views

Shortest path in Binary Maze

I want a feedback on my code for the below known problem from Daily coding challenge: You are given an M by N matrix consisting of booleans that represents a board. Each True boolean represents a ...
-1
votes
1answer
34 views

first missing positive integer in an array using javascript? [closed]

I am trying to find missing positive integer in an. array.I don't know where my function not working ? question given Given an unsorted integer array, find the ...
6
votes
1answer
73 views

Quine–McCluskey algorithm for minimizing Boolean functions

This is part of my homework on digital logic design, so I would like to present some technical background first. Quine–McCluskey algorithm is a method for minimizing Boolean functions. Given the ...
0
votes
0answers
40 views

Best way to optimize multiple search on Lists java

Anyone could help me to optimize this block of code, I already did a bit improvement but since I'm really bad with this kind of algorithms this all I've done so far. Much appreciate if you can explain ...
3
votes
1answer
41 views

Python implementation of Kahn's Algorithm

Please provide any suggestions on the below code for Kahn's algorithm. Can it be implemented in a better manner, or be improved: ...
5
votes
1answer
42 views

Calculate quote volumes (for a financial instrument) within numeric constraints

The function below is part of a trading system. Its purpose is to assign a volume (order size) to a bid (buy) quote and and ask (sell) quote, depending on the value of the ...
5
votes
1answer
69 views

Tarjan's Algorithm Python Implementation

I'm planning to use Tarjan's algorithm for a program in which I would be processing a file, converting the processed data to a dictionary, doing a topological sort on that dictionary (using this ...
3
votes
1answer
47 views

C backtracking Sudoku solver

I wrote this program in C to solve a given Sudoku puzzle (represented as 2D array) using backtracking algorithm. How can I make it more efficient, maybe faster and more C-onic? This is my first post ...
3
votes
2answers
78 views

Basic 'char' Stack implementation in C

...
3
votes
1answer
47 views

Python sudoku solver with classes

I just coded an object-oriented Sudoku solver, but I don't have any possibility to check whether I have written good code, so I thought I would just post it here for review. I have looked for other ...
2
votes
1answer
67 views

An implementation of Levenshtein Distance algorithm in modern C++

Below is an implementation of Levenshtein Distance algorithm. I am trying to use modern C++ features as much as I can, i.e. auto, no pointer / raw memory but I feel like it is a constant struggle. ...
1
vote
2answers
46 views

Count the number of discrete values in a slice

I'm using this right now to count the number of discrete values in a given []string. Is there a faster way to do this? ...
1
vote
0answers
35 views

Using pandas .apply to while loop through every row of the dataframe to get to intended substring given starting and ending index of a string

I have a function called postprocess that applies while loop condition to find for - and ...
3
votes
2answers
81 views

Heap Sort in Python

NOTE: I am beginner in Python I learnt the Heap sort today and tried my own implementation using Python. Can i get feedback for my code and areas of improvement. I have tried to add comments inline, ...
2
votes
2answers
54 views

An array of values. looping many times to calculate mean, closest matching array value, and then finding its index

I have an array of values. (cols) I want to find out which index of cols contains the value closest to the mean of ...
6
votes
2answers
63 views

Finding consecutive primes matching p, p + 4, p + 6, p + 10, p + 12, p + 16

Someone asked about this question on the main StackOverflow. The full question is: Given a value N, find p such that all of ...
3
votes
2answers
107 views

Dijkstra Algorithm implementation in C++

I have implemented Dijkstra's algorithm in C++, but it seems a bit complicated since I really tried to follow the process of the algorithm as much as I could. If there's any simplification you would ...
2
votes
2answers
133 views

Code for getting the coordinates of points on the chart

I am a beginner android developer. I am working on one of my applications. For this application, I wrote an algorithm that is needed to obtain data that is used to build a diagram. I have a list of ...
2
votes
0answers
25 views

Rotational Symmetry Indexing in a 1D “Square” Array

I managed to find a way to rotate a slice in-place (previous question on SO). The slice is linear, but represents a 2d square of elements. Is this approach efficient? Please check the previous ...
0
votes
0answers
17 views

Subset sum using the Horowitz-Sahni algorithm and pruning strategies

The subset sum problem asks if some subset of a set can be summed to a given number (equivalently, if they sum to 0). I recently had to implement it, under an additional restriction of all numbers ...
2
votes
1answer
58 views

Looking for specific words in a string and noting the order

The problem: I have some text that I go through line-by-line, if I find a line containing the keyword DATA_TYPE_1 and/or ...
4
votes
1answer
43 views

A fast generator of palindrome dates in chronological order

02/02/2020 is a palindrome day because reading the date left-to-right or right-to-left still refers to the same calendar date. And because it doesn't matter whether you use the DD/MM/YYYY format or ...
2
votes
1answer
48 views

Iterating lists and updating dictionary for corresponding match logic improvement

I have two lists: Users - [<UserObject1>, <UserObject2>, ...] Contributions - [...
1
vote
1answer
40 views

A* Search in JavaScript

I just implemented a version of A* search in JavaScript for educational purposes. I'd really love it if you could take a look and tell me how to improve my code. The ...
1
vote
2answers
127 views

Calculate transaction balances and find duplicate transactions

In an interview I was asked to solve two JavaScript questions. I thought I did pretty well because I: Covered the edge cases Wrote comprehensive tests Documented the code using jsdoc The interviewer ...
4
votes
3answers
101 views

C++ Merge Sort Algorithm

I have created this first-timer implementation of Merge Sort and I got confused by the C++ syntax once or twice. So I have some questions about this code: ...
0
votes
1answer
37 views

Algorithm for shifting data

I was bored and sketched out this idea in pseudocode( I will try to turn it into C++ later) for taking a set of numeric data and manipulating it. I ran through it manually and it seems to put the data ...
1
vote
0answers
25 views

Wildcard Matching with DFS and FSM

I'm trying to solve Wildcard Matching on Leetcode. I found a great solution using the Finite-state machine. The author builds an FSM and searches with BFS. I rewrite the solution with the same idea (...

1
2 3 4 5
85