Subarrays in O(N) complexity [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am stuck on finding a solution for finding all the contiguous subarrays of a given array in minimum time complexity O(n). For example: [1,2,3,4] Subarrays are: [1][2][3][4][1,2][2,3][3,4][1,2,3][2,3,4][1,2,3,4] I have done it with time complexity O(n^3) but question wants in O(N).

There are subarray as you described. Therefore, There is a lower bound of to your problem.

Related

O(n/2) search in linked list [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 months ago.
Improve this question
I'm supposed to make a search method for a linked list that has time complexity O(n/2). What would this look like? I heard that saying O(n/2) is the same as O(n). So is it just a search of all of the linked list's items? Or is there a specific sorting algorithm that would help me do this?
O(n/2) is indeed equivalent to O(n) so an O(n/2) search is just a linear search i.e. iterate over the list and test each item until you find the one you are looking for.
If you are confused why O(n) and O(n/2) are equivalent, see my answer here.

Time complexity of concatenating/copying two vectors [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
vector1.insert( vector1.end(), vector2.begin(), vector2.end() );
What will be the Time complexity of concatenating/copying two vectors?
From the standard [vector.modifiers]/2:
Complexity: If reallocation happens, linear in the number of elements
of the resulting vector; otherwise, linear in the number of elements
inserted plus the distance to the end of the vector.

How do you implement quicksort with the pivot in the middle position and what is this variation called? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How do you implement quicksort with the pivot in the middle position and not in the last/first one?
It seems to be Quicksort, as the function name suggests; however there apparently is no recursive call to sort the parts after pivoting. I suggest moving the output out of the function quickSort and add recursive calls to parts of the array after the poivoting and rearrangement.
The answer lies in the Wikipedia article linked in this post.

To count the occurrences of a particular word in the linked list of strings. how can it be done in log(n) time? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a SORTED singly linked list of strings. I need to find occurrences of a particular string in the list. How can I do it in logarithmic time?
Not. Lists support only linear access, and since your string can be anywhere you must check O(N) elements.

can 0-1 knapsack be implemented using 1D array? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I found implementation using 2D array http://www.geeksforgeeks.org/dynamic-programming-set-10-0-1-knapsack-problem/. But how to implement it using 1D array and if it is not possible then why?
Note that each of values in the current row uses only elements of the current and previous rows. Hence you can implement the algorithm with an array K[2][W], which is the same as using an array K[2*W] with some additional trivial index calculations