EzDevInfo.com

tree interview questions

Top tree frequently asked interview questions

Unable to show a Git tree in terminal

Killswitchcollective.com's old article, 30 June 2009, has the following inputs and outputs

git co master
git merge [your_branch]
git push

upstream    A-B-C-D-E            A-B-C-D-E-F-G
                 \        ---->               \
your branch       C-D-E                        G

I am interested how you get the tree like-view of commits in your terminal without using Gitk or Gitx in OS/X.

How can you get the tree-like view of commits in terminal?


Source: (StackOverflow)

Graph Search vs Tree Search

I am curious whether there is the basic difference between graph search and tree search versions regarding DFS, A* Searches in Artificial Intelligence?


Source: (StackOverflow)

Advertisements

Java tree data-structure?

Is there a good available (standard Java) data structure to represent a tree in Java?

Specifically I need to represent the following:

  • The tree at any node can have an arbitrary number of children
  • Each node (after the root) is just a String (whose children are also Strings)
  • I need to be able to get all the children (some sort of list or array of Strings) given an input string representing a given node

Is there an available structure for this or do I need to create my own (if so implementation suggestions would be great).


Source: (StackOverflow)

Why does the C++ STL not provide any "tree" containers?

Why does the C++ STL not provide any "tree" containers, and what's the best thing to use instead?

I want to store a hierarchy of objects as a tree, rather than use a tree as a performance enhancement...


Source: (StackOverflow)

What's the difference between the data structure Tree and Graph?

Academically speaking, what's the essential difference between the data structure Tree and Graph? And how about the tree based search and Graph based search?


Source: (StackOverflow)

How to efficiently build a tree from a flat structure?

I have a bunch of objects in a flat structure. These objects have an ID and a ParentID property so they can be arranged in trees. They are in no particular order. Each ParentID property does not necessarily matches with an ID in the structure. Therefore their could be several trees emerging from these objects.

How would you process these objects to create the resulting trees ?

I'm not so far from a solution but I'm sure it is far from optimal...

I need to create these trees to then insert Data into a database, in proper order.

There are no circular references. A Node is a RootNode when ParentID == null or when ParentID can't be found in the other objects


Source: (StackOverflow)

What are the differences between segment trees, interval trees, binary indexed trees and range trees?

What are differences between segment trees, interval trees, binary indexed trees and range trees in terms of:

  • Key idea/definition
  • Applications
  • Performance/order in higher dimensions/space consumption

Please do not just give definitions.


Source: (StackOverflow)

When to use Binary Space Partitioning, Quadtree, Octree?

I have recently learned about binary space partitioning trees and their application to 3d graphics and collision detection. I have also briefly perused material relating to quadtrees and octrees. When would you use quadtrees over bsp trees, or vice versa? Are they interchangeable? I would be satisfied if I had enough information to fill out a table like this:

            | BSP | Quadtree | Octree
------------+----------------+-------
Situation A |  X  |          |
Situation B |     |     X    |
Situation C |     |          |   X

What are A, B, and C?


Source: (StackOverflow)

When to choose RB tree, B-Tree or AVL tree?

As a programmer when should I consider using a RB tree, B- tree or an AVL tree? What are the key points that needs to be considered before deciding on the choice?

Can someone please explain with a scenario for each tree structure why it is chosen over others with reference to the key points?


Source: (StackOverflow)

Non recursive Depth first search algorithm

I am looking for a Non recursive Depth first search algorithm for a non binary tree. Any help is very much appreciated.


Source: (StackOverflow)

Database Structure for Tree Data Structure

What would be the best way to implement a customizable (meaning, a tree structure with an unknown number of level) tree data structure in a database?

I've done this once before using a table with a foreign key to itself.

What other implementations could you see, and does this implementation make sense?


Source: (StackOverflow)

ASCII Library for Creating "Pretty" Directory Trees?

Is there some *nix tool or perl/php library that will let you easily create directory tree visualizations that look like the following?

www
|-- private
|    |-- app 
|    |    |-- php
|    |    |    |-- classes
|    |    |    +-- scripts
|    |    |-- settings
|    |    +-- sql
|    +-- lib
|         +-- ZendFramework-HEAD
+-- public
	|-- css
	|-- images
	+-- scripts

Source: (StackOverflow)

How can I implement a tree in Python? Are there any built in data structures in Python like in Java?

I am trying to construct a general tree. Are there any built in data structures in Python to implement a tree?


Source: (StackOverflow)

What is the difference between tree depth and height?

This is a simple question from algorithms theory. The difference between them is that in one case you count number of nodes and in other number of edges on the shortest path between root and concrete node. Which is which?


Source: (StackOverflow)

Detect differences between tree structures

This is more of a CS question, but an interesting one :

Let's say we have 2 tree structures with more or less the same nodes reorganized. How would you find

  1. any
  2. in some sense minimal

sequence of operations

  • MOVE(A, B) - moves node A under node B (with the whole subtree)
  • INSERT(N, B) - inserts a new node N under node B
  • DELETE (A) - deletes the node A (with the whole subtree)

that transforms one tree to the other.

There might obviously be cases where such transformation is not possible, trivial being root A with child B to root B with child A etc.). In such cases, the algorithm would simply deliver an result "not possible".

Even more spectacular version is a generalization for networks, i.e. when we assume that a node can occur multiple times in the tree (effectively having multiple "parents"), while cycles are forbidden.

Disclaimer : This is not a homework, actually it comes from a real business problem and I found it quite interesting wondering if somebody might know a solution.


Source: (StackOverflow)