<b>please explain “ Stable sort ” in simple language</b>
Stable sorting algorithms maintain the relative order of records with equal keys. (i.e. sort key values). That is, a sorting algorithm is stable if whenever there are two records R and S with the same key and with R appearing before S in the original list, R will appear before S in the sorted list.
When equal elements are indistinguishable, such as with integers, or more generally, any data where the entire element is the key, stability is not an issue. However, assume that the following pairs of numbers are to be sorted by their first coordinate:
(4, 1) (3, 7) (3, 1) (5, 6)
In this case, two different results are possible, one which maintains the relative order of records with equal keys, and one which does not
(3, 7) (3, 1) (4, 1) (5, 6) (order maintained)
(3, 1) (3, 7) (4, 1) (5, 6) (order changed)
<b>what is “Binary search ” could you explain in simple terms</b>
A binary search algorithm is a technique for finding a particular value in a sorted list.A binary search finds the median element in a list, compares its value to the one you are searching for, and determines if it’s greater than, less than, or equal to the one you want.A binary search is an example of a divide and conquer algorithm. It copmapres the key with root, and if its less tha the the root element it goes to left child of the root, and compares again, if it is still less than the root, it goes further down and so on untill it finds the key. and if the key is greater than the root node or root element it goes to the right child and starts the comparison again.
Hope this answers the first two questins of yours.
Add comment