20172333 2018-2019-1 "program design and data structure" Fourth Week study summary

Source: Internet
Author: User

20172333 2018-2019-1 "program design and data structure" Fourth week study summary textbook Learning content summary 6.1 list collection
    • The list collection has no intrinsic capacity size and grows as needed
    • List collections can add and remove elements at the middle and end, except that queues and stacks can only be added and deleted at the end.
    • List collections are divided into three categories: ordered, unordered, indexed
    • There are sequence lists: their elements are sorted according to the intrinsic characteristics of the elements.
    • Unordered list: Elements are sorted only by their position in the list.
    • Indexed lists: The elements are sorted according to their own numeric index.
6.4 Josephus Problems
    • The elements in the list are extracted every other element, until one is left, and the first index of the last one is the Josephus problem.
    • After the elements are removed from the index list, their indexes are automatically filled, which is the problem.

      6 list in the Java Collection API
Method function
Add (E Element) Add an element to the end of the list
Add (int index, E Element) Inserts an element at the specified index
Get (int index) Returns the element at the specified index
Remove (int index) Deletes the element at the specified index
Remove (o OBJECR) Overrides the element at the specified index
Set (int index, E Element) Returns the number of elements in a list
6 List ADT
Operation function
Removefirst Remove the first element from a list
Removelast Remove the last element from the list
Remove Remove an element from the list
First View elements at the front of the list
Last View elements at the end of a list
Contains Determine if the list contains an element
IsEmpty Determines whether the list is empty
Size Determining the number of elements in a list
6 List of array implementations
    • Since the list can be inserted and deleted anywhere, and the array implements the list, the elements need to be moved.
    • In the case of the remove operation, if the element to be deleted is the last element of the list, then the n comparison operation is required. It turns out that the implementation of this delete operation requires just n comparisons and panning operations, so the complexity of the operation is O (n). If you are using a ring array implementation, he simply improves performance by removing the first element in such a special case.
    • When performing a contains operation, because the method performs a linear lookup of the list, the worst case scenario is that the element being found is not in the list, in which case the n comparison operation is required, and the complexity of the operation is O (n).
6 List of linked lists implementation
    • The Remove action is the most important step in the list implementation, which includes determining whether the list is empty and finding the deleted element. and removed in four different conditions (1. The deleted element is the only element in the list. 2. The deleted element is the head element in the list. 3. The deleted element is the tail element in the list. 4. The deleted element is located in the middle of the list. )
    • Although list-implemented lists do not need to translate elements to achieve the purpose of collapse, but because to find the deletion of elements, still may need to do the n comparison operation, so the complexity is still O (n).
Problems in teaching materials learning and the solving process
    • Question 1: When you learn a book, you see this sentence

      • Index values for index lists are always contiguous. If you delete an element, the position of the other element will be as "collapsed" to eliminate the resulting gap.
    • So what's the meaning of the collapse here, pointing to the elements that are going to disappear, or are they automatically padded?

    • Problem 1 Solution: After Baidu, is roughly the back of the elements will be automatically indexed, after all, the capacity of the list is unrestricted.

    • Question 2: In the book on the Array Implementation list Remove method inside, finally a row modcount++ operation, and then the book did not specifically describe what the modcount is used.
    • Problem 2 Solution: In the case of reference data and source code, the value is found to record the number of times the list array changes, if the number of exceptions, there is a check function about Modcount can call and produce an exception.

Graph function

Figure Source

Figure expected situation

Problems in code debugging and the resolution process
    • Issue 1: In the test process of the deletion method, the tail deletion will never delete things.
      Error message 1

    • Resolution 1: In the return to the test of the deletion method found that the deletion method is not a problem, think of the ToString method has a mistake, I look like no problem, later found that I put the initialization of the STR step in the loop, resulting in each cycle will be initialized once, This causes the Delete method to erase the initialized "".
      Figure ToString

    • Issue 2: In the implementation of the list of the tail method, there are the same problems as the array, the method used after the end of the deletion of elements.
    • Resolution 2: At the beginning I directly think of whether ToString made the last mistake, and then looked at the last error, can only check the method, because the list is deleted by the pointer, I have been concerned about the pointer, and later studied for a long time did not find any problem, The tail pointer is also pointing to the bottom of the original list of the second, it is said that directly will be disconnected Ah, later asked Yukun, he said he also encountered this problem, and this problem is because I will tail point to the second-to-last element, but the penultimate element or continue to point to the final element, equivalent to not open, It is completely detached to point to null. Hand Drawing

Code Hosting

-Figure Code

Last week's summary of the wrong quiz
    • 1.A linked implementation of A stack adds and removes elements from the _______ of the linked list.
    • A. Front
    • B. Rear
    • C. Middle
    • D. None of the above
    • Answer: A. Parsing: The stack is similar to putting the box, and then take the box from the top one to take is the front.
    • 2.A polymorphic Reference uses _______________, not the type of the reference, to determine which version of A method to I Nvoke.
    • A. The type of the object
    • B. The type of the reference
    • C. Both A and B
    • D. None of the above
    • Answer: A. Parsing: polymorphic use often focuses on the type of object rather than the type of application.
Pairing and mutual evaluation

Based on the scoring standards, I give Linan's blog score: 7 points. The score is as follows:

Correct use of markdown syntax (plus 1 points)

Complete features in the template (plus 1 points)

Problems and solutions in textbook learning (plus 3 points)

Problem and resolution in code debugging, no problem

Feelings, experience real (add 1 points)

Reviews seriously, can point out the blog and the Code of the problem (plus 1 points)

reviewed the classmates blog and code
    • This week's study of the knot
      • 20172330 Linan
      • Pair of photos
      • Pairs of learning content
        • Collection Overview-Stack
        • Chain Structure--stack
Other (sentiment, thinking, etc., optional)

This national day has been happy, in addition to the first day of the national day to enjoy seven hours of experimental programming and the countdown to three days of PP programming, as well as my favorite blog--in the process of writing PP only to find that they have a lot of knowledge points do not know, hope to gradually have that kind of handy feeling it.

Learning progress Bar
lines of code (new/cumulative) Blog Volume (Add/accumulate) Learning Time (new/cumulative) Important Growth
Goal 5000 rows 30 Articles 400 hours
First week 0/0 1/1 10/10
Second week 0/0 1/2 10/20
Third week 1500/1500 1/3 10/30
Week Four 2761/4261 2/5 25/55
    • Java Programming and Data Structure Tutorial (second edition)

    • Tutorial on Java Programming and data Structure (second edition) Learning Guide
    • The explanation of the big guy in a word the difference between generics and object

20172333 2018-2019-1 "program design and data structure" Fourth week study summary

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.