Skip to main content
Filter by
Sorted by
Tagged with
-4 votes
0 answers
49 views

Where does the reference to a variabl e.g. x = 3 get stored in Python? Sources on the web say that the references are stored on the stack. ex: Stack Memory: Stack memory stores temporary data, ...
Dominic's user avatar
  • 127
0 votes
1 answer
148 views

i was looking at this heap implementation, and i was wondering if it is necessary to implement heap for printf even if i'm calling setvbuf(stdout, NULL, _IONBF, 0) before calling printf. i looked at ...
W4ZM's user avatar
  • 75
1 vote
2 answers
83 views

According this awesome article there is an interesting case with two given examples: A: B: And there is an explanation for A: Unfortunately you have not taken into account that such Strings will ...
Bartłomiej Semańczyk's user avatar
0 votes
1 answer
49 views

In a microcontroller without any OS, how does the microcontroller keep track of where a malloc will point to in the heap? char *x; char *y; char *z; x=(char*)malloc(10); y=(char*)malloc(10); free(x); ...
hal's user avatar
  • 1
2 votes
4 answers
190 views

I'm working on a problem where I need to maintain the median of a data stream, but unlike typical implementations that only support insertions, I also need to support deletions of arbitrary values. ...
Aditya Rawat's user avatar
1 vote
1 answer
213 views

I am trying to write an efficient multistep solver in C++ using the Eigen library. To do so, I need a few variables that keep track of the history. One of them is of type Eigen::VectorX<Eigen::...
Fredo's user avatar
  • 47
4 votes
1 answer
106 views

I'm trying to port a program I wrote in windows with syscalls to linux. The program reads the memory of another running process and displays certain values as they change. To get started and figure ...
seenmycorpseanywhere's user avatar
1 vote
1 answer
102 views

I am currently running a C++ program in which I have used the heap to simulate the stack and employed assembly language to place relevant information (such as memory addresses) into registers, thereby ...
qingfu liu's user avatar
0 votes
1 answer
81 views

I do have this code. @RequestMapping("/test") fun getData(): ResponseEntity<ByteArray> { val items = repository.getItems() val outputStream = ByteArrayOutputStream() ...
dzikulisz cezar's user avatar
1 vote
3 answers
138 views

In heapsort, the heap is max-heap where each time we extract the maximum element from index 0 and place it at the right side of the array. I'm now wondering why we don't build the max-heap in reverse, ...
Fff's user avatar
  • 80
2 votes
1 answer
188 views

The undocumented (I can't find a MSDN reference) FrontEndHeapDebugOptions Registry key has two flags: Bit 2 (0x04) for disabling the Segment Heap, thus forcing NT Heap Bit 3 (0x08) for enabling the ...
Thomas Weller's user avatar
1 vote
1 answer
129 views

I know that a min pairing heap can decrease a key faster than O(logn). However, is there any way to make the increase key operate also faster than decrease key to the top, remove, than insert new ...
user27238111's user avatar
0 votes
1 answer
60 views

import heapq minHeap = [4, 7, 2, 8, 1, 3] heapq.heapify(minHeap) # O(n log n) operation print(minHeap) # [1, 4, 2, 8, 7, 3] heapq.heappush(minHeap, 1) # O(log n) operation? print(minHeap) # ...
etang's user avatar
  • 578
1 vote
0 answers
49 views

I am using priority queue to do the hierarchical clustering(can not import heapq), and want to use the complete-link method, but I don't know what is the problem of my code, the reason is far from ...
吳思覦's user avatar
5 votes
0 answers
111 views

The C++ standard explains how std::pop_heap is supposed to work: Effects: Swaps the value in the location first with the value in the location last - 1 and makes [first, last - 1) into a heap with ...
Tom's user avatar
  • 51
0 votes
1 answer
125 views

I am trying to understand merging two sorted lists into one sorted output. Got the below code from internet. trav's value will have to be the address of mergedHead but here, trav is holding the value ...
Preethi's user avatar
  • 55
1 vote
1 answer
47 views

So I am making a data compression tool using Huffman Encoding and decoding, I am at the stage where I have built the Huffman Tree and it is a success but I am feeding that tree in a GenerateCodes ...
Gaurav Tak's user avatar
1 vote
0 answers
167 views

I'm currently working on an assignment that requires me to analyze the memory layout of a given C program. The task is to identify which parts of the program are stored in different memory sections: ...
asfasfasf's user avatar
4 votes
4 answers
199 views

I need to find minimum subarray of size L, A[0:L], B[0:L] such that there are M different elements in A that are bigger than M different elements in B. Like A[i] > B[j] counts but I cannot use A[i] ...
Mert's user avatar
  • 53
-1 votes
1 answer
251 views

I have a problem to solve. Details of it basically irrelevant & I have two valid solutions for it: in python and Haskell. Python code: import heapq _, volume, *ppl = map(int, open("input.txt&...
mesenev's user avatar
-4 votes
1 answer
493 views

I know this is a min heap var minHeap = new PriorityQueue<int, int>(); But why does this comparer result in a max heap? var maxHeap = new PriorityQueue<int, int>(Comparer<int>....
coder19's user avatar
  • 51
1 vote
1 answer
130 views

I’m working on implementing a heapsort algorithm using a min-heap, specifically a ternary heap, where each node can have up to three children. I know that my solution is inefficient, and I'm looking ...
Djd Bdbd's user avatar
1 vote
0 answers
108 views

Why would we ever use a heap over a red-black tree? Take a scenario where we want a min-heap. The time complexities of a mean-heap are as follows. Peek: O(1) average/worst Delete First: O(log(n)) ...
Mike's user avatar
  • 21
2 votes
1 answer
143 views

I am trying to solve the leetcode problem: kth-largest-element-in-an-array I know a way to solve this is by using a heap. However, I wanted to implement my own heapify method for practice, and here is ...
Hemanth Annavarapu's user avatar
1 vote
1 answer
118 views

I have a question similar to question-1 and question-2. Q-1 describes an approach for modifying a single element of array and re-sorting. Q-2 talks about deleting an element from a heap and re-...
jjjjjj's user avatar
  • 1,192
0 votes
1 answer
66 views

I am new to using boost::fibonacci_heap and had some questions regarding usage. I have read the user manual, the answer is not clear: "https://www.boost.org/doc/libs/1_51_0/doc/html/boost/heap/...
user2128105's user avatar
2 votes
1 answer
114 views

I'm working on formally proving that it's impossible to convert a Min Heap into a BST in O(n) time complexity. My reasoning is that any algorithm attempting this conversion would need to perform ...
Re'em's user avatar
  • 23
0 votes
1 answer
91 views

I have a max binary heap implemented based on a complete binary tree. I need to insert multiple elements into the heap, where the current heap array has a length of n and the new elements array has a ...
alan's user avatar
  • 21
1 vote
1 answer
115 views

According to this page, there a two definitions of a heap (used by std::make_heap, std::is_heap, etc..) : Until C++20 : A random access range [first, last) is a heap with respect to a comparator comp ...
kingsjester's user avatar
0 votes
1 answer
268 views

I came across 3 approaches for the problem. Sort the array and find the k elements O(nlog(n)) Using minHeap, heapify in O(n) time and extract k elements O(klog(n)); total = O(n + klog(n)) Using ...
Rishav Raj's user avatar
0 votes
1 answer
170 views

I want to use heapq.heapify(Arr) but everytime i want a slice of array to be used without creating new memory allocation for the new array. I want the rest of the array to be as is. example: heapq....
swifty's user avatar
  • 303
0 votes
0 answers
15 views

In binary heap, these time complexities are given for the delete-min operation: best: Θ(1) average: Θ(log𝑛) amortised: Θ(log𝑛) worst: Θ(log𝑛) I don't understand the best case: Θ(1) Do we have to ...
KU risu's user avatar
0 votes
1 answer
80 views

task: Max Product Finder Create a maxProductFinderK() function that takes in a list of numbers and an integer k, and returns the largest product that can be attained from any k integers in the list. ...
asim elnour's user avatar
0 votes
3 answers
160 views

We were given the code: internal class Program { static void Main(string[] args) { int[] arr = { 10, 40, 30, 20, 10, 5, 8 }; int n = arr.Length; int i; ...
Ira 's user avatar
  • 1
0 votes
0 answers
65 views

i am building a max heap with class item which has (name ,price ,category) one time by comparing the name and one time by comparing the price but there is a problem with the name comparing here is the ...
ahmed mohsen's user avatar
1 vote
2 answers
535 views

I am currently learning about heap sort and I am having trouble understanding the heapify process, particularly when both children of the root are larger than the root itself, and the sub-children (...
Zain ul Abedin's user avatar
0 votes
1 answer
63 views

Ok so min heap place small value 1st in heap but in my case 5.xxx is being placed before 3.xxx and i dont know how to solve this issue when im using sort its giving correct answer but i want to do it ...
Divya Singh's user avatar
0 votes
1 answer
60 views

I have written the following program to implement heap sort (both ascending and descending) in Java. It has the following steps actually. Create an array with a pre-specified size and initialise it ...
Abitatha Roy's user avatar
1 vote
1 answer
88 views

To build a max Heap from Array. In implementation part. How to dynamically manage size of Array?. I am supposed to increase arr size when I use Insert method. Tried but it does not return desired heap ...
Yashawant Sawant's user avatar
1 vote
1 answer
214 views

I'm given an n sized array that houses a max-heap in it's first x elements (x is unknown). After those x elements, each element has value of infinity. My task is to find x in log(x) time complexity. ...
razml's user avatar
  • 13
0 votes
1 answer
72 views

Problem You are given a 0-indexed integer array costs where costs[i] is the cost of hiring the ith worker. You are also given two integers k and candidates. We want to hire exactly k workers according ...
Karina's user avatar
  • 101
2 votes
1 answer
328 views

I'm trying to create a more efficient way to sort lists and dictionaries in python and came across Efficient data structure keeping objects sorted on multiple keys. There the suggested solution was to ...
Lion In A Box's user avatar
0 votes
0 answers
46 views

Python's heapq seems to only support min heaps. If the heap were just made of numbers or an object thats compared using numbers, you could simply multiple each number by -1 to create a max heap but ...
Spectacles4's user avatar
1 vote
0 answers
54 views

I am working on the following problem. Assume you have a sorted array of numbers: a[1] > a[2] > ... > a[n] and a threshold T. You want to determine all pairs (i,j) such that a[i] + a[j] > ...
G2PL2N's user avatar
  • 11
0 votes
1 answer
121 views

We start on node 0 and need to get to node n-1 while using as less steps as possible. At the same time each step affects our temperature, some steps add 1 degree and some subtract 1. The input is in ...
user avatar
3 votes
2 answers
1k views

Consider a max-heap containing n elements. I'm interested in determining the levels within the heap where the k-th largest element could be located, where 2 <= k <= floor(n/2). It's assumed that ...
user avatar
1 vote
1 answer
85 views

I'm running in to an issue where none of the PHP heap classes store the data in the correct order. Examples given are trivial, but the error with this small dataset makes a project I'm working on fail ...
Dan Ringhiser's user avatar
2 votes
0 answers
109 views

I am working on a project that requires a priority queue with the following characteristics: Constant-Time Extraction: I need to efficiently extract the minimum element from the priority queue in ...
Lovepreet singh's user avatar
2 votes
1 answer
256 views

In 《Algorithms 4th edition》 2.4. It mentioned that In heap construction, to proceed from right to left, using sink() to make subheaps is more efficient. But why? I think it is the same to proceed from ...
Lucio Sun's user avatar
0 votes
1 answer
264 views

Im having trouble solving the Sliding Window Median problem using two heaps method as i keep encountering Time Limit Exceeded Error on the test case where K = 50000 and the input an array of 100000 ...
KevinL's user avatar
  • 11

1
2 3 4 5
38