mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-05 11:41:22 +08:00
deploy
This commit is contained in:
@@ -91,7 +91,7 @@
|
||||
<div data-md-component="skip">
|
||||
|
||||
|
||||
<a href="#41-arrays" class="md-skip">
|
||||
<a href="#41-array" class="md-skip">
|
||||
Skip to content
|
||||
</a>
|
||||
|
||||
@@ -201,7 +201,13 @@
|
||||
|
||||
<li class="md-select__item">
|
||||
<a href="/" hreflang="zh" class="md-select__link">
|
||||
中文
|
||||
简体中文
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="md-select__item">
|
||||
<a href="/zh-hant/" hreflang="zh-Hant" class="md-select__link">
|
||||
繁體中文
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@@ -393,7 +399,7 @@
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
0.1 About This Book
|
||||
0.1 About this book
|
||||
</span>
|
||||
|
||||
|
||||
@@ -414,7 +420,7 @@
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
0.2 How to Read
|
||||
0.2 How to read
|
||||
</span>
|
||||
|
||||
|
||||
@@ -491,7 +497,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2m0 16H5V5h14v14M6.2 7.7h5v1.5h-5V7.7m6.8 8.1h5v1.5h-5v-1.5m0-2.6h5v1.5h-5v-1.5M8 18h1.5v-2h2v-1.5h-2v-2H8v2H6V16h2v2m6.1-7.1 1.4-1.4 1.4 1.4 1.1-1-1.4-1.4L18 7.1 16.9 6l-1.4 1.4L14.1 6 13 7.1l1.4 1.4L13 9.9l1.1 1Z"/></svg>
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Chapter 1. Introduction to Algorithms
|
||||
Chapter 1. Introduction to algorithms
|
||||
</span>
|
||||
|
||||
|
||||
@@ -507,7 +513,7 @@
|
||||
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_2_label" aria-expanded="false">
|
||||
<label class="md-nav__title" for="__nav_2">
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
Chapter 1. Introduction to Algorithms
|
||||
Chapter 1. Introduction to algorithms
|
||||
</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
@@ -524,7 +530,7 @@
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
1.1 Algorithms are Everywhere
|
||||
1.1 Algorithms are everywhere
|
||||
</span>
|
||||
|
||||
|
||||
@@ -545,7 +551,7 @@
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
1.2 What is an Algorithm
|
||||
1.2 What is an algorithm
|
||||
</span>
|
||||
|
||||
|
||||
@@ -626,7 +632,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M6 2h12v6l-4 4 4 4v6H6v-6l4-4-4-4V2m10 14.5-4-4-4 4V20h8v-3.5m-4-5 4-4V4H8v3.5l4 4M10 6h4v.75l-2 2-2-2V6Z"/></svg>
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Chapter 2. Complexity Analysis
|
||||
Chapter 2. Complexity analysis
|
||||
</span>
|
||||
|
||||
|
||||
@@ -642,7 +648,7 @@
|
||||
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="false">
|
||||
<label class="md-nav__title" for="__nav_3">
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
Chapter 2. Complexity Analysis
|
||||
Chapter 2. Complexity analysis
|
||||
</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
@@ -659,7 +665,7 @@
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
2.1 Algorithm Efficiency Assessment
|
||||
2.1 Algorithm efficiency assessment
|
||||
</span>
|
||||
|
||||
|
||||
@@ -680,7 +686,7 @@
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
2.2 Iteration and Recursion
|
||||
2.2 Iteration and recursion
|
||||
</span>
|
||||
|
||||
|
||||
@@ -701,7 +707,7 @@
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
2.3 Time Complexity
|
||||
2.3 Time complexity
|
||||
</span>
|
||||
|
||||
|
||||
@@ -722,7 +728,7 @@
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
2.4 Space Complexity
|
||||
2.4 Space complexity
|
||||
</span>
|
||||
|
||||
|
||||
@@ -803,7 +809,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M11 13.5v8H3v-8h8m-2 2H5v4h4v-4M12 2l5.5 9h-11L12 2m0 3.86L10.08 9h3.84L12 5.86M17.5 13c2.5 0 4.5 2 4.5 4.5S20 22 17.5 22 13 20 13 17.5s2-4.5 4.5-4.5m0 2a2.5 2.5 0 0 0-2.5 2.5 2.5 2.5 0 0 0 2.5 2.5 2.5 2.5 0 0 0 2.5-2.5 2.5 2.5 0 0 0-2.5-2.5Z"/></svg>
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Chapter 3. Data Structures
|
||||
Chapter 3. Data structures
|
||||
</span>
|
||||
|
||||
|
||||
@@ -819,7 +825,7 @@
|
||||
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="false">
|
||||
<label class="md-nav__title" for="__nav_4">
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
Chapter 3. Data Structures
|
||||
Chapter 3. Data structures
|
||||
</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
@@ -836,7 +842,7 @@
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
3.1 Classification of Data Structures
|
||||
3.1 Classification of data structures
|
||||
</span>
|
||||
|
||||
|
||||
@@ -857,7 +863,7 @@
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
3.2 Fundamental Data Types
|
||||
3.2 Fundamental data types
|
||||
</span>
|
||||
|
||||
|
||||
@@ -878,7 +884,7 @@
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
3.3 Number Encoding *
|
||||
3.3 Number encoding *
|
||||
</span>
|
||||
|
||||
|
||||
@@ -899,7 +905,7 @@
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
3.4 Character Encoding *
|
||||
3.4 Character encoding *
|
||||
</span>
|
||||
|
||||
|
||||
@@ -982,7 +988,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 5v14h17V5H3m4 2v2H5V7h2m-2 6v-2h2v2H5m0 2h2v2H5v-2m13 2H9v-2h9v2m0-4H9v-2h9v2m0-4H9V7h9v2Z"/></svg>
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Chapter 4. Array and Linked List
|
||||
Chapter 4. Array and linked list
|
||||
</span>
|
||||
|
||||
|
||||
@@ -998,7 +1004,7 @@
|
||||
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_5_label" aria-expanded="true">
|
||||
<label class="md-nav__title" for="__nav_5">
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
Chapter 4. Array and Linked List
|
||||
Chapter 4. Array and linked list
|
||||
</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
@@ -1059,17 +1065,17 @@
|
||||
<li class="md-nav__item">
|
||||
<a href="#411-common-operations-on-arrays" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
4.1.1 Common Operations on Arrays
|
||||
4.1.1 Common operations on arrays
|
||||
</span>
|
||||
</a>
|
||||
|
||||
<nav class="md-nav" aria-label="4.1.1 Common Operations on Arrays">
|
||||
<nav class="md-nav" aria-label="4.1.1 Common operations on arrays">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#1-initializing-arrays" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
1. Initializing Arrays
|
||||
1. Initializing arrays
|
||||
</span>
|
||||
</a>
|
||||
|
||||
@@ -1078,7 +1084,7 @@
|
||||
<li class="md-nav__item">
|
||||
<a href="#2-accessing-elements" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
2. Accessing Elements
|
||||
2. Accessing elements
|
||||
</span>
|
||||
</a>
|
||||
|
||||
@@ -1087,7 +1093,7 @@
|
||||
<li class="md-nav__item">
|
||||
<a href="#3-inserting-elements" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
3. Inserting Elements
|
||||
3. Inserting elements
|
||||
</span>
|
||||
</a>
|
||||
|
||||
@@ -1096,7 +1102,7 @@
|
||||
<li class="md-nav__item">
|
||||
<a href="#4-deleting-elements" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
4. Deleting Elements
|
||||
4. Deleting elements
|
||||
</span>
|
||||
</a>
|
||||
|
||||
@@ -1105,7 +1111,7 @@
|
||||
<li class="md-nav__item">
|
||||
<a href="#5-traversing-arrays" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
5. Traversing Arrays
|
||||
5. Traversing arrays
|
||||
</span>
|
||||
</a>
|
||||
|
||||
@@ -1114,7 +1120,7 @@
|
||||
<li class="md-nav__item">
|
||||
<a href="#6-finding-elements" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
6. Finding Elements
|
||||
6. Finding elements
|
||||
</span>
|
||||
</a>
|
||||
|
||||
@@ -1123,7 +1129,7 @@
|
||||
<li class="md-nav__item">
|
||||
<a href="#7-expanding-arrays" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
7. Expanding Arrays
|
||||
7. Expanding arrays
|
||||
</span>
|
||||
</a>
|
||||
|
||||
@@ -1137,7 +1143,7 @@
|
||||
<li class="md-nav__item">
|
||||
<a href="#412-advantages-and-limitations-of-arrays" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
4.1.2 Advantages and Limitations of Arrays
|
||||
4.1.2 Advantages and limitations of arrays
|
||||
</span>
|
||||
</a>
|
||||
|
||||
@@ -1146,7 +1152,7 @@
|
||||
<li class="md-nav__item">
|
||||
<a href="#413-typical-applications-of-arrays" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
4.1.3 Typical Applications of Arrays
|
||||
4.1.3 Typical applications of arrays
|
||||
</span>
|
||||
</a>
|
||||
|
||||
@@ -1172,7 +1178,7 @@
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
4.2 Linked List
|
||||
4.2 Linked list
|
||||
</span>
|
||||
|
||||
|
||||
@@ -1214,7 +1220,7 @@
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
4.4 Memory and Cache
|
||||
4.4 Memory and cache
|
||||
</span>
|
||||
|
||||
|
||||
@@ -1293,7 +1299,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17.36 20.2v-5.38h1.79V22H3v-7.18h1.8v5.38h12.56M6.77 14.32l.37-1.76 8.79 1.85-.37 1.76-8.79-1.85m1.16-4.21.76-1.61 8.14 3.78-.76 1.62-8.14-3.79m2.26-3.99 1.15-1.38 6.9 5.76-1.15 1.37-6.9-5.75m4.45-4.25L20 9.08l-1.44 1.07-5.36-7.21 1.44-1.07M6.59 18.41v-1.8h8.98v1.8H6.59Z"/></svg>
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Chapter 5. Stack and Queue
|
||||
Chapter 5. Stack and queue
|
||||
</span>
|
||||
|
||||
|
||||
@@ -1309,7 +1315,7 @@
|
||||
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_6_label" aria-expanded="false">
|
||||
<label class="md-nav__title" for="__nav_6">
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
Chapter 5. Stack and Queue
|
||||
Chapter 5. Stack and queue
|
||||
</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
@@ -1368,7 +1374,7 @@
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
5.3 Double-ended Queue
|
||||
5.3 Double-ended queue
|
||||
</span>
|
||||
|
||||
|
||||
@@ -1447,7 +1453,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19.3 17.89c1.32-2.1.7-4.89-1.41-6.21a4.52 4.52 0 0 0-6.21 1.41C10.36 15.2 11 18 13.09 19.3c1.47.92 3.33.92 4.8 0L21 22.39 22.39 21l-3.09-3.11m-2-.62c-.98.98-2.56.97-3.54 0-.97-.98-.97-2.56.01-3.54.97-.97 2.55-.97 3.53 0 .96.99.95 2.57-.03 3.54h.03M19 4H5a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h5.81a6.3 6.3 0 0 1-1.31-2H5v-4h4.18c.16-.71.43-1.39.82-2H5V8h6v2.81a6.3 6.3 0 0 1 2-1.31V8h6v2a6.499 6.499 0 0 1 2 2V6a2 2 0 0 0-2-2Z"/></svg>
|
||||
|
||||
<span class="md-ellipsis">
|
||||
Chapter 6. Hash Table
|
||||
Chapter 6. Hash table
|
||||
</span>
|
||||
|
||||
|
||||
@@ -1463,7 +1469,7 @@
|
||||
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_7_label" aria-expanded="false">
|
||||
<label class="md-nav__title" for="__nav_7">
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
Chapter 6. Hash Table
|
||||
Chapter 6. Hash table
|
||||
</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
@@ -1480,7 +1486,7 @@
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
6.1 Hash Table
|
||||
6.1 Hash table
|
||||
</span>
|
||||
|
||||
|
||||
@@ -1501,7 +1507,7 @@
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
6.2 Hash Collision
|
||||
6.2 Hash collision
|
||||
</span>
|
||||
|
||||
|
||||
@@ -1522,7 +1528,7 @@
|
||||
|
||||
|
||||
<span class="md-ellipsis">
|
||||
6.3 Hash Algorithm
|
||||
6.3 Hash algorithm
|
||||
</span>
|
||||
|
||||
|
||||
@@ -2097,17 +2103,17 @@
|
||||
<li class="md-nav__item">
|
||||
<a href="#411-common-operations-on-arrays" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
4.1.1 Common Operations on Arrays
|
||||
4.1.1 Common operations on arrays
|
||||
</span>
|
||||
</a>
|
||||
|
||||
<nav class="md-nav" aria-label="4.1.1 Common Operations on Arrays">
|
||||
<nav class="md-nav" aria-label="4.1.1 Common operations on arrays">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#1-initializing-arrays" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
1. Initializing Arrays
|
||||
1. Initializing arrays
|
||||
</span>
|
||||
</a>
|
||||
|
||||
@@ -2116,7 +2122,7 @@
|
||||
<li class="md-nav__item">
|
||||
<a href="#2-accessing-elements" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
2. Accessing Elements
|
||||
2. Accessing elements
|
||||
</span>
|
||||
</a>
|
||||
|
||||
@@ -2125,7 +2131,7 @@
|
||||
<li class="md-nav__item">
|
||||
<a href="#3-inserting-elements" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
3. Inserting Elements
|
||||
3. Inserting elements
|
||||
</span>
|
||||
</a>
|
||||
|
||||
@@ -2134,7 +2140,7 @@
|
||||
<li class="md-nav__item">
|
||||
<a href="#4-deleting-elements" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
4. Deleting Elements
|
||||
4. Deleting elements
|
||||
</span>
|
||||
</a>
|
||||
|
||||
@@ -2143,7 +2149,7 @@
|
||||
<li class="md-nav__item">
|
||||
<a href="#5-traversing-arrays" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
5. Traversing Arrays
|
||||
5. Traversing arrays
|
||||
</span>
|
||||
</a>
|
||||
|
||||
@@ -2152,7 +2158,7 @@
|
||||
<li class="md-nav__item">
|
||||
<a href="#6-finding-elements" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
6. Finding Elements
|
||||
6. Finding elements
|
||||
</span>
|
||||
</a>
|
||||
|
||||
@@ -2161,7 +2167,7 @@
|
||||
<li class="md-nav__item">
|
||||
<a href="#7-expanding-arrays" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
7. Expanding Arrays
|
||||
7. Expanding arrays
|
||||
</span>
|
||||
</a>
|
||||
|
||||
@@ -2175,7 +2181,7 @@
|
||||
<li class="md-nav__item">
|
||||
<a href="#412-advantages-and-limitations-of-arrays" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
4.1.2 Advantages and Limitations of Arrays
|
||||
4.1.2 Advantages and limitations of arrays
|
||||
</span>
|
||||
</a>
|
||||
|
||||
@@ -2184,7 +2190,7 @@
|
||||
<li class="md-nav__item">
|
||||
<a href="#413-typical-applications-of-arrays" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
4.1.3 Typical Applications of Arrays
|
||||
4.1.3 Typical applications of arrays
|
||||
</span>
|
||||
</a>
|
||||
|
||||
@@ -2226,13 +2232,13 @@
|
||||
|
||||
|
||||
<!-- Page content -->
|
||||
<h1 id="41-arrays">4.1 Arrays<a class="headerlink" href="#41-arrays" title="Permanent link">¶</a></h1>
|
||||
<h1 id="41-array">4.1 Array<a class="headerlink" href="#41-array" title="Permanent link">¶</a></h1>
|
||||
<p>An "array" is a linear data structure that operates as a lineup of similar items, stored together in a computer's memory in contiguous spaces. It's like a sequence that maintains organized storage. Each item in this lineup has its unique 'spot' known as an "index". Please refer to the Figure 4-1 to observe how arrays work and grasp these key terms.</p>
|
||||
<p><a class="glightbox" href="../array.assets/array_definition.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="Array Definition and Storage Method" class="animation-figure" src="../array.assets/array_definition.png" /></a></p>
|
||||
<p align="center"> Figure 4-1 Array Definition and Storage Method </p>
|
||||
<p><a class="glightbox" href="../array.assets/array_definition.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="Array definition and storage method" class="animation-figure" src="../array.assets/array_definition.png" /></a></p>
|
||||
<p align="center"> Figure 4-1 Array definition and storage method </p>
|
||||
|
||||
<h2 id="411-common-operations-on-arrays">4.1.1 Common Operations on Arrays<a class="headerlink" href="#411-common-operations-on-arrays" title="Permanent link">¶</a></h2>
|
||||
<h3 id="1-initializing-arrays">1. Initializing Arrays<a class="headerlink" href="#1-initializing-arrays" title="Permanent link">¶</a></h3>
|
||||
<h2 id="411-common-operations-on-arrays">4.1.1 Common operations on arrays<a class="headerlink" href="#411-common-operations-on-arrays" title="Permanent link">¶</a></h2>
|
||||
<h3 id="1-initializing-arrays">1. Initializing arrays<a class="headerlink" href="#1-initializing-arrays" title="Permanent link">¶</a></h3>
|
||||
<p>Arrays can be initialized in two ways depending on the needs: either without initial values or with specified initial values. When initial values are not specified, most programming languages will set the array elements to <span class="arithmatex">\(0\)</span>:</p>
|
||||
<div class="tabbed-set tabbed-alternate" data-tabs="1:13"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><input id="__tabbed_1_3" name="__tabbed_1" type="radio" /><input id="__tabbed_1_4" name="__tabbed_1" type="radio" /><input id="__tabbed_1_5" name="__tabbed_1" type="radio" /><input id="__tabbed_1_6" name="__tabbed_1" type="radio" /><input id="__tabbed_1_7" name="__tabbed_1" type="radio" /><input id="__tabbed_1_8" name="__tabbed_1" type="radio" /><input id="__tabbed_1_9" name="__tabbed_1" type="radio" /><input id="__tabbed_1_10" name="__tabbed_1" type="radio" /><input id="__tabbed_1_11" name="__tabbed_1" type="radio" /><input id="__tabbed_1_12" name="__tabbed_1" type="radio" /><input id="__tabbed_1_13" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Python</label><label for="__tabbed_1_2">C++</label><label for="__tabbed_1_3">Java</label><label for="__tabbed_1_4">C#</label><label for="__tabbed_1_5">Go</label><label for="__tabbed_1_6">Swift</label><label for="__tabbed_1_7">JS</label><label for="__tabbed_1_8">TS</label><label for="__tabbed_1_9">Dart</label><label for="__tabbed_1_10">Rust</label><label for="__tabbed_1_11">C</label><label for="__tabbed_1_12">Kotlin</label><label for="__tabbed_1_13">Zig</label></div>
|
||||
<div class="tabbed-content">
|
||||
@@ -2321,10 +2327,10 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h3 id="2-accessing-elements">2. Accessing Elements<a class="headerlink" href="#2-accessing-elements" title="Permanent link">¶</a></h3>
|
||||
<h3 id="2-accessing-elements">2. Accessing elements<a class="headerlink" href="#2-accessing-elements" title="Permanent link">¶</a></h3>
|
||||
<p>Elements in an array are stored in contiguous memory spaces, making it simpler to compute each element's memory address. The formula shown in the Figure below aids in determining an element's memory address, utilizing the array's memory address (specifically, the first element's address) and the element's index. This computation streamlines direct access to the desired element.</p>
|
||||
<p><a class="glightbox" href="../array.assets/array_memory_location_calculation.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="Memory Address Calculation for Array Elements" class="animation-figure" src="../array.assets/array_memory_location_calculation.png" /></a></p>
|
||||
<p align="center"> Figure 4-2 Memory Address Calculation for Array Elements </p>
|
||||
<p><a class="glightbox" href="../array.assets/array_memory_location_calculation.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="Memory address calculation for array elements" class="animation-figure" src="../array.assets/array_memory_location_calculation.png" /></a></p>
|
||||
<p align="center"> Figure 4-2 Memory address calculation for array elements </p>
|
||||
|
||||
<p>As observed in the above illustration, array indexing conventionally begins at <span class="arithmatex">\(0\)</span>. While this might appear counterintuitive, considering counting usually starts at <span class="arithmatex">\(1\)</span>, within the address calculation formula, <strong>an index is essentially an offset from the memory address</strong>. For the first element's address, this offset is <span class="arithmatex">\(0\)</span>, validating its index as <span class="arithmatex">\(0\)</span>.</p>
|
||||
<p>Accessing elements in an array is highly efficient, allowing us to randomly access any element in <span class="arithmatex">\(O(1)\)</span> time.</p>
|
||||
@@ -2491,10 +2497,10 @@
|
||||
<p><div style="height: 531px; width: 100%;"><iframe class="pythontutor-iframe" src="https://pythontutor.com/iframe-embed.html#code=import%20random%0A%0Adef%20random_access%28nums%3A%20list%5Bint%5D%29%20-%3E%20int%3A%0A%20%20%20%20%22%22%22%E9%9A%8F%E6%9C%BA%E8%AE%BF%E9%97%AE%E5%85%83%E7%B4%A0%22%22%22%0A%20%20%20%20%23%20%E5%9C%A8%E5%8C%BA%E9%97%B4%20%5B0,%20len%28nums%29-1%5D%20%E4%B8%AD%E9%9A%8F%E6%9C%BA%E6%8A%BD%E5%8F%96%E4%B8%80%E4%B8%AA%E6%95%B0%E5%AD%97%0A%20%20%20%20random_index%20%3D%20random.randint%280,%20len%28nums%29%20-%201%29%0A%20%20%20%20%23%20%E8%8E%B7%E5%8F%96%E5%B9%B6%E8%BF%94%E5%9B%9E%E9%9A%8F%E6%9C%BA%E5%85%83%E7%B4%A0%0A%20%20%20%20random_num%20%3D%20nums%5Brandom_index%5D%0A%20%20%20%20return%20random_num%0A%0A%22%22%22Driver%20Code%22%22%22%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20%23%20%E5%88%9D%E5%A7%8B%E5%8C%96%E6%95%B0%E7%BB%84%0A%20%20%20%20nums%20%3D%20%5B1,%203,%202,%205,%204%5D%0A%20%20%20%20print%28%22%E6%95%B0%E7%BB%84%20nums%20%3D%22,%20nums%29%0A%0A%20%20%20%20%23%20%E9%9A%8F%E6%9C%BA%E8%AE%BF%E9%97%AE%0A%20%20%20%20random_num%3A%20int%20%3D%20random_access%28nums%29%0A%20%20%20%20print%28%22%E5%9C%A8%20nums%20%E4%B8%AD%E8%8E%B7%E5%8F%96%E9%9A%8F%E6%9C%BA%E5%85%83%E7%B4%A0%22,%20random_num%29%0A&codeDivHeight=472&codeDivWidth=350&cumulative=false&curInstr=7&heapPrimitives=nevernest&origin=opt-frontend.js&py=311&rawInputLstJSON=%5B%5D&textReferences=false"> </iframe></div>
|
||||
<div style="margin-top: 5px;"><a href="https://pythontutor.com/iframe-embed.html#code=import%20random%0A%0Adef%20random_access%28nums%3A%20list%5Bint%5D%29%20-%3E%20int%3A%0A%20%20%20%20%22%22%22%E9%9A%8F%E6%9C%BA%E8%AE%BF%E9%97%AE%E5%85%83%E7%B4%A0%22%22%22%0A%20%20%20%20%23%20%E5%9C%A8%E5%8C%BA%E9%97%B4%20%5B0,%20len%28nums%29-1%5D%20%E4%B8%AD%E9%9A%8F%E6%9C%BA%E6%8A%BD%E5%8F%96%E4%B8%80%E4%B8%AA%E6%95%B0%E5%AD%97%0A%20%20%20%20random_index%20%3D%20random.randint%280,%20len%28nums%29%20-%201%29%0A%20%20%20%20%23%20%E8%8E%B7%E5%8F%96%E5%B9%B6%E8%BF%94%E5%9B%9E%E9%9A%8F%E6%9C%BA%E5%85%83%E7%B4%A0%0A%20%20%20%20random_num%20%3D%20nums%5Brandom_index%5D%0A%20%20%20%20return%20random_num%0A%0A%22%22%22Driver%20Code%22%22%22%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20%23%20%E5%88%9D%E5%A7%8B%E5%8C%96%E6%95%B0%E7%BB%84%0A%20%20%20%20nums%20%3D%20%5B1,%203,%202,%205,%204%5D%0A%20%20%20%20print%28%22%E6%95%B0%E7%BB%84%20nums%20%3D%22,%20nums%29%0A%0A%20%20%20%20%23%20%E9%9A%8F%E6%9C%BA%E8%AE%BF%E9%97%AE%0A%20%20%20%20random_num%3A%20int%20%3D%20random_access%28nums%29%0A%20%20%20%20print%28%22%E5%9C%A8%20nums%20%E4%B8%AD%E8%8E%B7%E5%8F%96%E9%9A%8F%E6%9C%BA%E5%85%83%E7%B4%A0%22,%20random_num%29%0A&codeDivHeight=800&codeDivWidth=600&cumulative=false&curInstr=7&heapPrimitives=nevernest&origin=opt-frontend.js&py=311&rawInputLstJSON=%5B%5D&textReferences=false" target="_blank" rel="noopener noreferrer">Full Screen ></a></div></p>
|
||||
</details>
|
||||
<h3 id="3-inserting-elements">3. Inserting Elements<a class="headerlink" href="#3-inserting-elements" title="Permanent link">¶</a></h3>
|
||||
<h3 id="3-inserting-elements">3. Inserting elements<a class="headerlink" href="#3-inserting-elements" title="Permanent link">¶</a></h3>
|
||||
<p>Array elements are tightly packed in memory, with no space available to accommodate additional data between them. Illustrated in Figure below, inserting an element in the middle of an array requires shifting all subsequent elements back by one position to create room for the new element.</p>
|
||||
<p><a class="glightbox" href="../array.assets/array_insert_element.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="Array Element Insertion Example" class="animation-figure" src="../array.assets/array_insert_element.png" /></a></p>
|
||||
<p align="center"> Figure 4-3 Array Element Insertion Example </p>
|
||||
<p><a class="glightbox" href="../array.assets/array_insert_element.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="Array element insertion example" class="animation-figure" src="../array.assets/array_insert_element.png" /></a></p>
|
||||
<p align="center"> Figure 4-3 Array element insertion example </p>
|
||||
|
||||
<p>It's important to note that due to the fixed length of an array, inserting an element will unavoidably result in the loss of the last element in the array. Solutions to address this issue will be explored in the "List" chapter.</p>
|
||||
<div class="tabbed-set tabbed-alternate" data-tabs="3:14"><input checked="checked" id="__tabbed_3_1" name="__tabbed_3" type="radio" /><input id="__tabbed_3_2" name="__tabbed_3" type="radio" /><input id="__tabbed_3_3" name="__tabbed_3" type="radio" /><input id="__tabbed_3_4" name="__tabbed_3" type="radio" /><input id="__tabbed_3_5" name="__tabbed_3" type="radio" /><input id="__tabbed_3_6" name="__tabbed_3" type="radio" /><input id="__tabbed_3_7" name="__tabbed_3" type="radio" /><input id="__tabbed_3_8" name="__tabbed_3" type="radio" /><input id="__tabbed_3_9" name="__tabbed_3" type="radio" /><input id="__tabbed_3_10" name="__tabbed_3" type="radio" /><input id="__tabbed_3_11" name="__tabbed_3" type="radio" /><input id="__tabbed_3_12" name="__tabbed_3" type="radio" /><input id="__tabbed_3_13" name="__tabbed_3" type="radio" /><input id="__tabbed_3_14" name="__tabbed_3" type="radio" /><div class="tabbed-labels"><label for="__tabbed_3_1">Python</label><label for="__tabbed_3_2">C++</label><label for="__tabbed_3_3">Java</label><label for="__tabbed_3_4">C#</label><label for="__tabbed_3_5">Go</label><label for="__tabbed_3_6">Swift</label><label for="__tabbed_3_7">JS</label><label for="__tabbed_3_8">TS</label><label for="__tabbed_3_9">Dart</label><label for="__tabbed_3_10">Rust</label><label for="__tabbed_3_11">C</label><label for="__tabbed_3_12">Kotlin</label><label for="__tabbed_3_13">Ruby</label><label for="__tabbed_3_14">Zig</label></div>
|
||||
@@ -2674,10 +2680,10 @@
|
||||
<p><div style="height: 495px; width: 100%;"><iframe class="pythontutor-iframe" src="https://pythontutor.com/iframe-embed.html#code=def%20insert%28nums%3A%20list%5Bint%5D,%20num%3A%20int,%20index%3A%20int%29%3A%0A%20%20%20%20%22%22%22%E5%9C%A8%E6%95%B0%E7%BB%84%E7%9A%84%E7%B4%A2%E5%BC%95%20index%20%E5%A4%84%E6%8F%92%E5%85%A5%E5%85%83%E7%B4%A0%20num%22%22%22%0A%20%20%20%20%23%20%E6%8A%8A%E7%B4%A2%E5%BC%95%20index%20%E4%BB%A5%E5%8F%8A%E4%B9%8B%E5%90%8E%E7%9A%84%E6%89%80%E6%9C%89%E5%85%83%E7%B4%A0%E5%90%91%E5%90%8E%E7%A7%BB%E5%8A%A8%E4%B8%80%E4%BD%8D%0A%20%20%20%20for%20i%20in%20range%28len%28nums%29%20-%201,%20index,%20-1%29%3A%0A%20%20%20%20%20%20%20%20nums%5Bi%5D%20%3D%20nums%5Bi%20-%201%5D%0A%20%20%20%20%23%20%E5%B0%86%20num%20%E8%B5%8B%E7%BB%99%20index%20%E5%A4%84%E7%9A%84%E5%85%83%E7%B4%A0%0A%20%20%20%20nums%5Bindex%5D%20%3D%20num%0A%0A%22%22%22Driver%20Code%22%22%22%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20%23%20%E5%88%9D%E5%A7%8B%E5%8C%96%E6%95%B0%E7%BB%84%0A%20%20%20%20nums%20%3D%20%5B1,%203,%202,%205,%204%5D%0A%20%20%20%20print%28%22%E6%95%B0%E7%BB%84%20nums%20%3D%22,%20nums%29%0A%0A%20%20%20%20%23%20%E6%8F%92%E5%85%A5%E5%85%83%E7%B4%A0%0A%20%20%20%20insert%28nums,%206,%203%29%0A%20%20%20%20print%28%22%E5%9C%A8%E7%B4%A2%E5%BC%95%203%20%E5%A4%84%E6%8F%92%E5%85%A5%E6%95%B0%E5%AD%97%206%20%EF%BC%8C%E5%BE%97%E5%88%B0%20nums%20%3D%22,%20nums%29&codeDivHeight=472&codeDivWidth=350&cumulative=false&curInstr=6&heapPrimitives=nevernest&origin=opt-frontend.js&py=311&rawInputLstJSON=%5B%5D&textReferences=false"> </iframe></div>
|
||||
<div style="margin-top: 5px;"><a href="https://pythontutor.com/iframe-embed.html#code=def%20insert%28nums%3A%20list%5Bint%5D,%20num%3A%20int,%20index%3A%20int%29%3A%0A%20%20%20%20%22%22%22%E5%9C%A8%E6%95%B0%E7%BB%84%E7%9A%84%E7%B4%A2%E5%BC%95%20index%20%E5%A4%84%E6%8F%92%E5%85%A5%E5%85%83%E7%B4%A0%20num%22%22%22%0A%20%20%20%20%23%20%E6%8A%8A%E7%B4%A2%E5%BC%95%20index%20%E4%BB%A5%E5%8F%8A%E4%B9%8B%E5%90%8E%E7%9A%84%E6%89%80%E6%9C%89%E5%85%83%E7%B4%A0%E5%90%91%E5%90%8E%E7%A7%BB%E5%8A%A8%E4%B8%80%E4%BD%8D%0A%20%20%20%20for%20i%20in%20range%28len%28nums%29%20-%201,%20index,%20-1%29%3A%0A%20%20%20%20%20%20%20%20nums%5Bi%5D%20%3D%20nums%5Bi%20-%201%5D%0A%20%20%20%20%23%20%E5%B0%86%20num%20%E8%B5%8B%E7%BB%99%20index%20%E5%A4%84%E7%9A%84%E5%85%83%E7%B4%A0%0A%20%20%20%20nums%5Bindex%5D%20%3D%20num%0A%0A%22%22%22Driver%20Code%22%22%22%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20%23%20%E5%88%9D%E5%A7%8B%E5%8C%96%E6%95%B0%E7%BB%84%0A%20%20%20%20nums%20%3D%20%5B1,%203,%202,%205,%204%5D%0A%20%20%20%20print%28%22%E6%95%B0%E7%BB%84%20nums%20%3D%22,%20nums%29%0A%0A%20%20%20%20%23%20%E6%8F%92%E5%85%A5%E5%85%83%E7%B4%A0%0A%20%20%20%20insert%28nums,%206,%203%29%0A%20%20%20%20print%28%22%E5%9C%A8%E7%B4%A2%E5%BC%95%203%20%E5%A4%84%E6%8F%92%E5%85%A5%E6%95%B0%E5%AD%97%206%20%EF%BC%8C%E5%BE%97%E5%88%B0%20nums%20%3D%22,%20nums%29&codeDivHeight=800&codeDivWidth=600&cumulative=false&curInstr=6&heapPrimitives=nevernest&origin=opt-frontend.js&py=311&rawInputLstJSON=%5B%5D&textReferences=false" target="_blank" rel="noopener noreferrer">Full Screen ></a></div></p>
|
||||
</details>
|
||||
<h3 id="4-deleting-elements">4. Deleting Elements<a class="headerlink" href="#4-deleting-elements" title="Permanent link">¶</a></h3>
|
||||
<h3 id="4-deleting-elements">4. Deleting elements<a class="headerlink" href="#4-deleting-elements" title="Permanent link">¶</a></h3>
|
||||
<p>Similarly, as depicted in the Figure 4-4 , to delete an element at index <span class="arithmatex">\(i\)</span>, all elements following index <span class="arithmatex">\(i\)</span> must be moved forward by one position.</p>
|
||||
<p><a class="glightbox" href="../array.assets/array_remove_element.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="Array Element Deletion Example" class="animation-figure" src="../array.assets/array_remove_element.png" /></a></p>
|
||||
<p align="center"> Figure 4-4 Array Element Deletion Example </p>
|
||||
<p><a class="glightbox" href="../array.assets/array_remove_element.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="Array element deletion example" class="animation-figure" src="../array.assets/array_remove_element.png" /></a></p>
|
||||
<p align="center"> Figure 4-4 Array element deletion example </p>
|
||||
|
||||
<p>Please note that after deletion, the former last element becomes "meaningless," hence requiring no specific modification.</p>
|
||||
<div class="tabbed-set tabbed-alternate" data-tabs="4:14"><input checked="checked" id="__tabbed_4_1" name="__tabbed_4" type="radio" /><input id="__tabbed_4_2" name="__tabbed_4" type="radio" /><input id="__tabbed_4_3" name="__tabbed_4" type="radio" /><input id="__tabbed_4_4" name="__tabbed_4" type="radio" /><input id="__tabbed_4_5" name="__tabbed_4" type="radio" /><input id="__tabbed_4_6" name="__tabbed_4" type="radio" /><input id="__tabbed_4_7" name="__tabbed_4" type="radio" /><input id="__tabbed_4_8" name="__tabbed_4" type="radio" /><input id="__tabbed_4_9" name="__tabbed_4" type="radio" /><input id="__tabbed_4_10" name="__tabbed_4" type="radio" /><input id="__tabbed_4_11" name="__tabbed_4" type="radio" /><input id="__tabbed_4_12" name="__tabbed_4" type="radio" /><input id="__tabbed_4_13" name="__tabbed_4" type="radio" /><input id="__tabbed_4_14" name="__tabbed_4" type="radio" /><div class="tabbed-labels"><label for="__tabbed_4_1">Python</label><label for="__tabbed_4_2">C++</label><label for="__tabbed_4_3">Java</label><label for="__tabbed_4_4">C#</label><label for="__tabbed_4_5">Go</label><label for="__tabbed_4_6">Swift</label><label for="__tabbed_4_7">JS</label><label for="__tabbed_4_8">TS</label><label for="__tabbed_4_9">Dart</label><label for="__tabbed_4_10">Rust</label><label for="__tabbed_4_11">C</label><label for="__tabbed_4_12">Kotlin</label><label for="__tabbed_4_13">Ruby</label><label for="__tabbed_4_14">Zig</label></div>
|
||||
@@ -2831,11 +2837,11 @@
|
||||
</details>
|
||||
<p>In summary, the insertion and deletion operations in arrays present the following disadvantages:</p>
|
||||
<ul>
|
||||
<li><strong>High Time Complexity</strong>: Both insertion and deletion in an array have an average time complexity of <span class="arithmatex">\(O(n)\)</span>, where <span class="arithmatex">\(n\)</span> is the length of the array.</li>
|
||||
<li><strong>Loss of Elements</strong>: Due to the fixed length of arrays, elements that exceed the array's capacity are lost during insertion.</li>
|
||||
<li><strong>Waste of Memory</strong>: Initializing a longer array and utilizing only the front part results in "meaningless" end elements during insertion, leading to some wasted memory space.</li>
|
||||
<li><strong>High time complexity</strong>: Both insertion and deletion in an array have an average time complexity of <span class="arithmatex">\(O(n)\)</span>, where <span class="arithmatex">\(n\)</span> is the length of the array.</li>
|
||||
<li><strong>Loss of elements</strong>: Due to the fixed length of arrays, elements that exceed the array's capacity are lost during insertion.</li>
|
||||
<li><strong>Waste of memory</strong>: Initializing a longer array and utilizing only the front part results in "meaningless" end elements during insertion, leading to some wasted memory space.</li>
|
||||
</ul>
|
||||
<h3 id="5-traversing-arrays">5. Traversing Arrays<a class="headerlink" href="#5-traversing-arrays" title="Permanent link">¶</a></h3>
|
||||
<h3 id="5-traversing-arrays">5. Traversing arrays<a class="headerlink" href="#5-traversing-arrays" title="Permanent link">¶</a></h3>
|
||||
<p>In most programming languages, we can traverse an array either by using indices or by directly iterating over each element:</p>
|
||||
<div class="tabbed-set tabbed-alternate" data-tabs="5:14"><input checked="checked" id="__tabbed_5_1" name="__tabbed_5" type="radio" /><input id="__tabbed_5_2" name="__tabbed_5" type="radio" /><input id="__tabbed_5_3" name="__tabbed_5" type="radio" /><input id="__tabbed_5_4" name="__tabbed_5" type="radio" /><input id="__tabbed_5_5" name="__tabbed_5" type="radio" /><input id="__tabbed_5_6" name="__tabbed_5" type="radio" /><input id="__tabbed_5_7" name="__tabbed_5" type="radio" /><input id="__tabbed_5_8" name="__tabbed_5" type="radio" /><input id="__tabbed_5_9" name="__tabbed_5" type="radio" /><input id="__tabbed_5_10" name="__tabbed_5" type="radio" /><input id="__tabbed_5_11" name="__tabbed_5" type="radio" /><input id="__tabbed_5_12" name="__tabbed_5" type="radio" /><input id="__tabbed_5_13" name="__tabbed_5" type="radio" /><input id="__tabbed_5_14" name="__tabbed_5" type="radio" /><div class="tabbed-labels"><label for="__tabbed_5_1">Python</label><label for="__tabbed_5_2">C++</label><label for="__tabbed_5_3">Java</label><label for="__tabbed_5_4">C#</label><label for="__tabbed_5_5">Go</label><label for="__tabbed_5_6">Swift</label><label for="__tabbed_5_7">JS</label><label for="__tabbed_5_8">TS</label><label for="__tabbed_5_9">Dart</label><label for="__tabbed_5_10">Rust</label><label for="__tabbed_5_11">C</label><label for="__tabbed_5_12">Kotlin</label><label for="__tabbed_5_13">Ruby</label><label for="__tabbed_5_14">Zig</label></div>
|
||||
<div class="tabbed-content">
|
||||
@@ -3068,7 +3074,7 @@
|
||||
<p><div style="height: 549px; width: 100%;"><iframe class="pythontutor-iframe" src="https://pythontutor.com/iframe-embed.html#code=def%20traverse%28nums%3A%20list%5Bint%5D%29%3A%0A%20%20%20%20%22%22%22%E9%81%8D%E5%8E%86%E6%95%B0%E7%BB%84%22%22%22%0A%20%20%20%20count%20%3D%200%0A%20%20%20%20%23%20%E9%80%9A%E8%BF%87%E7%B4%A2%E5%BC%95%E9%81%8D%E5%8E%86%E6%95%B0%E7%BB%84%0A%20%20%20%20for%20i%20in%20range%28len%28nums%29%29%3A%0A%20%20%20%20%20%20%20%20count%20%2B%3D%20nums%5Bi%5D%0A%20%20%20%20%23%20%E7%9B%B4%E6%8E%A5%E9%81%8D%E5%8E%86%E6%95%B0%E7%BB%84%E5%85%83%E7%B4%A0%0A%20%20%20%20for%20num%20in%20nums%3A%0A%20%20%20%20%20%20%20%20count%20%2B%3D%20num%0A%20%20%20%20%23%20%E5%90%8C%E6%97%B6%E9%81%8D%E5%8E%86%E6%95%B0%E6%8D%AE%E7%B4%A2%E5%BC%95%E5%92%8C%E5%85%83%E7%B4%A0%0A%20%20%20%20for%20i,%20num%20in%20enumerate%28nums%29%3A%0A%20%20%20%20%20%20%20%20count%20%2B%3D%20nums%5Bi%5D%0A%20%20%20%20%20%20%20%20count%20%2B%3D%20num%0A%0A%22%22%22Driver%20Code%22%22%22%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20%23%20%E5%88%9D%E5%A7%8B%E5%8C%96%E6%95%B0%E7%BB%84%0A%20%20%20%20nums%20%3D%20%5B1,%203,%202,%205,%204%5D%0A%20%20%20%20print%28%22%E6%95%B0%E7%BB%84%20nums%20%3D%22,%20nums%29%0A%0A%20%20%20%20%23%20%E9%81%8D%E5%8E%86%E6%95%B0%E7%BB%84%0A%20%20%20%20traverse%28nums%29&codeDivHeight=472&codeDivWidth=350&cumulative=false&curInstr=6&heapPrimitives=nevernest&origin=opt-frontend.js&py=311&rawInputLstJSON=%5B%5D&textReferences=false"> </iframe></div>
|
||||
<div style="margin-top: 5px;"><a href="https://pythontutor.com/iframe-embed.html#code=def%20traverse%28nums%3A%20list%5Bint%5D%29%3A%0A%20%20%20%20%22%22%22%E9%81%8D%E5%8E%86%E6%95%B0%E7%BB%84%22%22%22%0A%20%20%20%20count%20%3D%200%0A%20%20%20%20%23%20%E9%80%9A%E8%BF%87%E7%B4%A2%E5%BC%95%E9%81%8D%E5%8E%86%E6%95%B0%E7%BB%84%0A%20%20%20%20for%20i%20in%20range%28len%28nums%29%29%3A%0A%20%20%20%20%20%20%20%20count%20%2B%3D%20nums%5Bi%5D%0A%20%20%20%20%23%20%E7%9B%B4%E6%8E%A5%E9%81%8D%E5%8E%86%E6%95%B0%E7%BB%84%E5%85%83%E7%B4%A0%0A%20%20%20%20for%20num%20in%20nums%3A%0A%20%20%20%20%20%20%20%20count%20%2B%3D%20num%0A%20%20%20%20%23%20%E5%90%8C%E6%97%B6%E9%81%8D%E5%8E%86%E6%95%B0%E6%8D%AE%E7%B4%A2%E5%BC%95%E5%92%8C%E5%85%83%E7%B4%A0%0A%20%20%20%20for%20i,%20num%20in%20enumerate%28nums%29%3A%0A%20%20%20%20%20%20%20%20count%20%2B%3D%20nums%5Bi%5D%0A%20%20%20%20%20%20%20%20count%20%2B%3D%20num%0A%0A%22%22%22Driver%20Code%22%22%22%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20%23%20%E5%88%9D%E5%A7%8B%E5%8C%96%E6%95%B0%E7%BB%84%0A%20%20%20%20nums%20%3D%20%5B1,%203,%202,%205,%204%5D%0A%20%20%20%20print%28%22%E6%95%B0%E7%BB%84%20nums%20%3D%22,%20nums%29%0A%0A%20%20%20%20%23%20%E9%81%8D%E5%8E%86%E6%95%B0%E7%BB%84%0A%20%20%20%20traverse%28nums%29&codeDivHeight=800&codeDivWidth=600&cumulative=false&curInstr=6&heapPrimitives=nevernest&origin=opt-frontend.js&py=311&rawInputLstJSON=%5B%5D&textReferences=false" target="_blank" rel="noopener noreferrer">Full Screen ></a></div></p>
|
||||
</details>
|
||||
<h3 id="6-finding-elements">6. Finding Elements<a class="headerlink" href="#6-finding-elements" title="Permanent link">¶</a></h3>
|
||||
<h3 id="6-finding-elements">6. Finding elements<a class="headerlink" href="#6-finding-elements" title="Permanent link">¶</a></h3>
|
||||
<p>Locating a specific element within an array involves iterating through the array, checking each element to determine if it matches the desired value.</p>
|
||||
<p>Because arrays are linear data structures, this operation is commonly referred to as "linear search."</p>
|
||||
<div class="tabbed-set tabbed-alternate" data-tabs="6:14"><input checked="checked" id="__tabbed_6_1" name="__tabbed_6" type="radio" /><input id="__tabbed_6_2" name="__tabbed_6" type="radio" /><input id="__tabbed_6_3" name="__tabbed_6" type="radio" /><input id="__tabbed_6_4" name="__tabbed_6" type="radio" /><input id="__tabbed_6_5" name="__tabbed_6" type="radio" /><input id="__tabbed_6_6" name="__tabbed_6" type="radio" /><input id="__tabbed_6_7" name="__tabbed_6" type="radio" /><input id="__tabbed_6_8" name="__tabbed_6" type="radio" /><input id="__tabbed_6_9" name="__tabbed_6" type="radio" /><input id="__tabbed_6_10" name="__tabbed_6" type="radio" /><input id="__tabbed_6_11" name="__tabbed_6" type="radio" /><input id="__tabbed_6_12" name="__tabbed_6" type="radio" /><input id="__tabbed_6_13" name="__tabbed_6" type="radio" /><input id="__tabbed_6_14" name="__tabbed_6" type="radio" /><div class="tabbed-labels"><label for="__tabbed_6_1">Python</label><label for="__tabbed_6_2">C++</label><label for="__tabbed_6_3">Java</label><label for="__tabbed_6_4">C#</label><label for="__tabbed_6_5">Go</label><label for="__tabbed_6_6">Swift</label><label for="__tabbed_6_7">JS</label><label for="__tabbed_6_8">TS</label><label for="__tabbed_6_9">Dart</label><label for="__tabbed_6_10">Rust</label><label for="__tabbed_6_11">C</label><label for="__tabbed_6_12">Kotlin</label><label for="__tabbed_6_13">Ruby</label><label for="__tabbed_6_14">Zig</label></div>
|
||||
@@ -3234,7 +3240,7 @@
|
||||
<p><div style="height: 477px; width: 100%;"><iframe class="pythontutor-iframe" src="https://pythontutor.com/iframe-embed.html#code=def%20find%28nums%3A%20list%5Bint%5D,%20target%3A%20int%29%20-%3E%20int%3A%0A%20%20%20%20%22%22%22%E5%9C%A8%E6%95%B0%E7%BB%84%E4%B8%AD%E6%9F%A5%E6%89%BE%E6%8C%87%E5%AE%9A%E5%85%83%E7%B4%A0%22%22%22%0A%20%20%20%20for%20i%20in%20range%28len%28nums%29%29%3A%0A%20%20%20%20%20%20%20%20if%20nums%5Bi%5D%20%3D%3D%20target%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20i%0A%20%20%20%20return%20-1%0A%0A%22%22%22Driver%20Code%22%22%22%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20%23%20%E5%88%9D%E5%A7%8B%E5%8C%96%E6%95%B0%E7%BB%84%0A%20%20%20%20nums%20%3D%20%5B1,%203,%202,%205,%204%5D%0A%20%20%20%20print%28%22%E6%95%B0%E7%BB%84%20nums%20%3D%22,%20nums%29%0A%0A%20%20%20%20%23%20%E6%9F%A5%E6%89%BE%E5%85%83%E7%B4%A0%0A%20%20%20%20index%3A%20int%20%3D%20find%28nums,%203%29%0A%20%20%20%20print%28%22%E5%9C%A8%20nums%20%E4%B8%AD%E6%9F%A5%E6%89%BE%E5%85%83%E7%B4%A0%203%20%EF%BC%8C%E5%BE%97%E5%88%B0%E7%B4%A2%E5%BC%95%20%3D%22,%20index%29&codeDivHeight=472&codeDivWidth=350&cumulative=false&curInstr=6&heapPrimitives=nevernest&origin=opt-frontend.js&py=311&rawInputLstJSON=%5B%5D&textReferences=false"> </iframe></div>
|
||||
<div style="margin-top: 5px;"><a href="https://pythontutor.com/iframe-embed.html#code=def%20find%28nums%3A%20list%5Bint%5D,%20target%3A%20int%29%20-%3E%20int%3A%0A%20%20%20%20%22%22%22%E5%9C%A8%E6%95%B0%E7%BB%84%E4%B8%AD%E6%9F%A5%E6%89%BE%E6%8C%87%E5%AE%9A%E5%85%83%E7%B4%A0%22%22%22%0A%20%20%20%20for%20i%20in%20range%28len%28nums%29%29%3A%0A%20%20%20%20%20%20%20%20if%20nums%5Bi%5D%20%3D%3D%20target%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20i%0A%20%20%20%20return%20-1%0A%0A%22%22%22Driver%20Code%22%22%22%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20%23%20%E5%88%9D%E5%A7%8B%E5%8C%96%E6%95%B0%E7%BB%84%0A%20%20%20%20nums%20%3D%20%5B1,%203,%202,%205,%204%5D%0A%20%20%20%20print%28%22%E6%95%B0%E7%BB%84%20nums%20%3D%22,%20nums%29%0A%0A%20%20%20%20%23%20%E6%9F%A5%E6%89%BE%E5%85%83%E7%B4%A0%0A%20%20%20%20index%3A%20int%20%3D%20find%28nums,%203%29%0A%20%20%20%20print%28%22%E5%9C%A8%20nums%20%E4%B8%AD%E6%9F%A5%E6%89%BE%E5%85%83%E7%B4%A0%203%20%EF%BC%8C%E5%BE%97%E5%88%B0%E7%B4%A2%E5%BC%95%20%3D%22,%20index%29&codeDivHeight=800&codeDivWidth=600&cumulative=false&curInstr=6&heapPrimitives=nevernest&origin=opt-frontend.js&py=311&rawInputLstJSON=%5B%5D&textReferences=false" target="_blank" rel="noopener noreferrer">Full Screen ></a></div></p>
|
||||
</details>
|
||||
<h3 id="7-expanding-arrays">7. Expanding Arrays<a class="headerlink" href="#7-expanding-arrays" title="Permanent link">¶</a></h3>
|
||||
<h3 id="7-expanding-arrays">7. Expanding arrays<a class="headerlink" href="#7-expanding-arrays" title="Permanent link">¶</a></h3>
|
||||
<p>In complex system environments, ensuring the availability of memory space after an array for safe capacity extension becomes challenging. Consequently, in most programming languages, <strong>the length of an array is immutable</strong>.</p>
|
||||
<p>To expand an array, it's necessary to create a larger array and then copy the elements from the original array. This operation has a time complexity of <span class="arithmatex">\(O(n)\)</span> and can be time-consuming for large arrays. The code are as follows:</p>
|
||||
<div class="tabbed-set tabbed-alternate" data-tabs="7:14"><input checked="checked" id="__tabbed_7_1" name="__tabbed_7" type="radio" /><input id="__tabbed_7_2" name="__tabbed_7" type="radio" /><input id="__tabbed_7_3" name="__tabbed_7" type="radio" /><input id="__tabbed_7_4" name="__tabbed_7" type="radio" /><input id="__tabbed_7_5" name="__tabbed_7" type="radio" /><input id="__tabbed_7_6" name="__tabbed_7" type="radio" /><input id="__tabbed_7_7" name="__tabbed_7" type="radio" /><input id="__tabbed_7_8" name="__tabbed_7" type="radio" /><input id="__tabbed_7_9" name="__tabbed_7" type="radio" /><input id="__tabbed_7_10" name="__tabbed_7" type="radio" /><input id="__tabbed_7_11" name="__tabbed_7" type="radio" /><input id="__tabbed_7_12" name="__tabbed_7" type="radio" /><input id="__tabbed_7_13" name="__tabbed_7" type="radio" /><input id="__tabbed_7_14" name="__tabbed_7" type="radio" /><div class="tabbed-labels"><label for="__tabbed_7_1">Python</label><label for="__tabbed_7_2">C++</label><label for="__tabbed_7_3">Java</label><label for="__tabbed_7_4">C#</label><label for="__tabbed_7_5">Go</label><label for="__tabbed_7_6">Swift</label><label for="__tabbed_7_7">JS</label><label for="__tabbed_7_8">TS</label><label for="__tabbed_7_9">Dart</label><label for="__tabbed_7_10">Rust</label><label for="__tabbed_7_11">C</label><label for="__tabbed_7_12">Kotlin</label><label for="__tabbed_7_13">Ruby</label><label for="__tabbed_7_14">Zig</label></div>
|
||||
@@ -3453,27 +3459,27 @@
|
||||
<p><div style="height: 549px; width: 100%;"><iframe class="pythontutor-iframe" src="https://pythontutor.com/iframe-embed.html#code=%23%20%E8%AF%B7%E6%B3%A8%E6%84%8F%EF%BC%8CPython%20%E7%9A%84%20list%20%E6%98%AF%E5%8A%A8%E6%80%81%E6%95%B0%E7%BB%84%EF%BC%8C%E5%8F%AF%E4%BB%A5%E7%9B%B4%E6%8E%A5%E6%89%A9%E5%B1%95%0A%23%20%E4%B8%BA%E4%BA%86%E6%96%B9%E4%BE%BF%E5%AD%A6%E4%B9%A0%EF%BC%8C%E6%9C%AC%E5%87%BD%E6%95%B0%E5%B0%86%20list%20%E7%9C%8B%E4%BD%9C%E9%95%BF%E5%BA%A6%E4%B8%8D%E5%8F%AF%E5%8F%98%E7%9A%84%E6%95%B0%E7%BB%84%0Adef%20extend%28nums%3A%20list%5Bint%5D,%20enlarge%3A%20int%29%20-%3E%20list%5Bint%5D%3A%0A%20%20%20%20%22%22%22%E6%89%A9%E5%B1%95%E6%95%B0%E7%BB%84%E9%95%BF%E5%BA%A6%22%22%22%0A%20%20%20%20%23%20%E5%88%9D%E5%A7%8B%E5%8C%96%E4%B8%80%E4%B8%AA%E6%89%A9%E5%B1%95%E9%95%BF%E5%BA%A6%E5%90%8E%E7%9A%84%E6%95%B0%E7%BB%84%0A%20%20%20%20res%20%3D%20%5B0%5D%20*%20%28len%28nums%29%20%2B%20enlarge%29%0A%20%20%20%20%23%20%E5%B0%86%E5%8E%9F%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E6%89%80%E6%9C%89%E5%85%83%E7%B4%A0%E5%A4%8D%E5%88%B6%E5%88%B0%E6%96%B0%E6%95%B0%E7%BB%84%0A%20%20%20%20for%20i%20in%20range%28len%28nums%29%29%3A%0A%20%20%20%20%20%20%20%20res%5Bi%5D%20%3D%20nums%5Bi%5D%0A%20%20%20%20%23%20%E8%BF%94%E5%9B%9E%E6%89%A9%E5%B1%95%E5%90%8E%E7%9A%84%E6%96%B0%E6%95%B0%E7%BB%84%0A%20%20%20%20return%20res%0A%0A%22%22%22Driver%20Code%22%22%22%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20%23%20%E5%88%9D%E5%A7%8B%E5%8C%96%E6%95%B0%E7%BB%84%0A%20%20%20%20nums%20%3D%20%5B1,%203,%202,%205,%204%5D%0A%20%20%20%20print%28%22%E6%95%B0%E7%BB%84%20nums%20%3D%22,%20nums%29%0A%0A%20%20%20%20%23%20%E9%95%BF%E5%BA%A6%E6%89%A9%E5%B1%95%0A%20%20%20%20nums%20%3D%20extend%28nums,%203%29%0A%20%20%20%20print%28%22%E5%B0%86%E6%95%B0%E7%BB%84%E9%95%BF%E5%BA%A6%E6%89%A9%E5%B1%95%E8%87%B3%208%20%EF%BC%8C%E5%BE%97%E5%88%B0%20nums%20%3D%22,%20nums%29&codeDivHeight=472&codeDivWidth=350&cumulative=false&curInstr=6&heapPrimitives=nevernest&origin=opt-frontend.js&py=311&rawInputLstJSON=%5B%5D&textReferences=false"> </iframe></div>
|
||||
<div style="margin-top: 5px;"><a href="https://pythontutor.com/iframe-embed.html#code=%23%20%E8%AF%B7%E6%B3%A8%E6%84%8F%EF%BC%8CPython%20%E7%9A%84%20list%20%E6%98%AF%E5%8A%A8%E6%80%81%E6%95%B0%E7%BB%84%EF%BC%8C%E5%8F%AF%E4%BB%A5%E7%9B%B4%E6%8E%A5%E6%89%A9%E5%B1%95%0A%23%20%E4%B8%BA%E4%BA%86%E6%96%B9%E4%BE%BF%E5%AD%A6%E4%B9%A0%EF%BC%8C%E6%9C%AC%E5%87%BD%E6%95%B0%E5%B0%86%20list%20%E7%9C%8B%E4%BD%9C%E9%95%BF%E5%BA%A6%E4%B8%8D%E5%8F%AF%E5%8F%98%E7%9A%84%E6%95%B0%E7%BB%84%0Adef%20extend%28nums%3A%20list%5Bint%5D,%20enlarge%3A%20int%29%20-%3E%20list%5Bint%5D%3A%0A%20%20%20%20%22%22%22%E6%89%A9%E5%B1%95%E6%95%B0%E7%BB%84%E9%95%BF%E5%BA%A6%22%22%22%0A%20%20%20%20%23%20%E5%88%9D%E5%A7%8B%E5%8C%96%E4%B8%80%E4%B8%AA%E6%89%A9%E5%B1%95%E9%95%BF%E5%BA%A6%E5%90%8E%E7%9A%84%E6%95%B0%E7%BB%84%0A%20%20%20%20res%20%3D%20%5B0%5D%20*%20%28len%28nums%29%20%2B%20enlarge%29%0A%20%20%20%20%23%20%E5%B0%86%E5%8E%9F%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E6%89%80%E6%9C%89%E5%85%83%E7%B4%A0%E5%A4%8D%E5%88%B6%E5%88%B0%E6%96%B0%E6%95%B0%E7%BB%84%0A%20%20%20%20for%20i%20in%20range%28len%28nums%29%29%3A%0A%20%20%20%20%20%20%20%20res%5Bi%5D%20%3D%20nums%5Bi%5D%0A%20%20%20%20%23%20%E8%BF%94%E5%9B%9E%E6%89%A9%E5%B1%95%E5%90%8E%E7%9A%84%E6%96%B0%E6%95%B0%E7%BB%84%0A%20%20%20%20return%20res%0A%0A%22%22%22Driver%20Code%22%22%22%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20%23%20%E5%88%9D%E5%A7%8B%E5%8C%96%E6%95%B0%E7%BB%84%0A%20%20%20%20nums%20%3D%20%5B1,%203,%202,%205,%204%5D%0A%20%20%20%20print%28%22%E6%95%B0%E7%BB%84%20nums%20%3D%22,%20nums%29%0A%0A%20%20%20%20%23%20%E9%95%BF%E5%BA%A6%E6%89%A9%E5%B1%95%0A%20%20%20%20nums%20%3D%20extend%28nums,%203%29%0A%20%20%20%20print%28%22%E5%B0%86%E6%95%B0%E7%BB%84%E9%95%BF%E5%BA%A6%E6%89%A9%E5%B1%95%E8%87%B3%208%20%EF%BC%8C%E5%BE%97%E5%88%B0%20nums%20%3D%22,%20nums%29&codeDivHeight=800&codeDivWidth=600&cumulative=false&curInstr=6&heapPrimitives=nevernest&origin=opt-frontend.js&py=311&rawInputLstJSON=%5B%5D&textReferences=false" target="_blank" rel="noopener noreferrer">Full Screen ></a></div></p>
|
||||
</details>
|
||||
<h2 id="412-advantages-and-limitations-of-arrays">4.1.2 Advantages and Limitations of Arrays<a class="headerlink" href="#412-advantages-and-limitations-of-arrays" title="Permanent link">¶</a></h2>
|
||||
<h2 id="412-advantages-and-limitations-of-arrays">4.1.2 Advantages and limitations of arrays<a class="headerlink" href="#412-advantages-and-limitations-of-arrays" title="Permanent link">¶</a></h2>
|
||||
<p>Arrays are stored in contiguous memory spaces and consist of elements of the same type. This approach provides substantial prior information that systems can leverage to optimize the efficiency of data structure operations.</p>
|
||||
<ul>
|
||||
<li><strong>High Space Efficiency</strong>: Arrays allocate a contiguous block of memory for data, eliminating the need for additional structural overhead.</li>
|
||||
<li><strong>Support for Random Access</strong>: Arrays allow <span class="arithmatex">\(O(1)\)</span> time access to any element.</li>
|
||||
<li><strong>Cache Locality</strong>: When accessing array elements, the computer not only loads them but also caches the surrounding data, utilizing high-speed cache to enchance subsequent operation speeds.</li>
|
||||
<li><strong>High space efficiency</strong>: Arrays allocate a contiguous block of memory for data, eliminating the need for additional structural overhead.</li>
|
||||
<li><strong>Support for random access</strong>: Arrays allow <span class="arithmatex">\(O(1)\)</span> time access to any element.</li>
|
||||
<li><strong>Cache locality</strong>: When accessing array elements, the computer not only loads them but also caches the surrounding data, utilizing high-speed cache to enchance subsequent operation speeds.</li>
|
||||
</ul>
|
||||
<p>However, continuous space storage is a double-edged sword, with the following limitations:</p>
|
||||
<ul>
|
||||
<li><strong>Low Efficiency in Insertion and Deletion</strong>: As arrays accumulate many elements, inserting or deleting elements requires shifting a large number of elements.</li>
|
||||
<li><strong>Fixed Length</strong>: The length of an array is fixed after initialization. Expanding an array requires copying all data to a new array, incurring significant costs.</li>
|
||||
<li><strong>Space Wastage</strong>: If the allocated array size exceeds the what is necessary, the extra space is wasted.</li>
|
||||
<li><strong>Low efficiency in insertion and deletion</strong>: As arrays accumulate many elements, inserting or deleting elements requires shifting a large number of elements.</li>
|
||||
<li><strong>Fixed length</strong>: The length of an array is fixed after initialization. Expanding an array requires copying all data to a new array, incurring significant costs.</li>
|
||||
<li><strong>Space wastage</strong>: If the allocated array size exceeds the what is necessary, the extra space is wasted.</li>
|
||||
</ul>
|
||||
<h2 id="413-typical-applications-of-arrays">4.1.3 Typical Applications of Arrays<a class="headerlink" href="#413-typical-applications-of-arrays" title="Permanent link">¶</a></h2>
|
||||
<h2 id="413-typical-applications-of-arrays">4.1.3 Typical applications of arrays<a class="headerlink" href="#413-typical-applications-of-arrays" title="Permanent link">¶</a></h2>
|
||||
<p>Arrays are fundamental and widely used data structures. They find frequent application in various algorithms and serve in the implementation of complex data structures.</p>
|
||||
<ul>
|
||||
<li><strong>Random Access</strong>: Arrays are ideal for storing data when random sampling is required. By generating a random sequence based on indices, we can achieve random sampling efficiently.</li>
|
||||
<li><strong>Sorting and Searching</strong>: Arrays are the most commonly used data structure for sorting and searching algorithms. Techniques like quick sort, merge sort, binary search, etc., are primarily operate on arrays.</li>
|
||||
<li><strong>Lookup Tables</strong>: Arrays serve as efficient lookup tables for quick element or relationship retrieval. For instance, mapping characters to ASCII codes becomes seamless by using the ASCII code values as indices and storing corresponding elements in the array.</li>
|
||||
<li><strong>Machine Learning</strong>: Within the domain of neural networks, arrays play a pivotal role in executing crucial linear algebra operations involving vectors, matrices, and tensors. Arrays serve as the primary and most extensively used data structure in neural network programming.</li>
|
||||
<li><strong>Data Structure Implementation</strong>: Arrays serve as the building blocks for implementing various data structures like stacks, queues, hash tables, heaps, graphs, etc. For instance, the adjacency matrix representation of a graph is essentially a two-dimensional array.</li>
|
||||
<li><strong>Random access</strong>: Arrays are ideal for storing data when random sampling is required. By generating a random sequence based on indices, we can achieve random sampling efficiently.</li>
|
||||
<li><strong>Sorting and searching</strong>: Arrays are the most commonly used data structure for sorting and searching algorithms. Techniques like quick sort, merge sort, binary search, etc., are primarily operate on arrays.</li>
|
||||
<li><strong>Lookup tables</strong>: Arrays serve as efficient lookup tables for quick element or relationship retrieval. For instance, mapping characters to ASCII codes becomes seamless by using the ASCII code values as indices and storing corresponding elements in the array.</li>
|
||||
<li><strong>Machine learning</strong>: Within the domain of neural networks, arrays play a pivotal role in executing crucial linear algebra operations involving vectors, matrices, and tensors. Arrays serve as the primary and most extensively used data structure in neural network programming.</li>
|
||||
<li><strong>Data structure implementation</strong>: Arrays serve as the building blocks for implementing various data structures like stacks, queues, hash tables, heaps, graphs, etc. For instance, the adjacency matrix representation of a graph is essentially a two-dimensional array.</li>
|
||||
</ul>
|
||||
|
||||
<!-- Source file information -->
|
||||
@@ -3497,7 +3503,7 @@ aria-label="Footer"
|
||||
<a
|
||||
href="../"
|
||||
class="md-footer__link md-footer__link--prev"
|
||||
aria-label="Previous: Chapter 4. &nbsp; Arrays and Linked Lists"
|
||||
aria-label="Previous: Chapter 4. &nbsp; Arrays and linked lists"
|
||||
rel="prev"
|
||||
>
|
||||
<div class="md-footer__button md-icon">
|
||||
@@ -3509,7 +3515,7 @@ aria-label="Footer"
|
||||
Previous
|
||||
</span>
|
||||
<div class="md-ellipsis">
|
||||
Chapter 4. Arrays and Linked Lists
|
||||
Chapter 4. Arrays and linked lists
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
@@ -3521,7 +3527,7 @@ aria-label="Footer"
|
||||
<a
|
||||
href="../linked_list/"
|
||||
class="md-footer__link md-footer__link--next"
|
||||
aria-label="Next: 4.2 Linked List"
|
||||
aria-label="Next: 4.2 Linked list"
|
||||
rel="next"
|
||||
>
|
||||
<div class="md-footer__title">
|
||||
@@ -3529,7 +3535,7 @@ aria-label="Footer"
|
||||
Next
|
||||
</span>
|
||||
<div class="md-ellipsis">
|
||||
4.2 Linked List
|
||||
4.2 Linked list
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-footer__button md-icon">
|
||||
@@ -3622,7 +3628,7 @@ aria-label="Footer"
|
||||
<nav class="md-footer__inner md-grid" aria-label="Footer" >
|
||||
|
||||
|
||||
<a href="../" class="md-footer__link md-footer__link--prev" aria-label="Previous: Chapter 4. &nbsp; Arrays and Linked Lists">
|
||||
<a href="../" class="md-footer__link md-footer__link--prev" aria-label="Previous: Chapter 4. &nbsp; Arrays and linked lists">
|
||||
<div class="md-footer__button md-icon">
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
|
||||
@@ -3632,20 +3638,20 @@ aria-label="Footer"
|
||||
Previous
|
||||
</span>
|
||||
<div class="md-ellipsis">
|
||||
Chapter 4. Arrays and Linked Lists
|
||||
Chapter 4. Arrays and linked lists
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<a href="../linked_list/" class="md-footer__link md-footer__link--next" aria-label="Next: 4.2 Linked List">
|
||||
<a href="../linked_list/" class="md-footer__link md-footer__link--next" aria-label="Next: 4.2 Linked list">
|
||||
<div class="md-footer__title">
|
||||
<span class="md-footer__direction">
|
||||
Next
|
||||
</span>
|
||||
<div class="md-ellipsis">
|
||||
4.2 Linked List
|
||||
4.2 Linked list
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-footer__button md-icon">
|
||||
|
||||
Reference in New Issue
Block a user