Problem Detail: When getting source array length, I want to generate the array of swaps that need to be performed in order to sort the source array. I want to make this array as small as possible. Swaps will be performed Read More …
Category: Uncategorized
Given a set of sets, find the smallest set(s) containing at least one element from each set
Problem Detail: Given a set $mathbf{S}$ of sets, I’d like to find a set $M$ such that every set $S$ in $mathbf{S}$ contains at least one element of $M$. I’d also like $M$ to contain as few elements as possible while Read More …
Solving the recurrency $T(n) = 2T(sqrt{n}) + O(1)$
Problem Detail: I need to solve the following recurrency: $T(n) = 2T(sqrt{n}) + O(1)$. It’s for a simple undergrad problem that a student asked me, but I really couldn’t solve it. Since it is for an undergrad question, it would be Read More …
What is the average height of a binary tree?
Problem Detail: Is there any formal definition about the average height of a binary tree? I have a tutorial question about finding the average height of a binary tree using the following two methods: The natural solution might be to take Read More …
Algorithm to find all 2-hop neighbors lists in a graph
Problem Detail: Given a graph $G = (V,E)$, where $|V| = n$. What is a fast algorithm for generating the collection of all 2-hop neighborhood lists of all nodes in $V$. Naively, you can do that in $O(n^3)$. With power of Read More …
Give CFG and PDA for the words that start and end with the same symbol
Problem Detail: I need to give a PDA and CFG for a language that contains all binary strings that start and end with the same symbol. I’ve created the CFG with no problem, but I’m stuck with the PDA and don’t Read More …
Can someone clarify this unification algorithm?
Problem Detail: I’ve been having trouble understanding a unification algorithm for first order logic, as I don’t know what a compound expression is. I googled it, but found nothing relevant. I also don’t know what a list means in this context. Read More …
Can I use breadth-first search for topological sorting?
Problem Detail: Can I use breadth-first search for topologicallly sort vertices and finding strongly connected components in a graph? If yes, how can I do that? If not, why? I tried with a simple acyclic graph of 3 vertices, gave the Read More …
Why does the splay tree rotation algorithm take into account both the parent and grandparent node?
Problem Detail: I don’t quite understand why the rotation in the splay tree data structure is taking into account not only the parent of the rating node, but also the grandparent (zig-zag and zig-zig operation). Why would the following not work: Read More …
How many max heaps are there?
Problem Detail: How many different max-heaps can I form using a list of $n$ integers. Example: list [1,2,3,4] and max-heap is 4 3 2 1 or 4 / 3 2 / 1 other possible max-heap is 4 2 3 1 4 Read More …