CSE 101

CSE 101 · WEEK 12 · READING

Artificial intelligence and data structures

From rules and search to learning systems; from records to connected nodes.

Read the AI concepts first, then trace the node-and-link examples. Try each Check before opening its answer. The detailed reference galleries are optional. Lab 11 focuses on supplied singly linked lists on the PC; tree and graph implementation is not required. Click any figure to enlarge it. Wide code and tables scroll sideways.

1. Intelligence is a question about tasks and evidence

Shakey at SRI, 1966–1972. Photograph: SRI International.
Figure 1. Shakey at SRI, 1966–1972. Photograph: SRI International. CSE101 Week 12, slide 2. Source slide.

A robot moving through a room needs more than a motor command. It must obtain observations, represent what matters, choose an action and assess what happened. Shakey, developed at SRI from 1966 to 1972, is a historical example linking perception, planning and physical action. Its photograph is a reminder that artificial intelligence includes interaction with the world, not only conversation. See SRI’s Shakey history.

Artificial intelligence is a broad area concerned with systems performing tasks associated with intelligent behavior. Machine learning is one family of methods within it: models are fitted from data or experience. Deep learning is a family of machine learning using multilayer neural networks. These terms are related, but not interchangeable. A planner using explicit rules and search can be an AI system without learning its rules from examples.

Turing’s imitation game examined behavior through conversation. Success on one behavioral test does not establish general competence or settle questions about consciousness. For engineering, begin with a concrete task: what inputs does the system receive, what output is useful, and what evidence would show that it works? A chess result, an image classification score and a robot’s navigation reliability measure different achievements.

Check: Must every AI system train a neural network?

No. Explicit rules, symbolic representations and search can support intelligent behavior. Learning can also be combined with these methods.

2. Rules need representations and reliable premises

Facts and rules produce a new conclusion. The conclusion depends on the premises.
Figure 2. Facts and rules produce a new conclusion. The conclusion depends on the premises. CSE101 Week 12, slide 9. Source slide.
A semantic network records concepts and relationships. Its links have explicit meanings.
Figure 3. A semantic network records concepts and relationships. Its links have explicit meanings. CSE101 Week 12, slide 10. Source slide.

An expert system separates knowledge from the procedure that applies it. Facts describe a situation; rules connect conditions to conclusions. In a simplified equipment example, observing a commanded motor with zero current might lead to a recommendation to inspect the circuit. This is a teaching illustration, not a real diagnostic or safety procedure: missing facts can change the conclusion.

Deduction follows implications from premises. If a rule says that every item of class A has property B, and a particular item is known to be A, B follows under that rule. The inference can be valid even when a premise is factually wrong. The quality of the knowledge base therefore matters as much as the inference mechanism.

A semantic network represents concepts and named relationships. A link can mean “is a kind of,” “has a part” or another explicit relation. Do not interpret all arrows as the same operation. These symbolic links differ from weighted connections in a neural network: a neural weight is a numerical parameter, not automatically a human-readable proposition.

Check: If a rule system can explain which rule it used, does that prove its answer is correct?

No. The explanation exposes the reasoning path. The facts and rules still need to be appropriate and correct.

4. A heuristic guides search without being an oracle

Manhattan distance adds each numbered tile’s row and column distance from its goal. The blank is excluded.
Figure 7. Manhattan distance adds each numbered tile’s row and column distance from its goal. The blank is excluded. CSE101 Week 12, slide 14. Source slide.
This example ranks candidates by estimated distance h. Smaller h looks more promising.
Figure 8. This example ranks candidates by estimated distance h. Smaller h looks more promising. CSE101 Week 12, slide 15. Source slide.

A heuristic h estimates the remaining effort. For the pictured puzzle, Manhattan distance counts horizontal and vertical displacement from each numbered tile’s target, ignoring the blank. The shown displaced tiles contribute 1 + 1 + 1 + 2 + 2 = 7. It is an estimate because legal moves may require temporary detours.

Greedy best-first search prioritizes a small h. A* instead combines the cost already paid, g, with the estimate remaining, h, using f = g + h. The original procedure shown later uses h alone and should not be called A*. A promising-looking state is not necessarily on the least-cost complete route.

Optimality claims require assumptions about costs, the heuristic and repeated-state handling. For the standard unit-cost sliding puzzle, the sum of numbered-tile Manhattan distances is a lower bound: a move changes one numbered tile’s distance by at most one. That does not turn every procedure using the estimate into an optimal search algorithm.

Check: Two candidates have (g,h) = (20,2) and (5,4). Which does greedy prefer, and which has smaller A* score?

Greedy prefers h = 2. Their g + h scores are 22 and 9, so A* prioritizes the second by that score. This comparison alone does not prove which complete route is optimal.

5. Search and learning can cooperate

1997 rematch: Garry Kasparov and IBM operator Joe Hoane. Photograph: IBM.
Figure 9. 1997 rematch: Garry Kasparov and IBM operator Joe Hoane. Photograph: IBM. CSE101 Week 12, slide 17. Source slide.
DeepMind team watching the match. Photograph: Google DeepMind.
Figure 10. DeepMind team watching the match. Photograph: Google DeepMind. CSE101 Week 12, slide 18. Source slide.

Deep Blue defeated Garry Kasparov in their 1997 match. Its success illustrates the power of extensive search, evaluation and specialized engineering in a well-defined game. AlphaGo combined learned policy and value information with search. Neither result means that one identical method solves every problem described as intelligent.

A game supplies legal moves and a clear result. Real deployments may instead have noisy observations, delayed feedback, changing conditions or disputed objectives. A system that is excellent within one environment can fail when those assumptions change. Identify the rules of the evaluation before transferring the conclusion to another task.

The photographs are credited to IBM and Google DeepMind. The point of the comparison is methodological: learned estimates can help choose useful branches, while explicit search organizes the alternatives.

Check: Does using a learned evaluation function mean a system no longer performs search?

No. Learning and search can serve different roles within the same system.

6. What changes when a model learns?

In supervised learning, an example contains input information and a target answer. A model makes a prediction; a loss measures its discrepancy from the target; training adjusts parameters to improve the objective. Features are the representation supplied to the model. Parameters are quantities fitted during training. Settings such as model size or learning rate are chosen through the development process.

Different kinds of feedback
SettingFeedbackExample
SupervisedTargets for examplesLabel photographs as defective or sound
UnsupervisedNo target label for each exampleFind groups of similar measurements
ReinforcementRewards linked to actions and experienceLearn a policy in a simulated control task

These categories describe learning arrangements, not a ranking of intelligence. Unsupervised learning does not mean that people make no design choices. Reinforcement learning does not receive the ideal action for every state automatically. The choice of objective influences what the system learns to do.

Training changes parameters. Inference uses a fitted model to compute an output. Ordinary inference need not update parameters, even when the response depends strongly on the supplied context. Some applications collect feedback for later training or use online learning, but that is an additional system design, not a consequence of every prediction.

Check: If you provide a paragraph as context and the response changes, has the model necessarily retrained?

No. The same parameters can produce a different output from different input context. Parameter updating is a separate operation.

7. A good fit is not enough

Diamonds and circles mark two classes of trees. Diagram: Google ML Crash Course, CC BY 4.0.
Figure 11. Diamonds and circles mark two classes of trees. Diagram: Google ML Crash Course, CC BY 4.0. CSE101 Week 12, slide 22. Source slide.
A complicated boundary can fit many training examples. Diagram: Google ML Crash Course, CC BY 4.0.
Figure 12. A complicated boundary can fit many training examples. Diagram: Google ML Crash Course, CC BY 4.0. CSE101 Week 12, slide 23. Source slide.
Crossed symbols show errors on test examples. Diagram: Google ML Crash Course, CC BY 4.0.
Figure 13. Crossed symbols show errors on test examples. Diagram: Google ML Crash Course, CC BY 4.0. CSE101 Week 12, slide 24. Source slide.

The three diagrams show training examples, a fitted boundary and new examples evaluated against it. A complicated boundary can follow the training points closely yet classify new points badly. This is overfitting. Underfitting is the opposite difficulty: the model fails to capture useful structure even in the training data. The goal is useful performance on the situations the system will encounter, not merely on remembered examples.

Training data fits parameters. Validation data helps choose settings and models. A test set supplies a later assessment; repeatedly choosing changes because they improve that same test score weakens its independence. Data leakage occurs when information unavailable at real prediction time influences development or evaluation. A duplicated image appearing in both training and test sets is a simple example.

These figures are from Google’s Machine Learning Crash Course, under CC BY 4.0, rasterized and resized from the source. Their lesson is to compare training behavior with genuinely new cases.

For sensor or video data, adjacent samples may be strongly related. Randomly splitting individual frames can place almost identical scenes on both sides. A deployment on a new machine, person or future period may need separation by that unit instead. An evaluation must reflect the actual question, including plausible changes in the environment.

Check: A model is perfect on training images. What essential evidence is still missing?

Its performance on independent, representative new images, including relevant failure cases. Training accuracy alone cannot establish generalization.

8. From a biological analogy to a numerical unit

Artificial neural networks borrow a simplified idea of connected units. They are not complete models of a brain.
Figure 14. Artificial neural networks borrow a simplified idea of connected units. They are not complete models of a brain. CSE101 Week 12, slide 26. Source slide.
Multiply inputs by weights, add the results, then apply an activation rule.
Figure 15. Multiply inputs by weights, add the results, then apply an activation rule. CSE101 Week 12, slide 27. Source slide.
Threshold rule in this example: output 1 when the weighted sum exceeds 1.5, otherwise output 0.
Figure 16. Threshold rule in this example: output 1 when the weighted sum exceeds 1.5, otherwise output 0. CSE101 Week 12, slide 28. Source slide.

Artificial neural networks borrow an idea of interconnected processing units. They are mathematical models, not complete simulations of brains. A basic unit combines inputs using weights, adds an optional bias and applies an activation function. The output depends on numerical values and the activation rule, not only on which units are connected.

The original threshold example uses weights −2, 3 and −1 with inputs (0,1,1). The weighted sum is −2×0 + 3×1 −1×1 = 2. Its stated rule outputs 1 when the sum exceeds 1.5, so this input produces 1. A threshold of 1.5 can equivalently be represented by a bias of −1.5 and a threshold at zero, provided the comparison convention is preserved.

Check: For inputs (1,1,0) in the same unit, what is the output?

The sum is −2 + 3 = 1. It does not exceed 1.5, so the output is 0.

9. Layers and nonlinearities expand what can be represented

Two classes occupy alternating regions. Diagram: Google ML Crash Course, CC BY 4.0.
Figure 17. Two classes occupy alternating regions. Diagram: Google ML Crash Course, CC BY 4.0. CSE101 Week 12, slide 29. Source slide.
The upper network computes XOR. The lower network has different weights and behaves differently.
Figure 18. The upper network computes XOR. The lower network has different weights and behaves differently. CSE101 Week 12, slide 30. Source slide.
Historical neural-network driving example. Image inputs connect through a hidden layer to steering outputs.
Figure 19. Historical neural-network driving example. Image inputs connect through a hidden layer to steering outputs. CSE101 Week 12, slide 31. Source slide.

A single straight boundary cannot separate every arrangement of classes. Hidden units and nonlinear activations can combine simpler computations into more complex boundaries. If a sequence of layers were purely linear or affine, it could be combined into one affine transformation; adding layers alone would not supply the same expressive benefit.

The original XOR networks show why a connection diagram is incomplete without weights and activation rules. XOR should produce 1 for unequal binary inputs and 0 for equal ones. Two networks with similar wiring can behave differently. Check their computed outputs instead of assuming that a familiar shape implements the intended function.

ALVINN is a historical illustration of learning steering from camera information. The figure connects measurements, hidden computations and an output choice; it is not evidence that a modern autonomous-driving system consists of this network alone. The nonlinear-boundary figure is from Google ML Crash Course, CC BY 4.0.

During training, a forward pass computes predictions and loss. Backpropagation applies the chain rule to calculate gradients through differentiable computations. An optimizer uses those gradients to adjust parameters. Backpropagation computes sensitivity; the optimizer determines the update. Improvement on one example can worsen another, which is why evaluation must consider many examples.

Check: Does a network diagram with the right number of layers prove that XOR is computed correctly?

No. The numerical parameters and activation functions determine the mapping. Test all four binary input pairs.

10. Generating content is not retrieving a guaranteed fact

A classifier predicts a category; a generative model produces a sample such as text or an image. In an autoregressive language model, the next token is predicted from the preceding context. A token may be a word, part of a word or another unit of encoding. Generation repeatedly selects a token and adds it to the context.

An illustrative next-token distribution, not a measured model output
ContextCandidateProbability
The kettle contains hotwater0.60
Same contexttea0.25
Same contextair0.10
Same contextother tokens combined0.05

The probabilities sum to one. A decoding procedure may choose the most likely token or sample from a modified distribution. Different decoding choices can produce different continuations from the same model. A plausible continuation can still be false: the training objective and generation process do not by themselves certify factual accuracy.

Diffusion models illustrate a different family of generative methods: they learn a process related to reversing added noise to construct samples. Do not describe every generative model as next-token prediction. The appropriate account depends on the model architecture and training objective.

Check: If “water” has probability 0.60 in this illustration, does the model know that a real kettle contains water?

No. The number describes a candidate continuation under the illustrative context. It does not verify the state of a physical kettle.

11. Context, attention and application tools

“The animal didn’t cross the street because it was too tired.” Diagram: Google ML Crash Course, CC BY 4.0.
Figure 20. “The animal didn’t cross the street because it was too tired.” Diagram: Google ML Crash Course, CC BY 4.0. CSE101 Week 12, slide 36. Source slide.

Attention computes weighted combinations of information from positions in a sequence. The diagram uses a sentence about an animal and a street to illustrate contextual relationships. Attention is a numerical computation; its name should not be interpreted as proof of human-like awareness. This Google ML Crash Course diagram is CC BY 4.0; see the transformer introduction and the original Attention Is All You Need paper.

A deployed application can add document retrieval, calculators, databases or other tools around a model. Retrieved information can supply relevant context, but does not guarantee that the response uses it correctly. Likewise, generating text that looks like a tool result is different from actually executing a tool and receiving its output.

Evaluate the complete application: the retrieved sources, requested actions, returned results and final claims. A base model, a retrieval system and an interface have separate responsibilities. For factual questions, inspect the evidence behind an answer rather than treating fluent wording as evidence.

Check: If a chatbot cites a document title, has it necessarily retrieved and checked that document?

No. Verify that the document exists and supports the claim. A generated reference can be inaccurate even when formatted convincingly.

12. A single accuracy score can hide important errors

One hundred inspected parts: the worked example
Actually defectiveActually sound
Predicted defective163
Predicted sound477

There are 16 true positives, 3 false positives, 4 false negatives and 77 true negatives. Accuracy is (16 + 77)/100 = 93%. Recall for defects is 16/(16 + 4) = 80%: the system misses one fifth of the actual defects. Precision is 16/(16 + 3), approximately 84.2%: that fraction of its defect warnings is correct.

Which errors matter depends on the task. False alarms consume inspection effort; missed defects can allow faulty parts through. Changing a decision threshold may change the trade-off. For definitions and further examples, use Google’s classification metrics lesson.

If only one part in a hundred were defective, predicting “sound” for everything would reach 99% accuracy while finding no defects. Also inspect performance across relevant conditions: lighting, device types, operating ranges and groups of users. Overall performance can hide a weak subgroup or a failure after conditions change.

Reliability also depends on the surrounding process: what happens when the system is uncertain, how people review outputs and how errors are detected after deployment. The NIST AI Risk Management Framework offers a broader resource for considering system risks and evaluation responsibilities.

Check: Is 93% accuracy sufficient to conclude that the inspection system is ready?

No. We need the error breakdown, representative test conditions, the costs of different errors and a suitable operational review process.

13. Access rules and storage representations are different

These are different access rules. Their implementation can use arrays or linked nodes.
Figure 21. These are different access rules. Their implementation can use arrays or linked nodes. CSE101 Week 12, slide 43. Source slide.
An array keeps successive elements together. Inserting in the middle may require moving later elements.
Figure 22. An array keeps successive elements together. Inserting in the middle may require moving later elements. CSE101 Week 12, slide 44. Source slide.
Each node stores data and a link. Physical location and logical sequence can differ.
Figure 23. Each node stores data and a link. Physical location and logical sequence can differ. CSE101 Week 12, slide 45. Source slide.
Books remain arranged by title while links provide an authorship order. Original instructor analogy and photograph.
Figure 24. Books remain arranged by title while links provide an authorship order. Original instructor analogy and photograph. CSE101 Week 12, slide 46. Source slide.

The second strand of this week builds on Week 11 structures and Week 9 pointers. An array keeps elements contiguously and supports direct indexing. A linked list stores a successor reference in each node; the logical order follows links and need not match physical memory order. The original bookshelf analogy shows one physical arrangement supporting another logical ordering.

A list describes a sequence. A stack specifies last-in, first-out access; a queue specifies first-in, first-out access. A stack or queue can be implemented with an array or linked nodes. Do not confuse the access rule with one particular storage diagram.

The useful comparison is operation-specific. Arrays provide direct access to an index and often good locality. Inserting into the middle may require moving elements. A linked list can change a few links once the relevant node is known, but locating that node still costs a traversal in a simple singly linked list. Links also consume storage and require lifetime management.

Check: Is insertion into a linked list always constant-time from the moment a user supplies an ID?

No. Searching for that ID may take linear time. Relinking after a known valid predecessor is the short operation.

14. A node is a record with a link

typedef struct Node {
    int event_id;
    int value;
    struct Node *next;
} Node;

The fields describe one event; next points to the successor node or is NULL at the end. The structure contains a pointer to its own type, not another complete Node object embedded recursively. A complete embedded copy would require a size that never ends. The tag struct Node is available for declaring the self-referential pointer.

Node c = {103, 30, NULL};
Node b = {102, 20, &c};
Node a = {101, 10, &b};
Node *head = &a;

These are ordinary local objects. They remain valid while their enclosing block is active. No malloc is involved, so they must not be passed to free. The head pointer is the entry point, not an extra data node. Following next yields 101, 102, 103 regardless of where the compiler places the objects in memory.

Check: Can a function safely return a pointer to a local Node that ceases to exist when the function returns?

No. The pointer would no longer designate a live object. The list needs an ownership and lifetime arrangement that outlasts its use.

15. Follow the links and stop before dereferencing NULL

Start at head, visit each node and follow next until NULL.
Figure 25. Start at head, visit each node and follow next until NULL. CSE101 Week 12, slide 47. Source slide.
void print_list(const Node *p)
{
    while (p != NULL) {
        printf("%d: %d\n", p->event_id, p->value);
        p = p->next;
    }
}
Trace for the three-node list
Iterationp points toOutputNext p
1a101: 10&b
2b102: 20&c
3c103: 30NULL
StopNULLNothingNo dereference

The condition is checked before member access. An empty list starts with NULL and prints nothing. Advancing the local traversal pointer does not move the nodes or change head in the caller. const prevents changing node members through p in this function, while p itself can still advance.

This loop assumes a finite valid chain ending in NULL. A cycle can make it repeat indefinitely; a dangling pointer can make member access invalid. A termination condition does not prove the data structure satisfies the conditions needed to reach it.

Check: If p = p->next is omitted, what happens for a nonempty valid list?

The pointer never advances, so the first node is printed repeatedly. The condition remains true.

16. Preserve the successor before redirecting the link

Preserve the old successor before redirecting the predecessor. No other node needs to move.
Figure 26. Preserve the old successor before redirecting the predecessor. No other node needs to move. CSE101 Week 12, slide 52. Source slide.
Node x = {104, 40, NULL};
x.next = a.next;
a.next = &x;

Initially a points to b. First, x receives the old successor, b. Then a is redirected to x. The resulting sequence is 101, 104, 102, 103. The nodes do not have to move. This example assumes x is a distinct live node that is not already in the chain.

Reversing the assignments is a real defect: after a.next = &x, reading a.next obtains x, not b. Assigning that value to x.next creates a self-loop and loses the original route to b. Drawing the arrows after each statement is often more effective than rereading both lines as one vague “insert” operation.

Check: For a list A → B, what is wrong with A.next = &X followed by X.next = A.next?

The second assignment sets X.next to X. Save B as X’s successor before changing A’s link.

17. Unlinking changes reachability, not object lifetime

Bypassing a node removes it from this list. It does not automatically release its storage.
Figure 27. Bypassing a node removes it from this list. It does not automatically release its storage. CSE101 Week 12, slide 54. Source slide.
Node *victim = x.next;
if (victim != NULL) {
    x.next = victim->next;
    victim->next = NULL;
}

After the insertion above, x.next is b. Redirecting x to b’s successor bypasses b, leaving 101, 104, 103. Clearing b’s next makes its detached state explicit. The object b still exists. Other pointers might still refer to it, and this operation has not released storage.

Node *pop_front(Node *head)
{
    if (head == NULL) return NULL;
    Node *rest = head->next;
    head->next = NULL;
    return rest;
}
/* Caller: head = pop_front(head); */

Removing the first node changes the entry point, so the caller must use the returned head. The helper detaches but does not free the old first node. For these local objects that is appropriate. With allocated nodes, retain the removed pointer if cleanup is needed and define who owns it. A helper that loses the only pointer to allocated storage without releasing it would leak memory.

Check: Why must this example not call free(victim) when victim points to b?

b is a local object, not storage returned by a compatible allocation function. Unlinking it does not change how its storage was obtained.

18. Pointer correctness needs explicit invariants

Failures to diagnose
MistakeConsequenceQuestion to ask
Dereference NULLInvalid member accessWas the pointer checked first?
Lose the old successorRemaining nodes become unreachableWas the link saved before redirection?
Create a cycleTraversal may not finishDoes every path reach the intended end?
Use an expired objectDangling pointerIs the node still alive?
Free the same object twiceInvalid memory operationWho owns cleanup?

For a simple list, maintain a live head or NULL, valid successor links, an intended termination point and a clear ownership policy. These are invariants: properties that operations must preserve. A function can be locally short and still be wrong if it breaks the larger structure.

The lecture uses known-lifetime local nodes so the link changes are visible without allocation machinery. Lab 11 supplies allocation and cleanup support where needed. Extended memory-management implementation is not added to the exercise. Diagram the empty, singleton, head-removal and middle-removal cases separately.

Check: Does checking head != NULL prove that every later next pointer is valid?

No. It only checks that head is not null. The rest of the chain still depends on correct construction, lifetime and updates.

19. Stacks and queues organize when an item is used

Push and pop act on the same end. This rule does not require one particular storage representation.
Figure 28. Push and pop act on the same end. This rule does not require one particular storage representation. CSE101 Week 12, slide 61. Source slide.
A stack can use an array. Its defining access rule is last in, first out.
Figure 29. A stack can use an array. Its defining access rule is last in, first out. CSE101 Week 12, slide 62. Source slide.
A queue’s access rule is first in, first out. Trace which positions change.
Figure 30. A queue’s access rule is first in, first out. Trace which positions change. CSE101 Week 12, slide 63. Source slide.
Wrapping indices reuses space in a bounded array.
Figure 31. Wrapping indices reuses space in a bounded array. CSE101 Week 12, slide 64. Source slide.

A stack pushes and pops at the same end, so the most recently added item is removed first. It suits nested work and returning to a previous state. A queue adds at one end and removes at the other, so earlier items leave first. It suits waiting tasks or buffered events. These rules are independent of whether the implementation uses nodes or an array.

In a bounded circular queue, indices wrap around to reuse array slots. Under a zero-based convention with positive capacity C, advancing an index can use (index + 1) % C. Equal head and tail indices need an additional convention to distinguish full from empty: for example, an explicit count, a full flag or reserving one unused slot. State the chosen convention before tracing it.

Check: With capacity 4, an explicit count and next-write index 3, where does that index go after one insertion when space exists?

It wraps to (3 + 1) % 4 = 0, and count increases by one. The exact meaning of head/tail names depends on the stated convention.

20. A hierarchy needs more than one successor

A tree represents relationships rather than only a linear order.
Figure 32. A tree represents relationships rather than only a linear order. CSE101 Week 12, slide 65. Source slide.
Root, leaves, parent and child describe positions in the hierarchy.
Figure 33. Root, leaves, parent and child describe positions in the hierarchy. CSE101 Week 12, slide 66. Source slide.
Each node stores data and up to two child links.
Figure 34. Each node stores data and up to two child links. CSE101 Week 12, slide 67. Source slide.
A binary-tree node can have left and right links. A linked list has one successor link.
Figure 35. A binary-tree node can have left and right links. A linked list has one successor link. CSE101 Week 12, slide 68. Source slide.
Index rules can encode child relationships without explicit pointers.
Figure 36. Index rules can encode child relationships without explicit pointers. CSE101 Week 12, slide 69. Source slide.
A sparse tree can leave many unused array positions.
Figure 37. A sparse tree can leave many unused array positions. CSE101 Week 12, slide 70. Source slide.
Compare the original index convention before applying a child-index formula.
Figure 38. Compare the original index convention before applying a child-index formula. CSE101 Week 12, slide 71. Source slide.

A tree expresses hierarchical relationships: a root, parent–child links and leaves with no children. A binary-tree node has at most two children. “Binary” alone does not imply search ordering. A binary search tree adds an ordering rule relating keys in the left and right subtrees to the node’s key, including a policy for duplicates.

Pointers can represent children explicitly. An array can encode their positions instead. For a zero-based complete-tree layout, children of i are 2i + 1 and 2i + 2; for a one-based layout they are 2i and 2i + 1. Inspect which convention a source figure uses before applying formulas. Sparse trees can waste many positions in such an array representation.

A doubly linked list adds a predecessor link; a graph can represent more general connections and cycles. These are recognition and comparison topics here. A graph is not automatically a tree, and following its links without a visited-state policy may revisit nodes.

Check: Does having two child pointers guarantee that a tree supports ordered search?

No. The key-ordering invariant must also hold. The representation alone does not enforce it.

21. Search, traversal and insertion have different goals

Week 8 explained the search advantage. Here the focus is the stored nodes and their left/right links.
Figure 39. Week 8 explained the search advantage. Here the focus is the stored nodes and their left/right links. CSE101 Week 12, slide 72. Source slide.
For a binary search tree, left subtree, node, right subtree gives sorted order.
Figure 40. For a binary search tree, left subtree, node, right subtree gives sorted order. CSE101 Week 12, slide 73. Source slide.
Follow comparisons to the location of the new leaf.
Figure 41. Follow comparisons to the location of the new leaf. CSE101 Week 12, slide 74. Source slide.

Week 8 explained why a balanced ordered tree can reduce the number of comparisons. Here inspect how the nodes and links store that ordering. Searching chooses a subtree from a comparison; visiting every node is a different operation. A highly unbalanced search tree can behave like a long chain, so binary branching is not by itself a logarithmic-time guarantee.

In-order traversal visits the left subtree, then the node, then the right subtree. It yields sorted keys for a binary search tree, subject to its duplicate convention. It visits any ordinary binary tree in that order too, but the resulting keys need not be sorted if the search-tree invariant is absent.

Insertion follows comparisons to an appropriate empty child position and links in a new node. The original M example makes the change visible. The search and insertion pseudocode is retained later for reference; implementing a tree is not part of this week’s list lab.

Check: Can an in-order traversal sort arbitrary values in an arbitrary binary tree without changing that tree?

No. It reports the values in traversal order. Sorted output depends on an ordering invariant already present in the tree.

22. What to carry into recitation and Lab 11

For AI, practice explaining where a decision comes from: an explicit rule, a searched alternative or learned parameters. State the evaluation data and the kinds of errors a score hides. For C, draw the nodes and update one arrow per statement. These are complementary forms of reasoning about a system’s behavior.

Lab 11 remains PC-focused: traverse or modify a supplied singly linked list and diagnose a familiar defect. Prepared records and allocation/cleanup support protect the focus on links. Live Arduino is optional. No tree, graph or standalone debugger implementation is required. Week 11 structures and the earlier pointer material are the prerequisites.

Check: What should be checked after inserting a node, beyond seeing the new ID once?

Verify the complete expected order, retention of the remaining nodes, termination and valid node lifetimes. One printed ID does not prove that the list is intact.

24. Optional: weight changes and associative memory

The architecture is fixed in this example. The numerical weights can change.
Figure 49. The architecture is fixed in this example. The numerical weights can change. CSE101 Week 12, slide 85. Source slide.
For XOR, equal binary inputs should produce 0. This example currently does so.
Figure 50. For XOR, equal binary inputs should produce 0. This example currently does so. CSE101 Week 12, slide 86. Source slide.
For XOR, unequal inputs should produce 1. The current network produces 0.
Figure 51. For XOR, unequal inputs should produce 1. The current network produces 0. CSE101 Week 12, slide 87. Source slide.
The changed weight corrects this one example.
Figure 52. The changed weight corrects this one example. CSE101 Week 12, slide 88. Source slide.
A change that helps one example can harm another. Training must account for multiple examples.
Figure 53. A change that helps one example can harm another. Training must account for multiple examples. CSE101 Week 12, slide 89. Source slide.
A network can reconstruct a stored pattern from a related input. This is a historical architecture.
Figure 54. A network can reconstruct a stored pattern from a related input. This is a historical architecture. CSE101 Week 12, slide 90. Source slide.
Follow the successive states. Associative memory here differs from next-token generation.
Figure 55. Follow the successive states. Associative memory here differs from next-token generation. CSE101 Week 12, slide 91. Source slide.

Trace the network output before and after each pictured adjustment. Correcting one XOR input can disturb another, so one successful example is not a completed learning task. Evaluate the whole intended truth table. The associative-memory figures then illustrate a different historical architecture that moves through configurations toward a stored pattern. Do not identify that settling process with autoregressive next-token generation.

Check: If a changed weight fixes one previously wrong input, is it safe to stop testing?

No. Recheck the other inputs. Shared parameters influence more than the example used to choose the change.

25. Optional: original structure procedures

The source uses pseudocode. The C version checks the pointer before accessing the node.
Figure 56. The source uses pseudocode. The C version checks the pointer before accessing the node. CSE101 Week 12, slide 92. Source slide.
Each comparison chooses a subtree. This is a reference algorithm.
Figure 57. Each comparison chooses a subtree. This is a reference algorithm. CSE101 Week 12, slide 93. Source slide.
Trace the progressively smaller subtrees in the original example.
Figure 58. Trace the progressively smaller subtrees in the original example. CSE101 Week 12, slide 94. Source slide.
Each call handles one subtree. The empty subtree supplies the stopping case.
Figure 59. Each call handles one subtree. The empty subtree supplies the stopping case. CSE101 Week 12, slide 95. Source slide.
Advanced reference. Tree implementation is not required for this week’s list exercise.
Figure 60. Advanced reference. Tree implementation is not required for this week’s list exercise. CSE101 Week 12, slide 96. Source slide.
Original Java/C# illustration for comparison. The C lecture does not require class syntax.
Figure 61. Original Java/C# illustration for comparison. The C lecture does not require class syntax. CSE101 Week 12, slide 97. Source slide.

The original traversal and tree algorithms are retained for enlarged restudy. Read their stopping conditions before their recursive or iterative steps. The C traversal in the main text tests the pointer before accessing a member. The original stack class uses Java/C# notation for comparison; class syntax is not a requirement for the C examples.

Check: What is the stopping case for a recursive traversal of a pointer-based binary tree?

An empty subtree, usually represented by NULL. It should return without accessing node fields.

26. Sources and further study

The reading follows the accepted 99-slide Week 12 deck and preserves all of its teaching images. Original AI figures come from the supplied Brookshear tenth-edition slides; the accompanying book is the twelfth Global Edition. Figure numbering differs between editions. Data-structure images come from the instructor’s original collection. The local figure manifest records exact source parts and inherited notes.

A useful review task is to compare two kinds of graph: a search-state graph and a linked data structure in memory. In each case explain what a node means, what a link means, why cycles matter and what information an algorithm must retain. Similar-looking arrows can represent very different relationships.

Search courses