From 04867399992506942058c7c5662f39ba27f88a7e Mon Sep 17 00:00:00 2001 From: kekeandzeyu Date: Mon, 9 Sep 2024 20:35:22 +0800 Subject: [PATCH] add sitemap --- Writerside/cfg/buildprofiles.xml | 1 + .../Data-Structures-and-Algorithms-1.md | 115 +++++++++--------- 2 files changed, 58 insertions(+), 58 deletions(-) diff --git a/Writerside/cfg/buildprofiles.xml b/Writerside/cfg/buildprofiles.xml index e7b10eb..25a6a87 100644 --- a/Writerside/cfg/buildprofiles.xml +++ b/Writerside/cfg/buildprofiles.xml @@ -1,6 +1,7 @@ + diff --git a/Writerside/topics/Data-Structures-and-Algorithms-1.md b/Writerside/topics/Data-Structures-and-Algorithms-1.md index b4e2d21..3481efb 100644 --- a/Writerside/topics/Data-Structures-and-Algorithms-1.md +++ b/Writerside/topics/Data-Structures-and-Algorithms-1.md @@ -11,7 +11,7 @@

Sentinel code make it easier to reason about code, and also give you specific goals to strive for in making sure your code works.

-Sentinel Node +Sentinel Node ### 2.1 Singly Linked Lists @@ -623,14 +623,14 @@ class Deque: ### 3.1 Quick Find (Eager Approach) - +
  • parent[i] is the root of i, p and q are connected if and only if they have the same parent[i].

  • -

    Find: Check if p +

    Find: Check if p and q have the same parent[i].

  • @@ -641,9 +641,9 @@ entries whose id equals parent[p] to parent[q]
  • - -

    Defect:

    - + +

    Defect:

    +
  • Union too expensive (N array accesses).

  • @@ -651,22 +651,22 @@ entries whose id equals parent[p] to parent[q]

    Trees are flat, but too expensive to keep them flat.

    -
    + ### 3.2 Quick Union (Lazy Approach)
  • parent[i] is the parent of i, root of i -is
    parent[parent[...[i]]] (keep going until it doesn't change). +is parent[parent[...[i]]] (keep going until it doesn't change).

  • -

    Find: Check if p +

    Find: Check if p and q have the same root.

  • -

    Union: To merge +

    Union: To merge components containing p and q, set the parent of p's root to the parent of q's root.

    @@ -674,8 +674,8 @@ root.

    -

    Defect:

    - +

    Defect:

    +
  • Trees can get tall.

  • @@ -689,7 +689,7 @@ root.

    Two Improvements: Weighting and Path Compression (WQUPC).

    - +

    Modify quick-union to avoid tall trees.

    @@ -711,7 +711,8 @@ each examined node to point to that root.

  • -

    rank[i] is the size of the tree rooted at i.

    +

    rank[i] is the size of the tree rooted at i +.

  • Property: Starting from an empty data structure, any sequence of @@ -852,25 +853,32 @@ class UnionFind: ## 4 Bags, Queues and Stacks -* Stack: Examine the item most recently added (LIFO: last in first out). - -* Queue: Examine the item least recently added (FIFO: first in first out). + +

  • +

    Stack: Examine the item most +recently added (LIFO: last in first out).

    +
  • +
  • +

    Queue: Examine the item least +recently added (FIFO: first in first out).

    +
  • +
    ### 4.1 Stacks -

    Defintion:

    +

    Defintion:

  • -

    Client: program using +

    Client: program using operations defined in interface.

  • -

    Implementation: actual code +

    Implementation: actual code implementing operations.

  • -

    Interface: description of +

    Interface: description of data types, basic operations.

  • @@ -889,11 +897,11 @@ client has many implementation from which to choose.

    many clients can re-use the same implementation.

  • -

    Design: creates modular, +

    Design: creates modular, reusable libraries.

  • -

    Performance: use optimized +

    Performance: use optimized implementation where it matters.

  • @@ -982,11 +990,11 @@ print(len(stack) == 0) Return saved item. -Stack pop +Stack pop - + Save a link to the list. @@ -996,8 +1004,8 @@ style = "inline"/> Set the instance variables in the new node. -Stack push +Stack push

    Properties:

    @@ -1012,11 +1020,7 @@ style = "inline"/>
    -Stroage Structure - - -

    This is the linked-list implementation of stacks.

    -
    +Stroage Structure Java @@ -1132,7 +1136,7 @@ class Stack: #### 4.1.3 Resizing-Array Implementation -

    Property: Uses between +

    Property: Uses between \sim 8N and \sim 32N bytes to represent a stack with N items.

    @@ -1145,21 +1149,23 @@ represent a stack with N items.

    - - - - - +
    Linked-List ImplementationResizing-Array -Implementation
    Every operation takes constant time in the worst case.Every operation -takes constant amortized time. -
    Uses extra time and space to deal with the links.Less wasted space.
    + + + + + + + + + + + +
    Linked-List ImplementationResizing-Array Implementation
    Every operation takes constant time in the worst case.Every operation takes constant + amortized time.
    Uses extra time and space to deal with the links.Less wasted space.
    -> This is the resizing-array implementation of stacks. -> -{style = "note"} - Java ```Java @@ -1205,10 +1211,6 @@ public class ResizingArrayStackOfStrings { #### 4.2.1 Built-in Queues -> This is the use of built-in queues. -> -{style = "note"} - Java ```Java @@ -1282,10 +1284,11 @@ print(q.empty()) Return saved item. -Queue dequeue +Queue dequeue - + Save a link to the last node. @@ -1295,13 +1298,9 @@ print(q.empty()) Link the new node to the end of the list. -Queue enqueue +Queue enqueue -> This is the implementation of queues. -> -{style = "note"} - Java ```Java