Introduction to Algorithms No.4

Hello. I have learnt and written the selection sort:

https://github.com/uriha421/introduction_to_algorithms/blob/master/I_Foundations/selection_sort.c


I have also learnt the running time of an algorithm. The running time means how long it takes to execute an algorithm.
It is clear that it depends on the size of an input. It also depends on the input itself. Let's take an example of the insertion-sort algorithm. If the input array is already sorted, the running time is clearly shorter than the average running time. On the other hand, the input is reversely sorted, the running time is much longer.
And it is more important to think about the running time in the worst case. Because ...
I have to go to bed :(

See you tomorrow.

Comments

  1. This comment has been removed by a blog administrator.

    ReplyDelete
    Replies
    1. An interesting point of view!

      They return the same value. But they are different functions. Considering what the input is, choose the best algorithm. For example, insertion sort runs much faster than the other sorting algorithms for an almost-sorted array. See wikipedia for details.

      Delete
    2. I am so sorry.........
      I have deleted your comment by mistake.......

      You said "Are the two algorithms(insertion sort and selection sort) implementing the same function but the different algorithm?"

      Delete
    3. I see. I will try to write two algorithms tomorrow at my computer. Thanks for you answer.

      Delete

Post a Comment

Popular posts from this blog

Introduction to Algorithms No.3

Introduction to Algorithms No.7

Introduction to Algorithms No.10