### Blogroll

### Topics

- Array and linked list
- Backtrack
- Binary search
- Bit operation
- C++
- Complexity
- Divide and Conquer
- Dynamic programming
- File operation
- Geometry
- Graph
- Greedy algorithm
- Hashtable and Map
- Heap
- JAVA
- Large scale data
- Number trick
- Object orientated design
- Probability
- Recursive
- Stack and Queue
- String
- Threads and locks
- Tree
- Uncategorized

### Archives

# Category Archives: File operation

## Saving a binary search tree to a file

Describe an algorithm to save a Binary Search Tree (BST) to a file in terms of run-time and disk space complexity. You must be able to restore to the exact original BST using the saved format. C++: 01 void BSTtoFile(Node* head, ofstream& … Continue reading

Posted in File operation, Recursive, Tree
Leave a comment

## Serialization/Deserialization of a binary tree

Design an algorithm and write code to serialize and deserialize a binary tree. Writing the tree to a file is called ‘serialization’ and reading back from the file to reconstruct the exact same binary tree is ‘deserialization’. C++: 01 void treeToFile(Node* … Continue reading

Posted in File operation, Recursive, Tree
Leave a comment

## Print the last k line.

Write a method to print the last K lines of an input file using C++. C++: 01 void printLastKline(string filename, int k) 02 { 03 ifstream in(filename.c_str()); 04 if(in.fail()){ 05 cout<<“fail!!!”<<endl; 06 in.clear(); 07 … Continue reading

Posted in File operation
Leave a comment