Introduction to algorithms tenth basic data types & 11th hash list (python)

Source: Internet
Author: User

More theoretical details can be used in the "data structure" Min to see a few times, data structure is very important to achieve a large part of the algorithm

Here's a talk about what Python implements

10.1 Stacks and queues

Stack: LIFO LIFO

Queue: FIFO first

Python uses list implementations in these features

Stack: Stack append () Rewind pop ()

Queue: Queued Append () out of the team pop (0)

Stack:

>>> stack = list ()>>> stack.append (3)>>> stack.append (2)> >> stack.append (5)>>> stack.append (1)>>> stack[3, 2, 5, 1] >>> stack.pop ()1>>> stack.pop ()5

Queue:

>>> queue = list ()>>> queue.append (1)>>> queue.append (2)> >> queue.append (3)>>> queue.append (4)>>> queue.append (5)> >> queue[1, 2, 3, 4, 5]>>> queue.pop (0)1>>> queue.pop (0)2 >>> queue[3, 4, 5]

Array implementation of linked list & pointer objects

These data structures have no value in Python and can be easily implemented with list

There is a root tree:

class Node:     def __init__ (self,data):         = None = None = None = Data                        

A node code is given, followed by a two-fork search tree Red-black tree is discussed in detail.

Hash list (hash table)

"Hash list is the generalization of the concept of ordinary arrays" one of the words to explain the hash list is better.

You can think of the array as a hash function for hash (x) = x% max (max ratio so the value is large) to get the hash value under this subscript to process the data

Pros: Very good expectations

Difficulties: Design and conflict handling of hash functions

Here's a summary of others:

Hash table (Python uses dict):

>>>#Initialize>>> a = dict (one = 1,two = 2)>>>#Access>>> a[' One']1>>>#Increase>>> a['three'] = 3>>>a{'three': 3,' One': 1,' Both': 2}>>>

Reference:

Http://www.wutianqi.com/?cat=515&paged=4

http://blog.csdn.net/fxjtoday/article/details/6448083

Introduction to algorithms tenth basic data types & 11th hash list (python)

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.