Code execution trace
Code line, i/j pointer movement, lps fallback, and return i-j.
This lesson uses a browser-generated execution trace to connect code branches, pointer movement, boundary conditions, and the final return value in one repeatable walkthrough.
Step through code, memory, stack frame, and CPU stage without loading a video file.
Step through the same trace without loading a video file. The code line, memory cells, CPU stage, and stack frame are all rendered from structured data.
func strStr(haystack, needle string) int {// entry n := len(haystack)// text length m := len(needle)// pattern length if m == 0 { return 0 }// empty pattern if n < m { return -1 }// impossible lps := buildLPS(needle)// pattern memory i, j := 0, 0// two pointers for i < n {// i only moves right if haystack[i] == needle[j] {// current chars equal i++ j++// advance together } else if j > 0 {// some prefix matched j = lps[j-1]// i does not move } else { i++// no memory } if j == m { return i-j }// return start } return -1// not found}The abstract machine starts by placing i, j, n, and m in the stack frame.
The rendered MP4 versions stay available while the HTML player is being evaluated.
Code line, i/j pointer movement, lps fallback, and return i-j.
Program counter, stack frame, memory reads, branch decision, and write-back.
Why empty needle returns 0, and why longer needle returns -1 before KMP starts.
How i, length, and lps change when the pattern compares with itself.
Why j falls back through lps while haystack's i stays where it is.
Keep generated videos as versioned static assets under public/learning.
Use one topic page per concept so each video has transcript, checkpoints, and follow-up practice.
Start noindex for prototypes, then link from Resources or Learning Plans after the format works.