Introduction to Algorithms third Edition exercise 2.2-2

Source: Internet
Author: User

Select the algorithm pseudo-code:

For j=1-n-1 smallest = j for i=j+1 to N if A[i]<a[smallest] smallest=i a[j]=a[smallest] cyclic invariant at f Each iteration of the or loop (the loop variable is J) starts, and the sub-array containing the element a[1..j-1] pairs is ordered (consisting of the j-1 smallest element of the array [1..N]) and the condition of the loop termination is j>n-1, because the iteration J of each loop increases by 1, so there must be j=n. The j=n is brought into the loop invariant representation, and the elements in the Subarray a[1..n-1] are ordered (consisting of the n-1 smallest elements of the array a[1..n), so A[n] is the largest element. So the entire array has been sequenced. Best run and worst-case scenario (n^2)


This article is from the "Silly Endless Upgrade Tour" blog, make sure to keep this source http://zhangshifan.blog.51cto.com/9970564/1618381

Introduction to Algorithms third Edition exercise 2.2-2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.