answersLogoWhite

0


Best Answer

quicksort should be O(n^2), but merge sort should be O(nlogn).

but if you can modify partition algorithm with checking all values same in array from p to r, it could be O(nlogn).

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: If quick sort and merge sort have same elements then what will be the complexity of both algorithms?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Which is the easiest sorting method?

There are generally eight sorting algorithms that are studied in school by computer science students. They are as follows: insertion, bubble, quick, quick3, merge, shell, heap, and selection sorting. There are different types of sorting algorithms. One would be considered good if it is accurate and efficient. Different types of sorting includes; sequential, ascending, and descending.


What do you understand by complexity of sorting algorithms?

By understanding the time and space complexities of sorting algorithms, you will better understand how a particular algorithm will scale with increased data to sort. * Bubble sort is O(N2). The number of Ops should come out <= 512 * 512 = 262144 * Quicksort is O(2N log N) on the average but can degenerate to (N2)/2 in the worst case (try the ordered data set on quicksort). Quicksort is recursive and needs a lot of stack space. * Shell sort (named for Mr. Shell) is less than O(N4/3) for this implementation. Shell sort is iterative and doesn't require much extra memory. * Merge sort is O( N log N) for all data sets, so while it is slower than the best case for quicksort, it doesn't have degenerate cases. It needs additional storage equal to the size of the input array and it is recursive so it needs stack space. * Heap sort is guaranteed to be O(N log N), doesn't degenerate like quicksort and doesn't use extra memory like mergesort, but its implementation has more operations so on average its not as good as quicksort.


Limitations of merge sort and quick sort?

Comolexity Not efficent big data


How do you sort an array of numbers?

Use a sorting algorithm. There are a bewildering number of sorting algorithms, both stable and unstable. To sort numbers, an unstable sort suffices. The algorithm you use will depend on how many numbers need to be sorted (a small or a large set), however a hybrid algorithm (a combination of two or more algorithms) can cater for both. Introsort (unstable) and timsort (stable) are the two most common hybrid sorting algorithms.


How do you select pivot in quick sort?

quick sort has a best case time complexity of O(nlogn) and worst case time complexity of 0(n^2). the best case occurs when the pivot element choosen as the center or close to the center element of the list.the time complexity can be derived for this case as: t(n)=2*t(n/2)+n. whereas the worst case time complexity for quick sort happens when the pivot element is towards the end of the list.the time complexity for this can be derived using the recurrence eqn: t(n)=t(n-1)+n

Related questions

Why quick sort better than merge sort?

it has less complexity


What are the types of sort algorithms?

insertion,bubble,quick, quick3, merge, shell,heap, selection sorting


What are advantages of greedy method?

Greedy algorithms are simple to implement and easy to understand. They typically have a low time complexity, making them efficient for some problems. Greedy algorithms can provide quick solutions when the problem can be solved by making locally optimal choices.


Which is the easiest sorting method?

There are generally eight sorting algorithms that are studied in school by computer science students. They are as follows: insertion, bubble, quick, quick3, merge, shell, heap, and selection sorting. There are different types of sorting algorithms. One would be considered good if it is accurate and efficient. Different types of sorting includes; sequential, ascending, and descending.


Did Fleet Financial and Quick and Ready merge?

Fleet Financial and Quick and Ready merged


What do you understand by complexity of sorting algorithms?

By understanding the time and space complexities of sorting algorithms, you will better understand how a particular algorithm will scale with increased data to sort. * Bubble sort is O(N2). The number of Ops should come out <= 512 * 512 = 262144 * Quicksort is O(2N log N) on the average but can degenerate to (N2)/2 in the worst case (try the ordered data set on quicksort). Quicksort is recursive and needs a lot of stack space. * Shell sort (named for Mr. Shell) is less than O(N4/3) for this implementation. Shell sort is iterative and doesn't require much extra memory. * Merge sort is O( N log N) for all data sets, so while it is slower than the best case for quicksort, it doesn't have degenerate cases. It needs additional storage equal to the size of the input array and it is recursive so it needs stack space. * Heap sort is guaranteed to be O(N log N), doesn't degenerate like quicksort and doesn't use extra memory like mergesort, but its implementation has more operations so on average its not as good as quicksort.


Limitations of merge sort and quick sort?

Comolexity Not efficent big data


How do you sort an array of numbers?

Use a sorting algorithm. There are a bewildering number of sorting algorithms, both stable and unstable. To sort numbers, an unstable sort suffices. The algorithm you use will depend on how many numbers need to be sorted (a small or a large set), however a hybrid algorithm (a combination of two or more algorithms) can cater for both. Introsort (unstable) and timsort (stable) are the two most common hybrid sorting algorithms.


How do you select pivot in quick sort?

quick sort has a best case time complexity of O(nlogn) and worst case time complexity of 0(n^2). the best case occurs when the pivot element choosen as the center or close to the center element of the list.the time complexity can be derived for this case as: t(n)=2*t(n/2)+n. whereas the worst case time complexity for quick sort happens when the pivot element is towards the end of the list.the time complexity for this can be derived using the recurrence eqn: t(n)=t(n-1)+n


What are the different types of sorting?

insertion,bubble,quick, quick3, merge, shell,heap, selection sorting


What are the different types of algorithm?

insertion,bubble,quick, quick3, merge, shell,heap, selection sorting


Who is better quick sort or merge sort?

Statistically both MergeSort and QuickSort have the same average case time: O(nlog(n)); However there are various differences. Most implementations of Mergesort, require additional scratch space, which could bash the performance. The pros of Mergesort are: it is a stable sort, and there is no worst-case scenario. Quicksort is often implemented inplace thus saving the performance and memory by not creating extra storage space. However the performance falls on already sorted/almost sorted lists if the pivot is not randomized. == ==