Original address: Github.com/kdn251/interviews translations from: Nuggets translation Program Translator: Wang invited the moon Bear Reviewer: phxnirvana, square root Three this link is used to see if there is a difference between this translation and the English version (if you don't see README.MD Change, that means the translation document is up to date. Interviews
Personal Guide for interviewing software engineering techniques.
Maintainer-kevin Naughton Jr.Other language versions中文版DirectoryOnline Practice online interview programming data structure algorithm bit arithmetic algorithm complexity analysis Video tutorials interview books computer science and technology information file structuresPractice OnlineLeetcode Virtual Judge careercup hackerrank codefights kattisOnline Interview ProgrammingGainlo RefdashData Structure linked ListA linked list is a linear set of nodes (node) that each node can use to point to other nodes. It is a data structure that contains multiple nodes and can be used to represent a sequence. One-way linked list: The nodes in the list point to only the next node, and the last node points to null. Bidirectional list: Each node has two pointers p, N, so that p points to the previous node and N points to the next node, and the last node's n pointer points to null. Loop list: Each node points to the next node and the last node points to the first node's list. Time complexity: Index: O (n) Search: O (n) Insert: O (1) Remove: O (1)StackA stack is a collection of elements that contains two basic operations: a push operation can be used to push elements into the stack, and pop operations can remove the top elements of the stack. Follow the back in first out (LIFO) principle. Time complexity: Index: O (n) Search: O (n) Insert: O (1) Remove: O (1)QueueA queue is a collection of elements that contains two basic operations: the Enqueue action can be used to insert elements into the queue, while the DEQUEEU action removes the elements from the queue. Follow the first in first out principle (FIFO). Time complexity: Index: O (n) Search: O (n) Insert: O (1) Remove: O (1) TreeA tree is a undirected, connected, loop-free graph.Binary TreeA binary tree is a tree-shaped data structure that contains up to two nodes of the left and right child nodes for each node. Full two fork tree: Each node in the tree contains only 0 or 2 nodes. Perfect binary (Perfect Binary tree): Each leaf node in a two-fork tree has two child nodes and has the same height. Complete binary tree: In addition to the last layer, the number of nodes on each layer reaches the maximum, and only a few nodes on the right are missing on the last level.Binary Search TreeA binary search tree (BST) is a special two-pronged tree in which values in any node are greater than or equal to the values stored in its left subtree and are less than or equal to the values stored in its right subtree. Time complexity: Index: O (log (n)) Search: O (log (n)) Insert: O (log (n)) Delete: O (log (n))
The Trie dictionary tree, also known as a cardinal tree or prefix tree, can be used to store a dynamic collection of key strings or a search tree of associative arrays. The node in the tree does not store the associated key value directly, but rather the mount position of the node in the tree determines its associated key value. All child nodes of a node have the same prefix, and the root node of the whole tree is an empty string.
Alt text
The Fenwick tree-like array, also known as the Binary Indexed tree, is expressed in the form of trees, but is essentially an array implementation. The subscript in the array represents the vertices in the tree, and the subscript of each vertex's parent node or child node can be obtained by bitwise operation. Each element in the array contains the sum of the calculated interval values, which are also updated during the entire tree update. Time Complexity: Interval evaluation: O (log (n)) Update: O (log (n))
Alt text
Segment Tree is a tree-shaped data structure for storing intervals or segments, which allows you to quickly find the number of times a node appears in several segments. Time Complexity: Interval query: O (log (n)) Update: O (log (n))
Alt text
The Heap heap is a special tree based data structure that satisfies certain attributes, and the key values of all parent-child nodes in the entire heap meet the same sorting criteria. The heap can be more accurately divided into the largest heap and the smallest heap, in the largest heap, the parent node's key value is always greater than or equal to the child node's value, and the maximum value in the entire heap stores the root node, while the parent node's key value is always less than or equal to its child node's key value, and the minimum value in the entire heap stores the root node. Time complexity: Access: O (log (n)) Search: O (log (n)) Insert: O (log (n)) Remove: O (log (n)) remove Max/min: O (1)
hashing hashes can map arbitrary-length data to fixed-length data. The hash function returns the hash value, which is called a collision if two different keys get the same hash value. Hash Map:hash map is a data structure that can establish the relationship between key and value, and hash map can use hash function to convert key into bucket or slot subscript, thus optimizing the search speed for target value. Collision resolution Chain Address method (separate chaining): In the chain address method, each bucket is independent of each other and contains a list of indexes. The time complexity of a search operation is the sum of the time (fixed time) of the search bucket and the time of the traversal list. Open Address method (open addressing): In the Open address method, when the new value is inserted, it will determine whether the corresponding hash bucket exists, if there is an algorithm in order to select the next possible location, until you find an address that has not yet been occupied. The open address method also means that the position of an element is not always determined by its hash value.
Alt text
Graph Graph is a data structure that is a many-to-many relationship between data elements, plus an abstract data type composed of a set of basic operations. undirected graph: A non-direction graph has a symmetric adjacency matrix, so if there is an edge from the node u to the node V, the opposite side from V to u exists. Directed graph: The adjacency matrix of a direction graph is asymmetrical, that is, if the existence of a side from U to V does not imply that there must be a side from V to U.
algorithm Sort Fast Sort Stability: No time complexity: Optimal time: O (Nlog (n)) Worst time: O (n^2) Average time: O (Nlog (n))
Alt text
Merge Sort merging sort is a typical divide-and-conquer algorithm, it continuously divides an array into two parts, sorts the Zoozi array and the right sub array, and then merges two arrays into a new ordered array. Stability: Time complexity: Optimal time: O (Nlog (n)) The worst time: O (Nlog (n)) Average time: O (Nlog (n))
Alt text
bucket Sort bucket sort will divide the array into a finite number of buckets. Each bucket is sorted individually (it is possible to use a different sort algorithm or to continue to sort by using a bucket sort recursively). Time complexity: Optimal time: Ω (n + k) Worst time: O (n^2) Average time: Theta (n + k)
Alt text
The cardinality sort cardinality sort resembles the bucket sort, dividing the array into a finite number of buckets, but it does not allow each bucket to be sorted separately after the split, but instead does a merge operation directly. Time complexity: Optimal time: Ω (NK) Worst time: O (NK) Average time: Theta (NK) graph algorithm Depth-First search depth-first algorithm is a priority to traverse the child node rather than backtracking algorithm. Complexity of Time: O (| v| + | e|)
Alt text
Breadth-First search breadth-First search is a graph traversal algorithm that prioritizes neighbor nodes rather than child nodes. Complexity of Time: O (| v| + | e|)
Alt text
topological sort topology sorting is a linear sort for a graph node, and if there is an edge from U to V, the subscript of U is assumed to be preceded by V. Complexity of Time: O (| v| + | e|) Dijkstra Algorithm The Dijkstra algorithm is used to compute the shortest path problem in a directed graph. Complexity of Time: O (| V|^2)
Alt text
Bellman-ford Algorithm The Bellman-ford algorithm is an algorithm for calculating the shortest path from a single source point to another node in a weighted graph. Although the complexity of the algorithm is greater than the Dijkstra algorithm, it is suitable for graphs that contain negative edges. Time complexity: Optimal time: O (| e|) Worst time: O (| v| | e|)
Alt text