返回首页

Data structure 3--Language support

Data Structures — Language Support (Part 3)

Data Structures—Language Support (Part 3) Data Structures 3—Language Support

arrays array

Support for N-th dimensional arrays is generally built directly into the core language itself. They exist in most of languages if not all of them. Support for n-dimensional arrays is usually built directly into the core language itself. They exist in most, if not all, languages.

Some languages ​​index from zero while others index from one. Some languages ​​index from 0 while others index from 1.

Dynamic Arrays dynamic array

java

Java offers a couple of classes, the best known being the ArrayList class. Java provides two classes, the most famous of which is the ArrayList class.

###python

In Python, list is a data type, just like strings and numbers. It’s an implementation of dynamic arrays. In Python, a list is a data type, just like strings and numbers. It is an implementation of dynamic array.

C++

C++’s std::vector is an implementation of dynamic arrays. C++'s std::vector is an implementation of a dynamic array.

C# also offers ArrayListclass as in Java. C# also provides ArrayListclass like Java.

linked list linked list

java

In Java, Listis an interface, where LinkedListclass implements the Listinterface. It’s implemented as doubly-linked list. In Java, Listis is an interface in which LinkedListclass implements Listinterface. It is implemented as a doubly linked list.

###python

Python does not have a built-in linked list implementation. Python lists are not linked lists, they are dynamic arrays. Python does not have a built-in implementation of linked lists. Python lists are not linked lists, they are dynamic arrays.

C++

The list container in the standard temple library is a doubly-linked list implementation. The list container in the standard temple library is a doubly linked list implementation.

C#

In C#, there is a LinkedListclass as in Java. It’s also implemented as doubly-linked list. In c#, there is a LinkedList class, just like in Java. It is also implemented as a doubly linked list.

stacks stack

java

In Java, it has a Stack class. In Java it has a stack class.

###python

Python doesn’t have an explicit stack class, but there is a section in the Python documentation of using lists as stacks. Python does not have an explicit stack class, but the Python documentation has a section on using lists as stacks.

C++

In C++, stack is part of the standard template library. In C++, stack is part of the standard template library.

C#

C# also offers Stack class as in Java. C# also provides stack classes in Java.

queues queues

java

Queueis an interface just as List was. There are multiple concrete classes that do support queue behavior. The LinkedListclass actually supports a simple queue behavior. Queueis is an interface identical to List. There are several concrete classes that support queue behavior. LinkedListclass actually supports a simple queue behavior.

###python

The queue module offers a queue class. It is especially useful in when working with threading which is very common with queues. It’s also possible to use list as queues, however, lists are not efficient for this purpose. The queue module provides a queue class. It is particularly useful when dealing with threads, which are very common in queues. It is also possible to use a list as a queue, however, lists are not efficient for this purpose.

collections.deque is an alternative implementation of unbounded queues with fast atomic append() and popleft() operations that do not require locking. deque is an alternative implementation of unbounded queues with fast atomic append() and popleft() operations that do not require locking.

C++

In C++, there is a queuecontainer in the standard template library. In C++, there is a queuecontainer in the standard template library.

C#

In C#, there is a Queueclass. In c#, there is a Queueclass.

##Deque

java

Java also has aDequeinterface just as Queue was. The LinkedListclass also implements that Dequeinterface. Java also has sufficient interfaces like Queue. LinkedListclass also implements that Dequeinterface.

Notice that LinkedList is turning out to be a very flexible class in Java. It can behave like a linked list and it can behave like a queue, and it can behave like a double ended queue; deque. It can be like a linked list, it can be like a queue, it can be like a double-ended queue; double-ended queue.

###python

Python also has a deque class for this. Even though you could use a Python list, the deque is optimized for this kind of usage; appends and pops on either end. Python also has a deque class for this. Even though you can use a Python list, deque is optimized for this usage; appending and popping at either end.

C++

In C++, there is a dequecontainer. In c++, there is a dequecontainer.

C#

It doesn’t have a built in explicit deque, but, we can provide equivalent behavior with a linked list or even a dynamic array. Just be conscious as shifting elements around in the array is not an efficient task. It has no built-in explicit deque, however, we can use linked lists or even dynamic arrays to provide equivalent behavior. Just keep your wits about you, because moving elements in an array is not an efficient task.

Priority Queues priority queue

Just as a list can be implemented with a linked list or an array, a priority queue can be implemented with a heap or a variety of other methods. Just as lists can be implemented using linked lists or arrays, priority queues can also be implemented using heaps or various other methods.

###Java Java has a PriorityQueueclass, which is based on a priority heap. Java has a PriorityQueueclass based on the priority heap.###Python The queue module offers a PriorityQueueclass, which uses heapq module under the hood to prioritize the queue entries. The heapq module uses the heap data structure.

Queue.PriorityQueue is a thread-safe class, while the heapq module makes no thread-safety guarantees. queue. PriorityQueue is a thread-safe class, and the heapq module does not provide thread-safety guarantees.

C++

C++ has priority_queuecontainer, which is also implemented as a heap data structure. c++ has priority_queuecontainer, which is also implemented as a heap data structure.

C#

C# doesn’t contain a priority queue class. But, there are several implementations for priority queues available on the internet. C# does not contain a priority queue class. However, there are several implementations of priority queues on the internet.

Associative Arrays Associative array

Most associate arrays, whether they are called dictionaries or maps or hash, are implemented using something called a hash table, and a hash table itself is a very important and useful data structure. Most associative arrays, whether they are called dictionaries, maps, or hashes, are implemented using something called a hash table, which itself is a very important and useful data structure.

Other languages use binary search tree (probably a red black tree; a type of self balancing binary search tree) where each node has a key and associated value. So, if you want to keep your keys in a sorted order, hash tables aren’t really good at that, but, binary search trees are. Other languages use a binary search tree (perhaps a red-black tree; a type of self-balancing binary search tree) where each node has a key and associated value. So, if you want to keep your keys ordered, hash tables are not good at that, but binary search trees are.

java

In Java, It has Map interface just as List was. It defines the operations for associative arrays, while HashMap and HashTable classes are implementations of these operations based on the hash table data structure. In Java, it has the same mapping interface as List. It defines operations on associative arrays, and the HashMap and HashTable classes are implementations of these operations based on the hash table data structure.

HashTable is better when working with multi-threaded applications, where you have different threads accessing and changing this hash table, but it will add a performance cost.

ConcurrentHashMapclass is a replacement for the older HashTable. ConcurrentHashMapclass is a replacement for the older HashTable.

There is also LinkedHashMap, which use linked list to iterate over the items in the same way they were inserted.

While TreeMap class also implements the Map interface, it’s actually a RedBlackTree, which is a self-balancing binary search tree.

##Python In Python, they are called dictionaries. They are implemented as a data type called dict, just like strings and numbers. They are implemented as a data type called dict, just like strings and numbers.

C++

C++ offers std::unordered_mapcontainer in the standard template library, while std::mapcontainer is the sorted version which is typically implemented as binary search tree. C++ provides std::unordered_mapcontainer in the standard template library, and std::mapcontainer is the sorted version, usually implemented as a binary search tree.

C#

In C#, they’re available in Dictionary<TKey,TValue>, Hashtableand StringDictionaryclasses, whileSortedDictionaryclass sorts the key-value pairs that’s implemented as a binary search tree. In C#, they are available in Dictionary<TKey, TValue>, Hashtable and StringDictionary classes, while the LessoredDictionary class sorts key-value pairs implemented as binary search trees.

sets sets

The idea of a set; having a big container where you can put a bunch of items into it, is usually implemented using hash tables, or binary search trees. The concept of a set; usually a hash table or binary search tree is used to implement a large container into which many items can be placed.

java

In Java, It has Set interface just as List and Queue, whileHashSet and TreeSetclasses implement the Setinterface. In Java it has Set interface just like List and Queue and lehashset and TreeSet classes implement Setinterface.

HashSet is internally implemented using an HashMap, while TreeSet is internally implemented using TreeMap. HashSet is implemented internally using HashMap, while TreeSet is implemented internally using TreeMap.

###python

Python supports set and frozensetdata types. frozenset is a way of making the set immutable after it has been created. Python supports set and frozensetdata types. frozenset is a way to make a collection immutable after creating it.

C++

As with maps, C++ also offers std::unordered_setcontainer in the standard template library, while std::setcontainer is the sorted version which is typically implemented as binary search tree. Like mapping, C++ also provides std::unordered_setcontainer in the standard template library, and std::setcontainer is the sorted version, usually implemented as a binary search tree.

C#C# also offers HashSet class which uses the hash table as in Java, while SortedSet is the sorted version.

C# also provides the HashSet class, which uses hash tables like in Java, and SortedSet is the sorted version.

graphs graphs

There is no direct support for graph data structure in languages(same as trees). Because the implementation of any graph is always going to be more specific. Graph data structures (the same as trees) are not directly supported in the language. Because the implementation of any graph is more concrete.

For example, A linked list is a kind of graph, a tree is a kind of graph, a heap is a kind of graph. A single linked list would be considered a directed graph, whereas a doubly linked list is a kind of undirected graph. They are all graphs with intentional constraints. For example, a linked list is a graph, a tree is a graph, and a heap is a graph. A singly linked list is considered a directed graph, while a doubly linked list is an undirected graph. They are both intent-constrained graphs.

Summary for Data Structures Language Support Summary language support for data structures

Source: https://medium.com/omarelgabrys-blog/data-structures-language-support-5f70f8312e84

FAQ

读完之后,下一步看什么

如果还想继续了解,可以从下面几个方向接着读。

Related

继续阅读

这里整理了同分类、同标签或同类问题的文章。