Tagged Questions
An algorithm is a sequence of well-defined steps that defines an abstract solution to a problem. Use this tag when your issue is related to algorithm design.
0
votes
3answers
28 views
attempting a code challenge in js, getting unexpected results --
The goal is to create a function called destroyer that filters all arguments after an initial array argument out of the array.
I'm not very good at functional programming yet so my answer doesn't ...
0
votes
2answers
26 views
Implementing Shunting Yard Algorithm in JavaScript
I've been learning JavaScript for just about a month, and I'm trying to implement the Shunting Yard Algorithm
However, I seem to have a logic error somewhere (probably in the while loop) but I can't ...
1
vote
1answer
105 views
Red - Black Spanning Tree
Good morning,
I came across the following question that deals with Graphs and was not able to come up with a correct solution. I would appreciate any possible help:
You are given a graph, some edges ...
0
votes
1answer
210 views
red black tree insertion
I inserted node 36 in the red black tree and the following red black tree resulted:
my problem is that how to handle double red in this special case? is it case 2 or 3?
15
votes
4answers
4k views
Concatenating red-black trees
The OCaml standard library has a wonderful Set implementation that uses a very efficient divide-and-conquer algorithm to compute the union of two sets. I believe it takes whole subtrees (not just ...
17
votes
8answers
3k views
How to find upper envelopes of intersected lines in O(nlogn)?
Disclaimer: Yes, this is a homework and I am thinking about it for a couple of days but couldn't find a way to go.
So there are n straight lines (y= ax + b) and I want to find upper envelopes of them ...
29
votes
3answers
14k views
Red black tree over avl tree
AVL and Red black trees are both self-balancing except Red and black color in the nodes. What's the main reason for choosing Red black trees instead of AVL trees? What are the applications of Red ...
1
vote
2answers
54 views
Can an ANN of 2 neurons solve XOR?
I know that an artificial neural network (ANN) of 3 neurons in 2 layers can solve XOR
Input1----Neuron1\
\ / \
/ \ +------->Neuron3
/ \ /
Input2----...
1
vote
1answer
795 views
What is the Practical Byzantine Fault Tolerance?
Can somebody please provide a gist of the Byzantine Fault Tolerant algorithm and Liskov's algorithm?
Thanks.
0
votes
0answers
26 views
How stackoverflow generate user id? [migrated]
How does stack overflow generate user ids? Judging by the number of digits in ids, it seems they have more than a million users. How do they handle id collisions?
-3
votes
1answer
49 views
bad memory alloc error - segment tree
I am trying to create a segmented tree,
Here is my struct for the node of tree:
struct Node{
int x1, x2; // x coordinates
int y1, y2; // y coordinates
Node * v1;
Node * v2;
Node ...
3
votes
2answers
133 views
Is it possible to evaluate lambda calculus terms efficiently?
I've been writing a lot of programs in the lambda calculus recently and I wish I could run some of them in realtime. Yet, as much as the trending functional paradigm is based on the lambda calculus ...
0
votes
1answer
72 views
Calculate the modulus of a big sum [closed]
I need to calculate
1^2 + 2^2 + ... + n^2 modulo 10234573
for n up to 2 billions. I need to use native C++ libraries. I can't figure out how to do it, because it seems like a huge number.
-2
votes
3answers
60 views
Check that if-statement was true several times in a row
I have a loop
count = 0;
do
{
...
if (statement)
count++;
...
} while (count != 3);
How to check that if statement was true three times at a stretch?
0
votes
0answers
15 views
How to solve the problom E in codeforces beta round#11?
I tried to get the ideal of the round#11 problem E. I got some information as following:
Assume the numbers of L and R in the original string is LRnum, and the length is len, When I add some X's to ...
-2
votes
0answers
20 views
UVa OJ 10252 - Common Permutation keeping Wrong Answer but seems right compared with accepted for lots of times
The problem's link is here
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1193
The method I use is first sort two strings in alphabetical ...
0
votes
1answer
21 views
How the recursion in Quicksort algorithm works?
I've seen some code in Google implementing Quicksort algorithm like this.
static public void QuickSort_Recursive(int [] arr, int left, int right)
{
// For Recusrion
if(left < right)
{
...
5
votes
2answers
668 views
Find the smallest and second smallest number in an array of 8 numbers with only 9 comparisons
This is an interview question I had to answer. Well a friends actually but he asked me and I didnt know the answer also. Hence I'm asking here:
Given an array of 8 integers, find the smallest and the ...
-2
votes
2answers
42 views
How to generate 4 digit unique id like discord id like #8052
DECLARE @chars NCHAR(36)
SET @chars = N'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
DECLARE @result NCHAR(4)
SET @result = SUBSTRING(@chars, CAST((RAND() * LEN(@chars)) AS INT) + 1, 1)
+ ...
55
votes
17answers
59k views
Explain this snippet which finds the maximum of two integers without using if-else or any other comparison operator?
Find the maximum of two numbers. You should not use if-else or any other comparison operator. I found this question on online bulletin board, so i thought i should ask in StackOverflow
EXAMPLE
Input: ...
0
votes
3answers
15 views
Using character codes to get frequency on words in a string, JavaScript
I'm trying to rewrite this frequency finding program in Javascript. Here is the Java code:
public class frequency {
public static void main(String[] args){
String S = "Temple University"; ...
0
votes
0answers
17 views
Suitable machine learning algorithm
I have to build a model to predict credit card defaults based on their transaction behavior for past few months.
I am new to machine learning algorithms.
I tried googling and tried multiple ...
-1
votes
0answers
23 views
PASCAL Arrays (choose Common values from within an array and insert it into a variable)
Note: This is not a Homework I don't Want an Answer for the Question given here it is given so that you all can get a clearer understanding on what i ask since it's Hard for me to explain it in ...
1
vote
1answer
1k views
Java implementation of 2 dimensional interval tree [on hold]
I need a 2 dimensional interval tree for storing rectangular regions in a canvas.
I need to identify the regions which contain the point clicked or the regions overlapping with a rectangular selection....
2
votes
2answers
147 views
Non-Linear Recurrence Relation
How can I find Nth term for this recurrence relation
F(n) = F(n-1) + F(n-2) + F(n-1)*F(n-2)
I have to find Nth term for this recurrence relation modulo 10^9+7.
I know how to find Nth term for ...
-2
votes
2answers
21 views
Organizing/rearranging highest to lowest scores in python text file for a game
Relevant Background Information
I'm developing a game in Python & Pygame for my high school Computer Science final. I have it pretty much all done. It's a zombie shooter game where a player ...
0
votes
1answer
25 views
doubts about a limit on size of each word of data in RAM model
In a book named Introduction To Algorithm, at p22, the definition about RAM model, it says that
We also assume a limit on the size of each world of data. For example, when working with inputs of ...
0
votes
3answers
37 views
How to use Euclid's algorithm to find GCF/GCD?
I have created a method that allows me to find the GCF/GCD of two numbers, and although I have a working code, I don't know how or why it works. I understand Euclid's algorithm, but am not sure how ...
-2
votes
0answers
43 views
An advice regards the book 'Thinking in Java' [on hold]
I'm trying to read 'Thinking in Java' by Bruce Eckel, but I've found the book little bit arduous to understand.
The examples code discourages the easy comprehension of the topic, and I need linger to ...
2
votes
3answers
67 views
Segmentation using maximum likelihood algorithm on images using python
I would like to perform image segmentation using maximum likelihood algorithm implemented in python.
The mean vectors of the classes, and covariance matrices are known, and iterating over the images (...
0
votes
0answers
67 views
Rotating array in C++ using single array
I've been recently solving various programming tasks. One that I found was rather easy - array circular rotation. I've chosen C++ as a language and I'd like to keep it.
The idea is to rotate each ...
13
votes
7answers
17k views
Finding the first n largest elements in an array
I have got an array containing unique elements. I need to find out the first n largest elements in the array in the least complexity possible. The solution that I could think of so far has a ...
2
votes
4answers
79 views
Find sequential smallest sums of the multiples of three different numbers, javascript
On this post I found an algorithm to determine the luminance of an RGB color:
Luminance (standard for certain colour spaces): (0.2126*R + 0.7152*G + 0.0722*B)
I want to use this equation, starting ...
-4
votes
0answers
18 views
Projects on algorithms for undergrad [on hold]
What would be a good topic to take up as a project, purely based on Algorithms and Data structures, for a undergraduate student with intermediate knowledge on these subjects.
It should be more of a ...
-1
votes
3answers
49 views
I'm stuck with this FreeCodeCamp algorithm
function destroyer(arr) {
// Remove all the values
var toFilter;
var toFrom;
for(var i=0;i<arguments.length;i++) {
if (typeof arguments[i]=="object") {
toFilter =...
0
votes
1answer
23 views
What is an example of an algorithm which uses Huffman coding only?
For example, a LZM algorithm example could be the LZMA, but the Huffman example I can't find. I understand that BWT uses it to some extent, but it uses another type of algorithm too.
13
votes
5answers
3k views
Cut rectangle in minimum number of squares
I'm trying to solve the following problem:
A rectangular paper sheet of M*N is to be cut down into squares such that:
The paper is cut along a line that is parallel to one of the sides of ...
0
votes
1answer
345 views
Multiplication with big numbers
I have seen many answers here and on the internet but i don't need a big int library, I need a program that multiplies big numbers in c++/c but really fast, I have tried different prorgams and some of ...
1
vote
1answer
52 views
Method is slower after memoization
I'm working on the following algorithm problem on Leetcode:
Given a binary tree, determine if it is height-balanced. For this
problem, a height-balanced binary tree is defined as a binary tree ...
0
votes
1answer
25 views
Modification to Travelling Salesman
I am currently learning about optimization algorithms for the travelling salesman problem, and I was wondering if the problem could be modified without changing the actual problem itself. If that ...
-1
votes
0answers
22 views
Given a list of names (strings) and the width of a line, design an algorithm to display them using the minimum number of lines
I am assuming you have a list of words which can be re-arranged in any fashion you want. There is a fix width 'w' and a list of names say, List names. You need to print those names and fill up the ...
4
votes
2answers
62 views
Why Quick sort code is breaking stability?
Below is the partition() logic used by qSort(),
static void qSort(List *list, int low, int high, compareTo compare){
if(high <= low){
return; // no partition for sub array of size 1
}
...
18
votes
2answers
12k views
KMP prefix table
I am reading about KMP for string matching.
It needs a preprocessing of the pattern by building a prefix table.
For example for the string ababaca the prefix table is: P = [0, 0, 1, 2, 3, 0, 1]
But I ...
0
votes
1answer
105 views
Modify lazy propogation in segment tree
I recently read about lazy propogation in segment tree and coded it too.But i got stuck when suppose instead of adding value(=val) i need to divide by value.How to do it ?
Please help
My update ...
2
votes
1answer
27 views
OpenDataStructures: ArrayQueue
I am studying algorithms on my own and turned to the Open Data Structures (C++ Edition) free ebook as a reference. In my attempt to master the topics, I am determined to finish all the challenges in ...
1
vote
2answers
44 views
worst case running time of segment tree
How is the range sum in segment tree O(logn) worst case?? Shouldn't it be O(n)? What if during the range sum operation,we traverse down both the left and right nodes as per the algorithm?
0
votes
3answers
2k views
Reversing a linked list recursively
The problem is that i need to write a recursive algorithm for reversing a singly linked list L, so that the ordering of the nodes becomes opposite.
it seems a bit abstract, but i don't need code or ...
2
votes
2answers
130 views
Total pairwise costs in a weighted undirected graph
Consider that we have a weighted undirected graph where, for any two vertices, there is a unique path that connects them. There are n vertices and n - 1 edges and the cost of each road is c_i.
Now, ...
1
vote
0answers
25 views
How can I insert elements in an empty (3,5) tree?
I know that people really don't like seeing homework questions here, but I just don't know what to do now.
For our algorithms lecture, I was asked to create a (3, 5) - tree. At the start it is empty ...
1
vote
1answer
46 views
N-Queens algorithm. Plot Twist: The Queen is a Knight too
Trying to modify the N-Queens algorithm for a Knights' movement set, on a N*N board. In my case I was testing it on a 4*4 and 8*8 board.
My algorithm, resp. my recursion fails dealing with the Knight ...