Rob Pike's Simple Regular Expressions
I came across an article by Brian Kernighan. The article is about a piece of C code written by Rob Pike, apparently for a book Pike and Kernighan wrote together, The Practice of Programming.
I came across an article by Brian Kernighan. The article is about a piece of C code written by Rob Pike, apparently for a book Pike and Kernighan wrote together, The Practice of Programming.
The old Daily Coding Problem email list gave us this problem around 2020:
Daily Coding Problem: Problem #237 [Easy]
A tree is symmetric if its data and shape remain unchanged when it is reflected about the root node. The following tree is an example:
4
/ | \
3 5 3
/ \
9 9
Given a k-ary tree, determine whether it is symmetric.
This problem is less well described than I thought when I worked on it in 2020.
There’s an older programming job interview question:
Given a string of round, curly, and square open and closing brackets, return whether the brackets are balanced (well-formed).
For example, given the string “([])”, you should return true.
Given the string “([)]” or “((()”, you should return false.
I found a set of linked list coding problems I’d never seen before.
The document is titled Linked List Problems, written and copyright by Nick Parlante, dated 2002. Apparently Linked List Problems is part of the Stanford CS Education Library, which looks to date to around the end of the 20th Century.
.Data values, or arbitrarily changing .Next pointers
does not cause the performance drops.
I looked for other anomalies, too.
What happens if you compare the number of comparisons made by recursive and wikipedia bottom up algorithms if the initial list is pre-sorted (low data value to high data value) or reverse sorted (high data value to low).
My recursive mergesort algorithm, and the wikipedia bottom-up) algorithm read and write the same list nodes in the same order, for list lengths that are powers of two. Something other than mere data reading and pointer writing causes abrupt performance drops at linked list lengths of 2N+1 nodes.
I decided to count the number of comparisons used in merging lists. I had to write a different program so as to use an unsorted list with data in the same randomly chosen order for each of the three algorithms.
I tried several minor variations of recursive mergesort to try to understand the abrupt performance drops that my iterative mergesort code exhibits at some linked list lengths.
I wrote variants of recursive mergesort that simulate function call recurision by iteration with an explicit stack of activation records. This is an effort to try to understand the abrupt performance drops that the wikipedia bottom up algorithm exhibits at some linked list lengths.
Incidentally, these two algorithms both satisfy the Daily Coding Problem problem statement. Their simulated call stack could potentially overflow for extremely long lists, but those stacks wouldn’t have to be much bigger to accomodate those long lists.
I finally looked at the addresses of linked list nodes that my recursive and wikipedia bottom-up) algorithms read and write.