Space cost of Algs4-1.4.36 down-pressure Stack

Source: Internet
Author: User

1.4.36 space cost of the lower-pressure stack. Explain the data in the following table. It shows the general space cost of implementing various lower-pressure stacks. The node of the linked list is a static nested class, thus avoiding the overhead of non-static Nested classes.

1) The Int element type based on the linked list. N nodes are required for N values. Each node requires 16 bytes of object overhead + two 8-byte references, a total of 32 bytes, N nodes need 32 N bytes.

2) The integer element type based on the linked list. N nodes and N integers are required for N values. Each node needs 32 bytes and 32 bytes, an integer requires 16 bytes of object overhead + 4 bytes of int + 4 bytes to fill in a total of 24 bytes requires 24 n Bytes, a total of 56 bytes.

3) Based on the int element type of the variable-size array, the minimum length of the array is N for N values, and the longest array is 4 N (when the contraction point is reached). An int needs 4 bytes, it must be 4 to 16 n Bytes. An array object requires a 16-Byte object overhead and an int4-byte storage length overhead. A total of lg4n array objects are created, totaling 16lgn to 16lg4n bytes. The final length is about 4 N to 16 n Bytes.

4) based on the integer element type of the variable-size array, the minimum length of the array is N for N values, and the longest array is 4 N (when the contraction point is reached). An integer must be 24 bytes, an integer needs an 8-byte reference to point to it, so an element needs 32 bytes, and n elements need 32 N bytes. When the length of the array is 4 N, there are 3 n Array elements that do not point to integer, a reference is 8 bytes, and a 3N reference is a total of 24 n Bytes, then 32n + 24N = 56n bytes are required.

Space cost of Algs4-1.4.36 down-pressure Stack

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.