121,474 questions
Advice
0
votes
2
replies
23
views
Can buffers or constant sized external arrays be used to create an fully in place iterative quicksort?
Quicksort and Mergesort are both (before any optimisation) recursive algorithms that take up O(nlogn) stack space (ignoring Merge Sort's O(n) space complexity taken for the merging step). Upon ...
Advice
0
votes
2
replies
67
views
In recursive DP, can a function parameter ever equal the return value?
When defining a DP solution, the state is represented by the function's parameters, and the function returns the answer to that subproblem.
For example in Fibonacci, the state is n and the return ...
Advice
1
vote
23
replies
196
views
coordinate proximity for likert scale analysis (php)
this is a project in php but i am happy with any suggestions, regardless of language. the coding is less the issue than a missing piece in logic i am struggling with.
users answer a series of 7-point ...
-2
votes
1
answer
179
views
How to reverse a singly linked list in-place in Java without using additional memory?
I am implementing a custom Singly Linked List in Java for a project, and I need to implement a method to reverse the list. The main constraint is that it must be done in-place (O(1) space complexity), ...
Advice
0
votes
6
replies
145
views
Do you need to implement an "update priority" method for a Priority Queue when using it in Dijkstra's algorithm?
In Dijkstra's algorithm, you need to select the nodes with the smallest distance (distance = priority in the Priority Queue which is implemented by a MIN heap)
You also need to update the distances of ...
Advice
0
votes
6
replies
180
views
I always overcomplicate easy problems and end up with a working but messy solution while the optimal one is dead simple
So I was solving Rearrange Array Elements by Sign (LC #2149)
What I wrote:
public int[] rearrangeArray(int[] nums) {
int nPointer = 0, pPointer = 0;
int[] result = new int[nums.length];
...
Best practices
0
votes
1
replies
78
views
Best algorithm for range-filling from pointers
What is the most common way to perform range filling algorithm in hardware (e. g. in Verilog)?
Problem: given 2 N-wire buses, need to provide resulting 2^N bus with those bits asserted, which are ...
-2
votes
1
answer
186
views
Longest special subsequence of strings [closed]
I'm trying to solve this problem https://open.kattis.com/problems/savez
Basically you get N strings where the i-th string is denoted by x[i]. you want to find the length of longest special subsequence ...
Advice
0
votes
7
replies
135
views
String hashing ignoring order
I am looking for a way to implement such hashing.
const str1 = "abc"
const str2 = "zyx"
const hash1 = hash(str1+str2)
const hash2 = hash(str2+str1)
// expecting hash1 to be equal ...
Advice
0
votes
6
replies
144
views
When adding an element to a heap why don't we Heapify it from the root?
To build a heap from an array, we take a list of elements and start calling heapify on all non-leaf nodes, from the bottom, up
When we add an element to a heap, we simple bubble it up
Won't bubbling ...
0
votes
2
answers
194
views
Is my maxHeapify logic correct? I have nested the right child check within the left child check
I've seen other books and articles do it differently, so I'm just wondering if I got it right or wrong. I have nested the right child check within the left child check. I've seen implementations ...
Advice
0
votes
3
replies
148
views
Why are certain sorting algorithms faster and better at certain things?
I know that there are many different types of sorting algorithms. But how do I know what algorithms do better jobs at certain questions and which ones take longer to run but are better at other things?...
Tooling
1
vote
7
replies
288
views
What sorting methods would I use for the following problem?
The Simpsons have constructed a cinema with R rows (4 ≤ R ≤ 500) of seats in the shape of a rectangle with an odd width W (7 ≤ W ≤ 501). The distance between two adjacent seats in the same row is ...
1
vote
1
answer
220
views
Malloc makes code crash in C while doing merge sort
I'm new to the C language (I'm doing CS50x) and I want to code a merge sort algorithm. I want to debug my code but I can't figure out why malloc in sort_disassemble is crashing.
P.S. The code isn't ...
Advice
1
vote
4
replies
143
views
Recursive Algorithm Needs Speed Up
def find_suffix_chain(word: str, start_pos: str, root: str,
current_chain: List = None, visited: Set = None,
shared_cache: dict = None) -> List:
&...