知识库 知识库
首页
  • Hyperskill - Java

    • Java basic
    • Java OOP
    • 应知
    • 扩展
    • IO & Stream
    • Error & Exception
    • Algorithm & Data structure
    • Design pattern
    • Web
    • Spring boot
  • 练习题

    • 选择题 & 填空题
    • 代码题
  • Frank - Java与生活 (OOP)

    • 参考资料
    • Java基础
    • OOP上半部分
    • OOP下半部分
  • Frank - Java API进阶

    • Base API
    • Unit Test and main function
  • 学习笔记
  • 学习笔记

    • 数据库
  • Frank - MySQL删库跑路

    • 安装、连接、配置
    • 基本操作——数据库
    • 基本操作——表
    • 基本操作——数据
    • 数据类型
    • 列属性完整性
    • 数据库设计思维
    • 单表查询
    • 多表查询
  • 学习笔记

    • 其它
  • Frank - Linux现代方法

    • 必知
    • 命令
    • 技巧
  • 技术文档
  • Git
  • GitHub技巧
  • 前端
  • Khan Academy - 语法
  • Monthly
  • 阅读
  • Others
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
收藏
  • 标签
  • 归档
GitHub (opens new window)

Jim FuckPPT

Java小学生
首页
  • Hyperskill - Java

    • Java basic
    • Java OOP
    • 应知
    • 扩展
    • IO & Stream
    • Error & Exception
    • Algorithm & Data structure
    • Design pattern
    • Web
    • Spring boot
  • 练习题

    • 选择题 & 填空题
    • 代码题
  • Frank - Java与生活 (OOP)

    • 参考资料
    • Java基础
    • OOP上半部分
    • OOP下半部分
  • Frank - Java API进阶

    • Base API
    • Unit Test and main function
  • 学习笔记
  • 学习笔记

    • 数据库
  • Frank - MySQL删库跑路

    • 安装、连接、配置
    • 基本操作——数据库
    • 基本操作——表
    • 基本操作——数据
    • 数据类型
    • 列属性完整性
    • 数据库设计思维
    • 单表查询
    • 多表查询
  • 学习笔记

    • 其它
  • Frank - Linux现代方法

    • 必知
    • 命令
    • 技巧
  • 技术文档
  • Git
  • GitHub技巧
  • 前端
  • Khan Academy - 语法
  • Monthly
  • 阅读
  • Others
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
收藏
  • 标签
  • 归档
GitHub (opens new window)
  • Hyperskill - Java

  • 练习题

    • 选择题 & 填空题

      • What does the method print
      • Appending strings and ints
      • Varargs method invocation
      • Good reasons to use Java modules
      • Number generators
      • When the keyword cannot be used
      • Size and capacity
        • Topic
        • Problem
        • Hint & Explain
      • The number of copies
      • The number of insertions
    • 代码题

  • Frank - Java与生活

  • Frank - Java API进阶

  • 学习笔记

  • Java
  • 练习题
  • 选择题 & 填空题
Jim
2022-09-24
目录

Size and capacity

# Topic

Dynamic array

# Problem

Size and capacity

Assume that for a dynamic array of size 22 and capacity 44 we perform the following sequence of operations:

add 7
add 1
add 3
insert 4 3
add 6
add 7
add 8
1
2
3
4
5
6
7

Here "add x" means "add an element x to the end of the array" and "insert x i" means "add an element x at the specified index i".

Once all operations are performed, what will be the difference between the capacity of the new array (new_capacity) and its size (new_size)? Print this number in the field below.

Assume that the scaling factor for the array is 22. Also note that every time you increase the array's capacity, it becomes twice as big as the capacity of the array at the previous step, rather than the initial array's capacity.

Enter a number:

7

Correct.

# Hint & Explain

// The task only confuses, but does not help !

    add(7); // size == 3; capacity == 4
    add(1); // size == 4; capacity == 4
    add(3); // size == 5; capacity == 8
            
    insert (3, 4); // size == 6; capacity == 8 !!! Insert !! not set. The array is being shifted
            
    add(6); // size == 7; capacity == 8
    add(7); // size == 8; capacity == 8
    add(8); // size == 9; capacity == 16
            
    // size == 9; capacity == 16
   // 16 - 9 = ?
编辑 (opens new window)
#Problem#Data structure
上次更新: 2022/09/25, 10:41:23
When the keyword cannot be used
The number of copies

← When the keyword cannot be used The number of copies→

最近更新
01
《挪威的森林》
04-14
02
青钢影
04-14
03
Processing strings
02-18
更多文章>
Theme by Vdoing | Copyright © 2022-2023 Jim Frank | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式