What is the difference in Searching and Sorting ?

Showing Answers 1 - 10 of 10 Answers

saravnan

  • Nov 21st, 2007
 

Searching means search the information in a common pool where as sorting means arrange the content in any order.

  Was this answer useful?  Yes

hashini

  • Sep 4th, 2008
 

Searching means finding whether the element is present in the list or not whereas sorting means Arranging the list in ascending or descending order.

  Was this answer useful?  Yes

kbjarnason

  • Jul 2nd, 2010
 

Searching is finding things, sorting is arranging them.

Suppose you have the characters 'Z', 'A' and 'M' in an array.  Your code needs to know if 'M' is in the array.  How does it do it?  It searches.  "Is element 0 an 'M'?  No, it's a 'Z'.  Is element 1 an 'M'?  No, it's an 'A'.  Is element 2 an 'M'?  Yes, it is.  M is in the array."

Of course, the characters of the array are not in order.  To put them in order, you would sort them, perhaps as follows:

   Is 'Z' larger than 'A'?  Yes, so exchange them:  'A', 'Z', 'M'
   Is 'Z' larger than 'M'?  Yes, so exchange them: 'A', 'M', 'Z'
   Is 'Z' larger than... oops, we're at the end.  Done sorting.

Sorrting and searching are very distinct operations, but sorting can actually help searching.  For example, suppose your array had all 26 letters of the alphabet, but in random order, and your task was to find out the index of letters as someone passed them to you.

Suppose they pass an 'A'.  It might be in the first spot, but chances are against it.  Same for the second spot.  And so on.  As you examine more spots, the chances of finding the 'A' go up, until you have examined _every_ spot, all 26 of them, and your chances of finding it are now 100%.

Of course, you may have found it sooner, too.  Obviously, _some_ letter is in the first spot, another in the second, and so on, meaning if someone asks you those letters, you finish searching for them very quickly... but there's also some letter in the last spot and the second last spot, and those take longer.

If you average it out, searching this way takes about 13 tries per character - half of the number of elements being examined.  Could you improve that?

Absolutely: sort the array.  Get the desired character, say an 'R'.  Now start halfway into the array, where you get, say, an M.

Is R > M?  Yes; so you want to move "forwards".  How much?  You started with a jump of 13, you want half of that.  Call it 6.  Move ahead 6 elements, you get, oh, an S.  Is R > S?  No, so you jump back, again by half as much - 3 characters. 

If you do this, you'll discover that the average number of tries to find the desired letter is no longer 13 tries, but a little less than 5.  Indeed, you can do this with most any data set, and it doesn't have to be contiguous - it doesn't need to have _every_ letter or number in the set, it just needs to be sorted.  Start with the middle item, check it against the desired item, jump forwards or backwards by half as much as you started with, repeat.  If your "jump size" reaches 0 and you haven't found the item, it's not there.

Using this method, you can search for an element in a set of 1,024 items in just 10 steps instead of averaging 512 steps the other way, or in a set of 4.2 billion items in just 32 steps, instead of averaging 2.1 billion steps the other way.

Sorting and searching are distinct, but sorting can vastly help searching.

  Was this answer useful?  Yes

nsudheer

  • Jun 4th, 2011
 

Searching means Searching
Sorting means Sorting

Nothing special in its meaning, even in computer science. But, the algorithms to achieve this task are going to be special

  Was this answer useful?  Yes

Rubab Mujeeb

  • Dec 25th, 2015
 

In a given list...Search means to find a matched and appropriate element while Sorting does two things.. it finds the element and arrange it in a particular sequence.

  Was this answer useful?  Yes

naruto

  • Jan 5th, 2016
 

Imagine you have an array with 3,2,6,7,22. now sorting means to arrange the array like 2,3,6,22.
Searching simply means you have a number, eg 3, you have to search 3 in the array. It has nothing to do with arrangement of numbers. (But ofcourse it would be easy 2 search if numbers are sorted)

  Was this answer useful?  Yes

Soham Medda

  • Feb 3rd, 2016
 

Searching is to find a record or a set of record from a group of records.

Sorting is arranging group of record following an order.

  Was this answer useful?  Yes

Jeff

  • Jun 4th, 2017
 

Searching mean when you are performing an operation looking for a specific thing that you need...the thing that you are looking for does not alike to any thing so you have to find your exact requirement through it different process. Whereas sorting meaning you are doing a work in library i.e arranging a book in a proper manner..although it has different process type, sorting has already been done when you perform a work of arranging book even if it is ascending or descending

  Was this answer useful?  Yes

loki

  • Feb 27th, 2018
 

Searching means finding whether the element is present in the list or not whereas sorting means Arranging the list in ascending or descending order.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions