Why the python web learns data structures and algorithms why do interviewers always ask those algorithms and linear table binary tree

Source: Internet
Author: User

What is the algorithm?

To give a simple example

That year Liu Jingsheng critically ill Liu Qi was involved in the succession of things helpless to Zhuge Liang

Above the ancient Bingshu to be invited by the Ming-hung loft talk ....

Zhuge Liang once said that the beginning of the book is Zhenfa from the heart

So the progress of ancient military advisers is also seen

The same is true of algorithms, although we as web back-end developers

But every day saw and heard the day long also adapted.

But I want to go further two ways.

Look at high-quality code

Two-look algorithm

We are not using many of the web development algorithms as possible

Every day that is, write interface interface and product manager tear

But the most important part of the algorithm is to help you expand your logical thinking.

Maybe the guy who just looked at the algorithm thought it was too hard for me to learn.

For example, it is the Dota2ti contest (I am also concerned as a veteran DotA player)

Will it be difficult for you to play ti every day? It's good to get started.

Talk about the interviewer's problem.

I had a new interview with the boss before.

1 What is a linear table

A linear table is a general designation of a data structure

There are basically two types of sequence lists (that is, a list of Python)

The advantage is that the query can be positioned once because all the element addresses are connected (data built-in)

Data external refers to the storage type is different, so the memory address in the table has its own address, so it is recommended that you store only one data type when storing data in a list

Cons for a sequential table, his memory space is the whole. Once it changes, the entire storage space will change (enrich the data series table) so the overall space required is very large

Fixed expansion stable but slow

Multiple expansions such as lists it expands five times times more storage space each time the element reaches 5W and changes to 1 time times

Use the Order table (list) when possible do not use + = To use to add to the tail if the head insert add will be 30 times times slower than append (I tried insert and append)

The reason is that when you add the sequence to the list, if it's the head subscript 0, then it means that the whole listing moves back one subscript.

The second type is linked list

The list is broadly divided into two parts, 1 element area 2 pointer area (two kind is the last element pointer area is the next element of the pointer area) all data are linked together, so called linked list

The advantage is that you can use fragmented space in memory to store it, but you use fragmented space.

Disadvantages when you take advantage of fragmented space, the overhead is huge and you can't do it when you're fetching data. O (1) because the space in the table is disconnected.

Linear tables generally (in Python) use less, if it is fortunate to use to add data to avoid trailing add because he added when the loop to the last pointer to the head when the last pointer will be

Point to new element to point to the head element of the new element pointer

Adding a head instead of O (1) Simply point the new element to the head element

The last point of the tree is based on the linear table, and then the tree will dwell on it later.

What are stacks and queues?

The popular analogy stack is a cup LIFO queue is FIFO

Implementations of stacks and queues are also implemented using linear tables

Simple implementation with sequence lists (list)

But you need to consider the complexity of the time. You don't have to use the sequence list. Add & List all the way to the end it's not worth the candle.

Talk about bubble sort

Bubble sort is the most basic sort of algorithm

The idea is that the first cycle of a two-layer cyclic outer cycle control the cycle of the whole cycle will be the second largest value of the second cycle to find and so on.

Quick sort (quick-row)

The quick line as the name suggests sort fast

The mind is divided into two layers

The first layer is to find two cursors a mid_value (median) a cursor starts with subscript 0, starting with a subscript from the len-1 tail.

Let the right cursor move to the cursor value larger than mid-1 touches a value that is smaller than mid to the left cursor

The left cursor begins to move to the right cursor and then the right cursor continues execution, with the subscript +1 smaller than the mid and the mid-size assignment

When the left and right cursors meet, the mid subscript also appears

From this mid to the left is all that's bigger than his little right side.

Then there's the important second-level recursion.

Recursively call yourself to perform smaller than yourself on the left

Recursively call yourself to perform larger than yourself on the right side

There's a pit-point operation with the same list, so don't use slices.

Slices are returned to the new list! Memory references have changed!

Note Control recursion value!

Imagine if you had 10W of data, he'd be handing out a lot of himself.

In other words, the function's running size also determines how much performance is consumed.

Typical performance-Change efficiency

What else do you know about sorting?

Select Sort Insert Sort Hill sort Merge sort

Select sort Insert sort and bubbling it's almost out of the detail.

But there is a sort of special is two improvements based on the insertion sort

That's going to say. Insert sort is there are two subscript 0 and 1 in turn than if 1:0 is the same position, then 5 will be 43210

Hill sort just also said is based on the insertion sort of two times development

One more median loop time from the value depending on the GEP

The list length is 8 I take the divisible 2 that's 4.

Starting from 4, the cycle table each subscript 4+1+1+1

There's just one more GEP. But the synthetic consideration of the time complexity is O (n^2) but is said to be mathematically accurate calculation can achieve n^1.3

Merge sort is also the recursion is just always divided and then the smallest exchange order with it but the slice is the last to return the same list

There's a tree down here. The most asked is the binary tree

What is the application scenario for a tree?

Pretty much.

Like the front-end HTML contains div ah a ah li ah various tags

Database indexes are also

Directory of files

Algorithm of routing protocol

Many AI algorithms are tree search machine learning DecisionTree is also tree structure and so on no example ....

There are two kinds of binary tree, which are ordered binary tree and unordered binary tree unordered. We're talking about ordered binary trees.

The binary tree also has a complete binary tree that is complete except for the bottom of the other degrees are 21 like the best understanding each node has a maximum of two degrees

When it comes to the recursion of the fast row is not always divided into two of their own regardless of the left side or the side has always been divided into a two-fork tree personally think this explanation is very suitable although there is no basis

But it's really a binary tree feature.

The storage of a tree is also divided into two kinds of tables, one is the sequential table, the other is the linked list

Sequential table storage is a good query for convenience. But the space is too big to be used

Use list storage because the list can take advantage of trivial memory space in a thin point to say the queue

Traversal of a binary tree

It's best to understand that the value of each traversal is 123456789.

The first sequence traversal traverses the left-right and the post-order traversal around the root.

It's not hard to use recursion.

Of course, some interviewers will ask you.

Painting a tree?

It takes two sequences to draw a tree, and the middle order is essential.

We'll take the simple 123456789来.

First Order traversal is 0137849256

Middle order 781940526

Post-7839412560

If we give first order and middle order

Preface 0137849256, Sequence 781940526

Why must the middle order because the middle order can separate left and right

Middle order 78194 0 526 0 137849 256

Left and right out of the first order also came out. In retrospect the rule of the first order is the rule of the left and right

There's a big tree on this basis. As long as enough time for the painting can also draw

The same sequence and order can be found

Well, why don't you tell me why the interviewer wants to ask? Linear table stack bubble fast binary tree bar

As a web developer he's not going to ask you, because you're not an algorithmic engineer. His idea is just to see if you usually love to learn logical thinking how

Let's start with the linear table. You know how the stack of data is stored is just a high level. See if you know the stack. He'd be happier if you'd put the queue and the double-ended queue up.

Bubble and fast row why are so many sorts just asking for a quick row and bubbling?

Bubble is the basis of the algorithm only if you know how to bubble he'll keep chasing after me, personally, I feel like bubbles are not an algorithm, it's a two-layer loop.

Bubble He's stable, but slow, slow, and you think about it. If you have tens of thousands of data, you don't want to go through it.

The fast platoon is in contact with recursion. He asked you at the same time if you can put the recursion is also very good, that means you have the understanding of recursion and the fast line really soon!!! The larger the data, the deeper the recursion depth

Typical use of performance efficiency although not stable generally also does not have a list of data in the meantime also put the tuple put. Good if you have to put!! Then use merge to sort the chant.

If he does know other algorithms

Bubble Insert Select Shell a routine fast and merge is also a routine

So he just asked for bubbles and the Clippers.

Forgot to write the dichotomy.

The same is always divided by recursion until it is found. I'll follow you through the dictionary. If you look at the ape, you divide the dictionary in half. If the first half is divided until the point is reached

The general tree does not ask the most deep is to traverse it

The hierarchical traversal sequence is a good follow-up. If you're going to spend the tree, ask him for a piece of paper. Give him the simplest logic 123456789.

But web development is generally not too deep, think more about the technical point of not knowing what to say don't know nothing embarrassing.

Well, that's a pretty general idea. I'm going to take the university's algorithm introduction and algorithm 4 out of the way.

Why the python web learns data structures and algorithms why do interviewers always ask those algorithms and linear table binary tree

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.