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.
Related
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.
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 2 years ago.
Improve this question
I was solving a question in codeforces,which was about insertion sort,
the link:the problem
I am unable to solve the question the editorial says
old - 2 * (di, ai + dj, aj - di, aj - dj, ai) - 1
I am not understanding the solution kindly help!
here is the editorial link:
https://codeforces.com/blog/entry/9584
For an insertion sort into a linked list, the number of "swaps" is maximum of 2, if you consider inserting a new item as "swapping pointers". The minimal number would be zero, if the key already exists; otherwise you'll swap one pointer when inserting before the head or after the tail.
The concept of an insertion sort is to keep the container sorted. Most of the time is spent searching for the proper place in the container to insert the new datum.
For an array container, you would need to move elements in order to make room for the new data; which doesn't involve swapping.
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 7 years ago.
Improve this question
Which of the following containers have average search by value complexity equal to O(log(n))?
Which ones have O(n) and O(n^2)?
std::vector
std::list
std::deque
std::set
std::multiset
std::unordered_set
std::unordered_multiset sorted
std::vector sorted
std::list sorted
std::deque sorted
The standard specifies the complexity of the relevant functions. Get a copy, or read a good reference. (See e.g. http://en.cppreference.com/w/cpp/container/unordered_set/find.)
They're all pretty much what you'd expect.
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.
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.