Searching and Sorting an Array

Hi, long long time no see, this is Bndsbon. And the blog post I am writing about is related to searching and sorting an array. Which includes several different sorting methods. And some exercises of the textbook. So without further due, let us get started!

Searching Algorithms

When computers are created, people were looking for a way to increase their efficiency in searching for information. Thus, they created algorithms that would enable users to find key components faster and more efficient. And soon, there are hundreds of algorithms appearing, and in order to let you guys know more, here I am going to talk about two of the major and most popular searches. The first one is Linear search, and the second one is the Binary search.

Binary Search

The binary search algorithm looks for an item that is already in the sorted list and compares that with the other data in the list.

The mechanism behind the search is that it uses the value to compare with the middle data. If the two data are not equal, the minimum or the maximum of the array is eliminated depending on the result of the searches itself, and it will loop until it is successful.

Sequential Search

The search closely examines every data within the array and compares the data with the one that is currently searching.

This method is commonly used with collections and reading textfiles.

Sorting Algorithms

After talking about the searching algorithms, people during the time the computer era also invented algorithms that would help the users to put the numbers into the correct order. And today, I am going to talk about Bubble sort and Selection sort 

Bubble Sort

In essence, the bubble sort is a way that compares the value from the start of the array with the next value, and if the next value is smaller they swap, and the algorithm go through this process multiple times until they get to an end.

Though this sorting is very simple to understand, but most computers do not prefer to use it, since it is too slow and impractical. However, this algorithm could still be used to deal with daily small troubles involved in sorting like a series of simple numbers.

And here is the code for the bubble sort that I have created.

Screen Shot 2017-09-19 at 3.41.18 PM.png

Here are the values after sorted:

Screen Shot 2017-09-19 at 5.21.39 PM.png

Selection Sort

The selection sort first select the smallest number and place it at the end of the array. Then the next smallest number is placed at the next position of the first number, so on and so forth, the array can be sorted. The unsorted section of the array is considered as the unsorted array.

It is famous for its simplicity, but it is useful only under situations like when the computer lacks necessary memories etc.

Here is a program I have created that would sort the array using a selection sort.

Screen Shot 2017-09-19 at 3.41.29 PM.png.

Here is what the program looks like:

Screen Shot 2017-09-19 at 5.22.02 PM.png

Big O Notation

The big O notation is a notation used in mathematical models and computer algorithms, when behavior of a function is tending to go to infinity. In computer science, it is used to evaluate how efficient the algorithm is.

If you wanted to know more about this, please visit the following website: https://www.youtube.com/watch?v=__vX2sjlpXU&feature=youtu.be

Here are all the information that I am going to talk about. Please feel free to ask any questions or concerns.

Leave a comment

Blog at WordPress.com.

Up ↑