Selection and sequencing of algorithm plots

Source: Internet
Author: User

Tells the basic data structure in memory, array is good at finding the element, the list is good at finding the position, in order to adapt to the data different operation request, should use flexibly.

1. How the Memory Works

Computer memory is like a cupboard with many drawers.

2. Arrays and Linked lists

The position of the element in the array is called the index element xx at index XX

The time complexity of the array and the different operations of the linked list

3. Select sort

Definition: Iterate over this array, remove the largest element to the new array and delete the largest element in the tuple, and iterate over the array again ... Until the original array is empty

Python implementation selection sort

def findSmallest(arr):    smallest = arr[0]    smallest_index = 0    for i in range(1, len(arr)):        if arr[i] < smallest:            smallest = arr[i]            smallest_index = i    return smallest_indexdef selectionSort(arr):    newArr = []    for i in range(len(arr)):        smallest = findSmallest(arr)        newArr.append(arr.pop(smallest))    return newArrprint(selectionSort([5, 3, 6, 2, 10])) # [2, 3, 5, 6, 10]

Selection and sequencing of algorithm plots

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.