Question

In: Computer Science

Describe what are sorting and searching, and why are they essential in a computer science field....

Describe what are sorting and searching, and why are they essential in a computer science field. Give two examples when sorting and searching are necessary in designing software applications. Describe three different types of existing sorting algorithms and two types of searching algorithms. Justify, compare and contrast your choice of sorting and searching algorithms. Include one example of sorting or searching program. You may use a program you discover on the Internet as an example. Please make sure to give credits to the author of the program and cite the website where you found it.

Solutions

Expert Solution

Describe what are sorting and searching, and why are they essential in a computer science field.

SORTING - Arrangement in a certain order

In Computer Science, when data is in some random fashion, making it to an arranged way, will assist in improving the readability, understanding and working with the data.

SEARCHING - Check if a particular element is present in a group of elements

In Computer Science, when we have a bunch of values, we may need to check the existence of a particular value and respond accordingly.

Give two examples when sorting and searching are necessary in designing software applications.

1. For analysing students' results like finding topper among a set of students (marks must be sorted in ascending/descending order to determine the topper ), to find those who have failed in one particular subject but not another specific subject (find the students failed in particular subject, search for the same student's result in another subject to compare)

2. In library management system, the details of the books are added whenever a new book is purchased. It must be sorted in some order (like arranging according to the title of the book). When a reader requests a book, it must searched for among the list of available books.

Describe three different types of existing sorting algorithms and two types of searching algorithms.

Selection Sort:
Selection sort to arrange in ascending order finds the first minimum element and puts it in the first position, finds the second minimum element in the group and puts in the second position, finds the third minimum element and puts in the third position and so on.

Insertion Sort:
Insertion Sort works in the fashion like inserting a new card in a deck of already sorted cards. Initially, consider one value as sorted group, rest as unsorted. Then move a value from unsorted group to the sorted group. When moving check the value and place it in appropriate position. Repeat until all values are moved to the sorted group.

Merge Sort:
Merge Sort works on the idea of Dividing and Conquering. Keep dividing the entire group into two groups until each group contains only one value. Then start merging two groups into one by comparing and arranging the values during the merge.

Linear Search:
Linear Search searches in a linear fashion- sequentially one after another from the beginning to the end until the element is found. If the entire list is checked, but no match is found, it means there is no such value present.
It can search in a group of unsorted values.

Binary Search:

Binary Search searches in a group of sorted values by dividing into two. For any element in the group, when sorted in ascending order, the elements to the left are less and the elements to the right are larger. So, using this logic the search is restricted to one half by comparing with the value of search element.

Justify, compare and contrast your choice of sorting and searching algorithms.

SORTING ALGORITHM

In Selection Sort and Insertion Sort, the maximum number of comparisons made include N*N

In Merge Sort, the maximum number of comparisons include N log N independent of how the data is distributed.

So, choosing merge sort would be an ideal choice

SEARCH ALGORITHM

Linear Search is used when the elements are unsorted and binary search is used when the elements are sorted.

For Linear Search, when element is not found, a maximum of n checks are made.

For Binary Search, when element is not found, a maximum of n/2 checks are made.

Include one example of sorting or searching program.

EXAMPLE: LINEAR SEARCH

Get the values and the number to check. For every number starting from the first value, search if that is the search element. If found, print the index and position. Else, if the entire list is traversed, print element not found

-PYTHON PROGRAM

# Get the list of numbers
number=[int(i) for i in input("Enter the values").split(",")]
# Get the number to search for
num_to_check=int(input("Enter the number to check:"))
# Starting from beginning, check if that is the search element
for j in range(0,len(number)):
        # If found, print the index and position
        if(num_to_check==number[j]):
                print("Number found at index",j,"and position", j+1)
                break
#If the entire list is traversed and no match is found, print number not found
else:
        print("Number not found")

SCREENSHOT OF PROGRAM TO ASSIST IN INDENTATION

OUTPUT (SCREENSHOT)

In this example, the element is found at third check. First check made is 5 with 7, then 3 with 7 and then 7 with 7.


Related Solutions

In regards to tableau what is nested sorting useful for? sorting on a single field appearing...
In regards to tableau what is nested sorting useful for? sorting on a single field appearing in the last column sorting alphabetically on a field with long text sorting data using values in more than one field sorting both alphabetically and numerically on the same field
a.) What are the tight lowerbound of the comparison based sorting problem and searching problem respectively....
a.) What are the tight lowerbound of the comparison based sorting problem and searching problem respectively. b.) True or False: A P problem is one that can be solved in polynomial time. while a NP problem is one that cannot be solved in polynomial time.Tell the relationship between P and NP problems
For your initial post, utilizing credible sources, describe the various types of sorting and searching algorithms...
For your initial post, utilizing credible sources, describe the various types of sorting and searching algorithms and give an example of each other than the examples provided in the assigned readings. Apply algorithmic design and data structure techniques in developing structured programs by discussing time and space complexity in relation to whether using a sort algorithm is better than using a search algorithm. Does it really matter with the capabilities of computers today? Provide justification to support your answers.
What is an algorithm? Why is it important in the field of computer programming?
What is an algorithm? Why is it important in the field of computer programming?
i want to write research paper in the field of computer science but cant decide the...
i want to write research paper in the field of computer science but cant decide the topic for that plz help me.
Give me 4 important ethics for students in computer science field should be followe?
Give me 4 important ethics for students in computer science field should be followe?
Problem Description Objective This practical will test your knowledge on sorting and searching algorithms. In this...
Problem Description Objective This practical will test your knowledge on sorting and searching algorithms. In this practical, you will be implementing a number of algorithms. Each of these algorithms will be constructed in a different class. You should make sure that you know the complexity of the algorithms you implement. Design Think of how you are going to solve the problem and test your implementation with the test cases you designed based on the stages below. Testing Hint: it’s easier...
Describe different types of data structures in Computer Science with examples.
Describe different types of data structures in Computer Science with examples.
IN JAVA Searching and Sorting In An Integer List File IntegerList contains a Java class representing...
IN JAVA Searching and Sorting In An Integer List File IntegerList contains a Java class representing a list of integers. The following public methods are provided: ? IntegerList(int size)—creates a new list of size elements. Elements are initialized to 0. ? void randomize()—fills the list with random integers between 1 and 100, inclusive. ? void print()—prints the array elements and indices ? int search(int target)—looks for value target in the list using a linear (also called sequential) search algorithm. Returns...
Java Searching and Sorting, please I need the Code and the Output. Write a method, remove,...
Java Searching and Sorting, please I need the Code and the Output. Write a method, remove, that takes three parameters: an array of integers, the length of the array, and an integer, say, removeItem. The method should find and delete the first occurrence of removeItem in the array. If the value does not exist or the array is empty, output an appropriate message. (After deleting an element, the number of elements in the array is reduced by 1.) Assume that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT