Question Detail: I need to know what class of CFL is closed under i.e. what set is complement of CFL. I know CFL is not closed under complement, and I know that P is closed under complement. Since CFL $subsetneq$ P Read More …
Blog
What algorithm would compute the maximum choices from two sets?
Question Detail: Given two vectors of integers of possibly unequal lengths, how can I determine the maximum result possible from accumulating choosing the maximum between corresponding pairs of numbers between the two vectors with extra zeros inserted into the shorter vector Read More …
Constructing a binary tree with given traversals
Question Detail: I have given a post order & in order traversal a BST & I need to construct it. I want to know how to do this. for eg. Post Order : DCBGFEA In Order : BDCAFGE This is how Read More …
Given the logical address, how to extract the page number?
Question Detail: I am studying Computer Systems. I have th following question and its answer: Given the logical address 0xAEF9 (in hexadecimal) with a page size of 256 bytes, what is the page number? Answer: 0xAE (I found this answer in Read More …
Left-Factoring a grammar into LL(1)
Question Detail: I have a homework assignment where I need to convert a grammar into LL(1). I’ve already removed the left recursion, but I’m having trouble doing left-factoring. All of the examples I’ve found are simple, and look something like this: Read More …
How to fool the "try some test cases" heuristic: Algorithms that appear correct, but are actually incorrect
Question Detail: To try to test whether an algorithm for some problem is correct, the usual starting point is to try running the algorithm by hand on a number of simple test cases — try it on a few example problem Read More …
How does the 3-opt algorithm for TSP work?
Question Detail: I understand that the 3-Opt Heuristic for solving the Traveling Salesman problem involves removing three edges from a graph and adding three more to recomplete the tour. However, I’ve seen many papers that mention that when three edges are Read More …
Maximum number of nodes with height h
Question Detail: How is $frac{n}{2^{h+1}}$ the maximum possible number of nodes at height $h$ for a binary search tree or heap tree? I saw this as proof to asymptotically bound the build_heap function in the book, but I don’t get it. Read More …
DFA for exactly two of a and one or more of b
Question Detail: I’m totally new to DFA’s and automaton in general — this is the first week or two of class that I’ve actually seen this — and I’m curious as to a pattern to match the following: “Match the set Read More …
What is the most efficient way to compute factorials modulo a prime?
Question Detail: Do you know any algorithm that calculates the factorial after modulus efficiently? For example, I want to program: for(i=0; i<5; i++) sum += factorial(p-i) % p; But, p is a big number (prime) for applying factorial directly $(p leq Read More …