For example, this tree:
5
/ \
2 1
/ \ / \
14 13 9 6
/ /
10 12
Code in the language of your choice, and include declarations of your data structures (plural).
int hash(int key)
a) Write a function which locates the node containing a specified search key, and returns a pointer to the node (or NULL).
b) Write a function which deletes the node containing a specified search key. The delete function must utilize the find function in part a). If the node does not exist, do nothing.
Code in the language of your choice, and include the declaration of your data structure. Each list has a dummy header that you can assume is always present. Do not worry about returning the node to memory.
// Global Variables, initialized once:
int readcount = 0;
boolean readOK = true;
boolean writeOK = false;
Readers: Writer:
while (true) { while (true) {
while (!readOK) {} while (!writeOK) {}
readcount++;
// read data section // write data section
readcount--;
if (readcount == 0) {
readOK = false; writeOK = false;
writeOK = true; readOK = true;
}
} }
Answer the following questions YES/NO, with an explanation.
Is it possible (perhaps after an initial period) to get into a situation such that:
a) data is read AND written at the same time (i.e. no mutual exclusion)?
b) ONLY data is read (i.e. not fair to the writer)?
c) ONLY data is written (i.e. not fair to the readers)?
d) NO data is read or written (i.e. no progress)?
a) LRU = FIFO = OPT. That is, all three strategies behave exactly the same. In particular, the page reference string should be of length 6, and the final physical memory, starting from frame 0, should contain 3, 1, 2.
b) LRU = FIFO = LFU. In particular, the page reference string should be of length 6, and the final physical memory, starting from frame 0, should contain 3, 1, 2.
c) LRU = OPT <> FIFO. In particular, the page reference string should be of length 7, and the final physical memory, starting from frame 0, should contain:
LRU = OPT: 0, 3, 2
FIFO: 3, 1, 2
int sum(int len, int nums[]) {
int result = 0;
// DRAW STACK HERE
for (int i = 0; i < len; i++)
result = result + nums[i];
return result;
}
int main() {
int list[] = {10, 30, 20}; // list starts at address 0x22ff60
int length = 3; // at address 0x22ff6c
int x = sum(length, list);
// rest of program omitted
}
Draw the stack assuming each of the following parameter passing mechanisms:
a) call-by-value
b) call-by-reference
Assume that BOTH parameters to "sum" follow the specified mechanism. Be sure to include all types of information that would appear in the stack.
[WARNING: the syntax matches C/C++ and is close to Java, but the semantics of the parameter passing mechanisms is not tied to any language.]
a) Write a recursive routine to perform depth-first-search traversal on G. Declare any data structures, including their initialization. Assuming a specified starting node, give the initial call. Code in the language of your choice.
b) State in BIG-THETA terms the runtime of your routine as a function of V and E.
a) Does this language have a context free grammar? Either write a grammar or show that there is no such grammar.
b) Does this language have a regular expression or deterministic finite automaton? Either write a regular expression (or deterministic finite automaton) or show that one does not exist.