1. Data structure

Set structure linear structure tree structure graph structure

1.1, set structure is a set, is a circle with a lot of elements, elements and elements do not have any relationship between this is very simple

1.2 linear structure is a line standing a lot of individuals. This line doesn’t have to be straight. It could be bent. It can also be the equivalent of a line divided into sections (use your imagination). A linear structure is a one-to-one relationship

To put it plainly, developers must know that XML parsing trees are more or less similar to him. You can also imagine a pyramid. The tree structure is a one-to-many relationship

This one is more complicated. He is infinite. You can think of many-to-many as kind of like the intersection of people

Storage of data structures

There are two kinds of sequential storage structure and chain storage structure commonly used in data structure

2.1 Sequential storage structure

Use your imagination. Take an example. The array. The 1-2-3-4-5-6-4-5-6-10. So this is a sequential storage structure, storage is in order to illustrate. Stacks, those of you who do development are familiar with them. The stack is first in last out, last in first out, right?

You can think of it this way, hello world in the stack from the bottom of the stack to the top of the stack is h-E-L-L-O-W-O-R-L-D and that’s sequential storage, and the queue, the queue is first in first out, right, from beginning to end, h-E-L-L-O-W-O-R-L-D and that’s the way it’s sorted

2.2 Chain storage structure

Again, imagination, this is a little bit more complicated and this is an image that I’ve been working on, and I go back to the artist and I say, With the For example, Or an array of 1-2-3-4-5-6-1-2-3-10 chain stores are different (address) (1-2 (address) to 7 (address) (address) – 4-5 (address) – 9 (address) to 8 (address) – 3-6 (address) (address) to 10 (address). Each of these numbers is followed by an address and it’s not stored in order anymore, so it’s out of order, so the address after 1 refers to 2 and the address after 2 refers to 3 and the address after 3 refers to who you get the idea. He performs is 1-2 (address) (address) to 3 (address) (address) – 4-5 (address) – 6-7 (address) (address) – 8 (address) – 9 (address) to 10 (address), but the store is completely random. I see?

Unidirectional linked list, bidirectional linked list, circular linked list

Again, an example. Understanding is the most important. Don’t learn things by rote. Definition. Logic. Understanding is the most important thing

3.1 Unidirectional Linked List

A->B->C->D->E->F->G-> h. This is A unidirectional linked list. H is the head and A is the tail. It’s like A train with only one head and can only be pulled by one head

3.2 Two-way linked list

The difference between arrays and linked lists:

Array: Array elements are stored continuously in memory, and can be found by subscript; Inserting or deleting requires a large number of elements to be moved, and is more applicable when the elements rarely change

Linked list: the elements in the list are not stored in order in memory, the search is slow, the insertion and deletion only need to re-assign the element pointer, high efficiency

3.3 Circular linked list

Circular linked list is the same as unidirectional linked list, is a chain type storage structure, the difference is that the last node of the circular linked list pointer is pointing to the first node of the circular linked list or table head node, thus forming a circular chain. A->B->C->D->E->F->G->H->A. Make a circle. It’s like a snake eats its own. It’s a cycle. You don’t have to learn anything by rote.

Binary tree/balanced binary tree

4.1 What is a binary tree

In a tree structure, it’s called a binary tree between two nodes. There’s no node greater than two that can be divided into a left subtree and a right subtree. You can’t reverse the order. I speak in mandarin again now, you see the binary tree as a person, the head of the people is the root of the tree, the left subtree is his left hand, right subtree is right hand, right hand can have (disability, record, no discrimination against disabled friends, don’t blame, don’t blame is, for example, I am very sorry), and both can have one, It can’t be upside down. That should make sense

There are five forms of binary trees

1. Empty trees (no nodes) can understand why they are not like air

2. Only the root node is available. (Understand that a person has only one head and nothing else, it’s a little scary to say)

3. Only left subtree (one first and one left)

4. Only the right subtree

5. Both left and right subtrees

A binary tree can be converted into a forest tree or a binary tree. I’m not going to go into this because you don’t really need data structures for your projects but I’m going to go through that. Understanding, not memorizing. What’s the use of memorizing

(1) What is the algorithm for the interview?

1. Swap the values of A and B in two ways, without using an intermediate variable

As a developer, it is particularly important to have a learning atmosphere circle, this is one of my iOS developers public number: Programming Daxin, whether you are small white or big ox are welcome to enter, let us progress together, common development! 支那

**2, ** find the greatest common divisor

3. Simulate stack operations

Stack is a data structure characterized by: first in, then out –

Exercise: Simulate stack operations using global variables

#include <stdio.h>

#include <stdbool.h>

#include <assert.h>

Static int data[1024] = static int data[1024]; // The stack can hold up to 1024 pieces of data

static int count = 0; // How many numbers have been placed (equivalent to the top of the stack)

4. Sorting algorithm

Selection sort, bubble sort, insertion sort three sort algorithms can be summarized as follows:

Both divide the array into sorted and unsorted parts.

1. Select sort to define the sorted part on the left, and then select the smallest element of the unsorted part to exchange with the first element of the unsorted part.

2. Bubble sort defines the sorted part at the right end, and performs an exchange during the process of traversing the unsorted part, swapping the largest element to the right end.

3. Insertion sort defines the sorted part at the left end and inserts the first element of the unsorted part into the appropriate position of the sorted part.

4.1. Select sort

[Selection sort] : The most value appears at the beginning

The first trip: find the smallest (large) number among n numbers to switch positions with the first number

Second trip: find the smallest (large) number to switch positions with the second number among the remaining n-1 numbers

Repeat this operation… The third, the fourth… Number switching position

N -1, finally can realize the ascending (descending) order of data.

4.2 bubble sort

[Bubble sort] : Comparison of adjacent elements in pairs. After a comparison, the most value appears at the end

The first trip: compare the two adjacent numbers in turn, constantly switching (before the decimal number, after the large number) advance one by one, the most value finally appears in the NTH element position

The second trip: compare the two adjacent numbers in turn, constantly switching (before the decimal number, after the large number) advance one by one, the most value finally appears in the n-1 element position

… …

N -1 trip: compare two adjacent numbers in sequence, constantly switching (before the decimal number, after the large number) advance one by one, the most value finally appears in the second element position

5, half search (binary search)

Split search: Optimizes the search time (without traversing all the data)

1. The array must be ordered

2. Min and Max must be known (know range)

3. Calculate the value of MID dynamically and take out the value corresponding to MID for comparison

4. If the value of mid is greater than the value to be searched, then Max should be reduced to mid-1

5. If mid is less than the value we are looking for, then min must be greater than mid+1

// Given an ordered array and a key, we need to find the index of the key in the array

3. Algorithmic Interview Questions (2)

String inversion

Given the string “Hello,world”, the implementation inverts it. Output: DLrow,olleh

Ordinal Numbers combine

Will be an orderly array,4,6,7,9 {1} and {2,3,5,6,8,9,10,11,12} into,2,3,4,5,6,6,7,8,9,9,10,11,12 {1}

The HASH algorithm

Hash table

Example: given the letter a, the corresponding ASCII code value is 97, and the array index subscript is 97.

ASCII code here, even a hash function, storage and search through the function, effectively improve the efficiency of search.

Finds the first character in a string that occurs only once. For example, the input “abaccdeff”, the output ‘b’ character (char) is a data type of length 8, so there are 256 possibilities. Each letter is a number in the array subscript according to its ASCII code value. The array stores the number of occurrences of each character.

Find the common superview of the two child views

Record all the superviews of the two subviews separately and save them in an array, then search in reverse order until you find the first different superview.

Find the median in an unordered array

Median: when the number of arrays n is odd, it is (n + 1)/2, that is, the middle number; When n is even, it is (n/2 + (n/2 + 1))/2, which is the average of the middle two numbers.

First of all, let’s look at some sorting algorithms :iOS sorting algorithms

Ideas:

1. Sorting algorithm + median

First use bubble sort, quick sort, heap sort, hill sort and other sorting algorithms to sort the array, and then take out the digit.

2. Use quicklist thinking

Iv. Data security and encryption

1. Describe what encryption methods are used in the SSL encryption process and why?

The SSL encryption process has been covered before and will not be covered here.

SSL encryption actually uses a combination of symmetric and asymmetric encryption in the process.

The main consideration is to use asymmetric encryption for the connection in the first place to avoid a man-in-the-middle attack in which the key is hijacked, but asymmetric encryption is less efficient. So once a secure connection is established, you can use lightweight symmetric encryption.

2. RSA asymmetric encryption

Symmetric encryption [algorithm] uses the same key for encryption and decryption; The asymmetric encryption algorithm requires two keys, the public key and the private key, for encryption and decryption.

RSA encryption

Unlike symmetric encryption, asymmetric encryption requires two [keys] : [publickey] and [privatekey]. The public key and private key are a pair. If the public key is used to encrypt data, only the corresponding private key can be used to decrypt data. If the data is encrypted with a private key, only the corresponding public key can be used to decrypt it. Because encryption and decryption use two different keys, this algorithm is called asymmetric encryption.

RSA encryption principle **

RSA is a commonly used encryption mode, and its encryption principle can be briefly discussed in the following examples.

Take two random primes

That’s all for this post. Thanks for watching!