This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class Pair { | |
public int val; | |
public int cnt; | |
public Pair(int v, int c) { | |
this.val = v; | |
this.cnt = c; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xun@xun-DVM:~/CS6253-Distributed-OS/TutorialTest/gen-cpp$ g++ -DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H -Wall -I/usr/local/include/thrift *.cpp -L/usr/local/lib -lthrift -o Calculator | |
Calculator_server.skeleton.cpp: In member function ‘virtual int32_t CalculatorHandler::add(int32_t, int32_t)’: | |
Calculator_server.skeleton.cpp:33:3: warning: no return statement in function returning non-void [-Wreturn-type] | |
} | |
^ | |
Calculator_server.skeleton.cpp: In member function ‘virtual int32_t CalculatorHandler::calculate(int32_t, const tutorial::Work&)’: | |
Calculator_server.skeleton.cpp:38:3: warning: no return statement in function returning non-void [-Wreturn-type] | |
} | |
^ | |
Calculator_server.skeleton.cpp: In function ‘int main(int, char**)’: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Chapter 4 | |
4.9 You are given a binary tree in which each node contains an integer | |
value (which might be positive or negative). Design an algorithm to | |
print all paths which sum to a given value. The path does not need | |
to start or end at the root or a leaf, but it must go in a straight | |
line down. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Chapter 4 | |
4.8 You have two very large binary tree: T1, with millions of nodes, and T2, with hundreds of nodes. | |
Create an algorithm to decide if T2 is a subtree of T1. | |
A tree T2 is a subtree of T1 if there exist a node n in T1 such that the subtree of n is identical | |
to T2. That is, if you cut off the tree at node n, the tow trees would be identical. | |
*/ | |
/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Chapter 4 | |
4.7 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. | |
*/ | |
// Assumption: when p is one ancestor of q's, we say p is the first common | |
// ancestor of p, q |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Chapter 4 | |
4.6 Write an algorithm to find the 'next' node (i.e., in-order successor) | |
of a given nodes in a binaru search tree. You may assume that each node | |
has a link to its parent. | |
*/ | |
#include <iostream> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Chapter 4 | |
4.5 Implement a function to check if a binary tree is a binary search tree. | |
*/ | |
#include <iostream> | |
#include <stack> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Chapter 4 | |
4.4 Given a binary tree, design an algorithm which creates a linked | |
list of all the nodes at each depth. (e.g., if you have a tree with | |
depth D, you'll have D linked lists.) | |
*/ | |
#include <iostream> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Chapter 4 | |
* 4.3 Given a sorted (increasing order) array with unique integer elements, | |
* write an algorithm to create a binary search tree with minimal height. | |
*/ | |
/* Recursive way to solve this problem */ | |
#include <iostream> | |
using namespace std; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Chapter 4 | |
* 4.2 Given a directeed graph, design an algorithm to find out | |
* whether there is a route between two nodes. | |
*/ | |
#include <iostream> | |
#include <queue> | |
#include <list> |
NewerOlder