fast sorting in C ++

I am implementing the quick sort algorithm from Cormen's Algorithm book(CLRS), but it always prompt "offset out of range", and I don't know how to fix it. Here's my code. template<typename Iterator> void quick_sort(Iterator first, Iterator

Add element values ​​in two IEnumerable collections

I have two IEnumerable collections of generic objects. Each object has a name and value property. The name is a string and the value is a double. I would like to merge the two into one and add the value properties. For example, say an object that is

Need help counting inversions with merge sorting

The following code counts inversions in an array nums (pairs i,j such that j>i && nums[i] > nums[j]) by merge sort. Is it possible to use the same approach to count the number of special inversions like j>i && nums[i] > 2*nums[

Counting words in a table in a string

I have an array of string say A=["hello", "you"] I have a string, say s="hello, hello you are so wonderful" I need to count the number of occurrence of strings from A in s. In this case, the number of occurrences is 3 (2 &quo

O (nk (log (k))) is it the same algorithm that O (n (log (k)))

I was asked to give an algorithm that was supposed to be O(n(log(k))) k is the number of arrays and n is the total number of elements in all of these. I had to sort the arrays. Minus the details I came up with an algorithm that does the job for in kl

The time complexity of this specific algorithm

Forgive me if what I'm about to ask is obvious, but I've been thinking about it for 2 hours now! I just can't figure it out.... Well, I had something similar to this : for(int i=0;i<N;i++) for(int j=0;j<i;j++) I can certainly say that the complexity

Connect a set of vertices in an optimally weighted graph

This is essentially the problem of connecting n destinations with the minimal amount of road possible. The input is a set of vertices (a,b, ... , n) The weight of an edge between two vertices is easily calculated (example the cartesian distance betwe

Detection cycle with BFS

I am trying to detect cycles with BFS algoritm in a directed graph. My main idea to detect the cycles is: since BFS visites each node (and edge) only once, if I encounter an already visited node again; it causes a cycle. However, my code sometimes fi

Count the number of comparisons made for BinarySearch

I have the task of creating two seperate programs, one linear search program, which I have already completed, and a binary search program. These programs must also count the number of comparisons made during the search process. My linear search progr

Dependency table command with perl

Have an array of hashes, my @arr = get_from_somewhere(); the @arr contents (for example) is: @arr = ( { id => "id2", requires => 'someid', text => "another text2" }, { id => "xid4", requires => 'id2', text =>

Make 3 levels of difficulty in a quiz app

I am developing a simple quiz app on Android. The questions in the quiz should become more difficult as advancing in the quiz. Now, I am trying to implement a static method that takes a list of Question objects and produces (pick) a sub-list of the a

Intersection between 3D flat polygons

How to find intersections between two (or more) 3D planar polygons (for the simplest case they are all convex)? Seeking algorithms able to provide the intersection line if there is any. Note the methods proposed for infinite Plane-Plane cases are not

GetHashCode Replacement

This question already has an answer here: What is the best algorithm for an overridden System.Object.GetHashCode? 16 answers As you know, GetHashCode returns a semi-unique value that can be used to identify an object instance in a collection. As a go

Linked list of intervals

I have the following two questions. I'm aware of the concept of a linked list. What is a linked list of intervals? I need to store a very huge (more than 100 bits) number in C/C++ and perform bitwise operations on it. Without using any big number lib

faster than in_array?

I need to compare a value to a set of array. However, I need to compare multiple values in foreach. If using in_array, it can be slow, real slow. Is there any faster alternative? My current code is foreach($a as $b){ in_array($b, $array); } Thank you

Reverse the permutation of a table in Java effectively

Okay, here is my problem: Im implementing an algorithm in Java and part of it will be following: The Question is to how to do what I will explain now in an efficient way. given: array a of length n integer array perm, which is a permutation of [1..n]

Calculate points to create a curve or spline to draw an ellipse

I am working with Dundas maps and need to overlay the map with bubbles depicting some data. I want to add shapes to the map in order to achieve this. I can add a triangle (or any straight-line-polygon) like this: public static void AddShape(this MapC

C # - Find which prefix applies

just looking for a bit of help in terms of the best way to proceed with the following problem: I have a list of a bunch of dialled numbers, don't think you need me to show you but for e.g. 006789 1234 006656 1234 006676 1234 006999 1234 007000 1234 0