OS:
1: The difference between process and thread? Can multiple threads/processes share memory?
Ans: 1) A process is an executing instance of an application. A thread is a pathofexecutionwithin a process. Also, a process can contain multiple threads.
2) Threads (of the same process) run in a shared memory space, while processes run in separate memory spaces. This allows threads to read from and write to the same data structures and variables, and also facilitates communication between threads.
3) A thread can do anything a process can do. But threads are used for small tasks, whereas processes are used for more ‘heavyweight’ tasks – basically the execution of applications.
How does synchronization between threads work?
2: Where are local variables stored in memory? Ans: Stack
3: What happens in OS when one function calling another function?
Data structure:
1: Remove an item in a linked list. Time Complexity.
2: What is a BST? Traverse a BST iteratively. Time Complexity to remove a node from a BST.
BST properties:
- The left subtree of a node contains only nodes with keys less than the node's key.
- The right subtree of a node contains only nodes with keys greater than the node's key.
- The left and right subtree each must also be a binary search tree.
- There must be no duplicate nodes.
Traverse a BST iteratively. O(n)
- 1) Create an empty stack S.
- 2) Initialize current node as root
- 3) Push the current node to S and set current = current->left until current is NULL
- 4) If current is NULL and stack is not empty then
- a) Pop the top item from stack.
- b) Print the popped item, set current = current->right
- c) Go to step 3.
- 5) If current is NULL and stack is empty then we are done.
/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<int> inorderTraversal(TreeNode *root) {
stack<TreeNode*> s;
vector<int> res;
if (!root) return res;
TreeNode *cur=root;
while (cur || s.size()) {
while (cur) {
s.push(cur);
cur = cur->left;
}
cur = s.top();
s.pop();
res.push_back(cur->val);
cur=cur->right;
}
return res;
}
};
3: Difference between stack and queue. Which data structure can be used to build stack? How to build? Time Complexity to push or pop.
Networking:
1: Difference between TCP and UDP.
2: Difference between RIP and OSPF. Advantages of them.
RIP (Routing Information Protocol) is a Distance vector routing protocol based onBellman-Ford algorithm. Each router on the network complies a list ofnetworks it can reach and exchange with its neighboring routers only. Upon receiving vectors form each of its neighbors, the router computes its own distance to each neighbor. Then for every network X, router finds that neighbor who is closer to X than to any other neighbor.Router updates its cost to X. After doing this for all networks, the router goes to the first step.
OSPF (Open Shortest Path First) is a link state routing protocol based on Dijkstra algorithm. Each router on the network is assumed to know the state of links to all its neighbors, and each router will broadcast this information about its link state to all routers in the network. Therefor, each router has enough information to build a complete map of the network andi able to construct a shortest path spanning tree form itself to every other node.
OSPF advantages:
It provides the shortest path and its loop-free.
It has the ability to scale up or down the number of IP packets that are sent at a time or within a time frame, so that it's more scalable and can be used in large network.
The main reason behind the OSPF protocol being faster is that whenever changes are made in the routing tables, only the new or updated values are transferred, instead of sending the entire code.
3: What ARP used for?
Determine the MAC address of its IP address. ARP is at the link layer.
4: How dose
ping work?
The ping command is a method for troubleshooting the accessibility of devices to determine whether a remote host is active or inactive, the round-trip delay in communicating with the host, and the packet loss. It sends one datagram per second and prints one line of output for every response received. It calculates round-trip times and packet loss statistics, and displays a brief summary on completion. It completes when the program times out or on receipt of a SIGINT signal. The Host parameter is either a valid host name or Internet address.
The protocol used for ping is ICMP (Internet Control Message Protocol) at the network layer. To ping a host you first send an ICMP Echo Request Packet, the host will then reply with an ICMP Echo Reply. ICMP messages are typically used for diagnostic or control purposes or generated in response to errors in IP operations.Plus, the traceroute (by using UDP) command can be used to discover the routers along the path that packets are taking to a destination.
就记得这么多了,总的来讲印度哥哥还是蛮nice哒~
理解进程与线程的本质及操作
本文深入探讨了进程与线程的概念区别,详细解释了它们如何共享内存空间及同步工作原理。同时,介绍了局部变量的存储位置、函数调用时的操作流程,并通过实例展示了二叉搜索树的迭代遍历方法。此外,还对比了TCP与UDP、RIP与OSPF这两种网络协议的特性及优势。最后,阐述了ARP协议的作用和ping命令的工作机制。
2936

被折叠的 条评论
为什么被折叠?



