Wednesday 9 October 2013

Algorithm in real world



Role of algorithms in real-world

Algorithm

An algorithm is a step-by-step list of directions that need to be followed to solve a problem. The instructions should be simple enough such that each step can be done without thinking about it. Algorithms are often used to describe how a computer might solve a problem. But there are algorithms in the real world too. A recipe can be considered a type of algorithm. It tells what ingredients are needed to make the dish and what steps to follow. If the recipe tells exactly what to do without too much confusion, then it is an algorithm.
There is usually more than one way to solve a problem. However, some of the ways will be better than others. When we look at algorithms as a way of solving problems, often we want to know how long it would take a computer to solve the problem using a particular algorithm. When we write algorithms, we like our algorithm to take the least amount of time so that we can solve our problem as quickly as possible. Algorithms are better when they are easier for the computer to do. The thing that measures how hard an algorithm is called complexity.
Examples:

        1)    Usage of classification algorithms in smartphones
            Classification algorithms are used to identify activities, such as walking, jogging, climbing stairs, sitting, standing, and help map accelerometer data to those activities. These algorithms, or methods, learn from specific examples. Generally it provides the algorithm with acceleration data that is labeled with the associated activity, and from this data the algorithm automatically generates rules for identifying the activities. Since these rules can be implemented in software, the activity recognition process can be automated.the smartphone are more context-sensitive, so that its behavior would take into account what the user is doing. The only assumption that we make is that the user's phone is running our app in the background and that the phone is in their pocket.
·         The phone could then, for example, automatically send phone calls to voice mail if the user was jogging.
The result is adequate for obtaining a general picture of how much time a person spends on each activity daily, but are far from ideal. However, if we can obtain even a very small amount of data that a user actively labels as being connected with a particular activity.This shows that people move differently and that these differences are important when identifying activities.
             
               
2)    Sorting algorithm
Now let us discuss one of the real-world example where the algorithms are applied.
Sorting by colors
This is an example of an algorithm for sorting cards with colors on them into piles of the same color:
1.      Pick up all of the cards.
2.      Pick a card from your hand and look at the color of the card.
3.      If there is already a pile of cards of that color, put this card on that pile.
4.      If there is no pile of cards of that color, make a new pile of just this card color.
5.      If there is still a card in your hand, go back to the second step.
6.      If there is no card left in your hand, then the cards are sorted. You are done.





·         Figure below demonstrates that the cards have been sorted into piles of same colors 

                  
·          

  • Figure below demonstrates that if pile of card is of that color then a new pile is made and again starts sorting

     
Sorting by numbers
These are examples of algorithms for sorting a stack of cards with many different numbers, so that the numbers are in order. Players start with a stack of cards that have not been sorted.

Algorithm:-

This algorithm goes through the stack of cards, one card at a time. This card is compared to the next card in the stack. Please note that this position only changes in step 3. This algorithm is called bubble sort. It is slow.
  1. If the stack of cards is empty, or it only contains one card, it is sorted; you are done.
  2. Take the stack of cards. Look at the first card (the top) of the stack.
  3. The card you are looking at is card A. The position where card A currently is in the stack is P.
  4. If there are no more cards in the stack after card A, go to step 8.
  5. The next card in the stack is card B.
  6. If card B has a lower number than card A, swap the positions of cards A and B. Remember you did this. When you swap cards, do not change the position P.
  7. If there is another card in the stack after position P, look at it; go back to step 3.
  8. If you didn’t swap the position of any cards in the last run, you are done; the stack of cards is sorted.
  9. Otherwise go back to step 2.
·         Figure below illustrates that the stack of cards have started to sort according to the same color and even sort by numbers in order.
                     

·         Figure below illustrates the finally sorted stack of cards in  order.


                      

No comments:

Post a Comment