Given a binary search tree, design an algorithm which creates a linked list of all the nodes at each depth (i e , if you have a tree with depth D, you’ll have D linked lists) #include <iostream> using namespace std; typedef int Data;
Write an algorithm to find the ‘next’ node (i e , in-order successor) of a given node in a binary search tree where each node has a link to its parent #include <iostream> using namespace std; typedef int Data; struct Node {
Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree Avoid storing additional nodes in a data structure NOTE: This is not necessarily a binary search tree #include <iostream> using namespace std;
You have two very large binary trees: T1, with millions of nodes, and T2, with hundreds of nodes Create an algorithm to decide if T2 is a subtree of T1 #include <iostream> using namespace std; typedef int Data; struct Node {
CareerCup是一本相當好Code面試的書,開始研讀Description: Consider what problems the algorithm is similar to, and figure out if you can modify the solution to develop an algorithm for this problem Example: A sorted array has been rotated so that the elements might
You are given a binary tree in which each node contains a value Design an algorithm to print all paths which sum up to that value Note that it can be any path in the tree - it does not have to start at the root #include <iostream>#include
這個題刷起來感覺比編程之美什麼的easy多了Description: Solve the algorithm first for a base case (e g , just one element) Then, try to solve it for elements one and two, assuming that you have the answer for element one Then, try to solve it for elements one, two and
Question:Implement an algorithm to determine if a string has all unique characters What if you can not use additional data structures?#include <iostream>using namespace std;bool isUnique(char* s){ bool count[256]; for(int i=0; i<256;
Given a sorted (increasing order) array, write an algorithm to create a binary tree withminimal height#include <iostream>using namespace std;typedef int Data;struct Node{ Node(Data d):data(d){left = right = NULL;}; Data data; Node*