当前位置:网站首页>Data dictionary in C #
Data dictionary in C #
2022-07-06 10:58:00 【Dotnet cross platform】

Preface
Surfing the Internet as usual this morning , I saw an interview question chatting in the wechat group of maijiage , It's interesting , Here is a brief share of the conclusions Dictionary Dictionaries .
Yes 50w individual int Type of number , Now we need to judge whether there are duplicate numbers , Please briefly explain .
If this topic let me do , The first feeling may be directed to two for loop , Simply make a judgment and solve . But I saw the discussion of several big guys , I found that my knowledge is shallow .
Is this question about the application of business code cycle ? Definitely not .
We know , In verifying a piece of code or a program algorithm, the perfect indicators are space complexity and time complexity . Judge by these two indicators .
Spatial complexity :
It refers to the execution of an algorithm program , How much storage capacity is temporarily occupied per unit time . use S(n)=O(f(n)) To express .
Time complexity :
It refers to the execution of an algorithm program , How much time will it take .
In general , The number of times the basic operations are repeated in the algorithm is the scale of the problem n A function of , use T(n) Express , If there is an auxiliary function f(n), Properly n Approaching infinity ,T(n)/f(n) The limit value of is a constant not equal to zero , said f(n) yes T(n) Functions of the same order of magnitude of , Write it down as T(n)=O(f(n)), be called O(f(n)) Time complexity of the algorithm .
For example, the time complexity of insertion sorting is O(n^2), The space complexity is O(1).
The advantages and disadvantages of an algorithm are mainly measured from two aspects: the execution time of the algorithm and the required storage space .
During the discussion in the Group , There is an array array, Key value pair , And data dictionary Dictionary( A key value pair ). Finally, I feel like using Dictionary Store this 50w individual int Data of type , Use it key perhaps value To determine if there are duplicate values .
Now that I see this , Today we will simply review Dictionary, See what charm it has .
Dictionary<TKey,TValue> Dictionaries
according to MSDN Records on , Say it is a set of keys and values . Provide a set of keys to a set of values mapping . Each addition to the dictionary contains a value and its associated key . The speed of retrieving values using its keys very fast , near O(1).
Dictionary<TKey,TValue> This class is implemented as a hash table , The speed of retrieval depends on the quality of the hash algorithm for the specified type TKey.
Other features are briefly summarized as follows
Must contain a namespace System.Collection.Generic
Dictionary Every element in it is a key value pair
The key must be unique , The value does not need to be unique
Keys and values can be of any type
The time complexity of reading a value through a key is close to O(1), Search speed is very fast , than list Wait a lot faster
The partial order between key value pairs can not be defined
You can search by key value 、 Insert 、 Delete a key value pair , It is very troublesome to implement these with arrays

Here is about Dictionary Some of CRUD operation .
Definition dictionary 、 Add key value 、 Value 、 Change value 、 Traverse key、 Traverse value、 Remove elements 、 Empty all elements
// Definition
static Dictionary<int, string> ahuiInfo = new Dictionary<int, string>();
static void Main(string[] args)
{
// Add key value
ahuiInfo.Add(1," A Hui ");
ahuiInfo.Add(2, " Arabinase ");
ahuiInfo[2] = " Al I "
// Value
var name=ahuiInfo[0].ToString();
Console.WriteLine(""+name
// Modified value
ahuiInfo[0] = " aunt ";
Console.WriteLine("" + ahuiInfo[0].ToString()
// Traverse key and value
foreach (var key in ahuiInfo.Keys)
{
Console.WriteLine(""+key.ToString());
foreach (var value in ahuiInfo.Values)
{
Console.WriteLine(" "+value.ToString());
// Ergodic dictionary
foreach(KeyValuePair<int ,string> kvp in ahuiInfo)
{
Console.WriteLine("key="+kvp.Key+",value="+kvp.Value);
// Remove elements
ahuiInfo.Remove(0
// Judge whether the key exists
if (ahuiInfo.ContainsKey(0))
{
Console.WriteLine("true");
}
else
{
Console.WriteLine("false");
}
}
}remarks
Life is short , I don't want to pursue what I can't see , I just want to catch what I can see .
Originality is not easy. , Pay attention .
I am a A Hui , Thank you for reading , If it helps you , Please like it 、 forward thank you .

边栏推荐
- MySQL completely uninstalled (windows, MAC, Linux)
- Development of C language standard
- 导入 SQL 时出现 Invalid default value for ‘create_time‘ 报错解决方法
- Solve the problem that XML, YML and properties file configurations cannot be scanned
- CSDN博文摘要(一) —— 一个简单的初版实现
- Yum prompt another app is currently holding the yum lock; waiting for it to exit...
- There are three iPhone se 2022 models in the Eurasian Economic Commission database
- MySQL master-slave replication, read-write separation
- Valentine's Day is coming, are you still worried about eating dog food? Teach you to make a confession wall hand in hand. Express your love to the person you want
- Kubesphere - deploy the actual combat with the deployment file (3)
猜你喜欢

Csdn-nlp: difficulty level classification of blog posts based on skill tree and weak supervised learning (I)
![[recommended by bloggers] C MVC list realizes the function of adding, deleting, modifying, checking, importing and exporting curves (with source code)](/img/b7/aae35f049ba659326536904ab089cb.png)
[recommended by bloggers] C MVC list realizes the function of adding, deleting, modifying, checking, importing and exporting curves (with source code)

Bytetrack: multi object tracking by associating every detection box paper reading notes ()

Postman Interface Association

Mysql34 other database logs

CSDN blog summary (I) -- a simple first edition implementation

Mysql35 master slave replication

Detailed reading of stereo r-cnn paper -- Experiment: detailed explanation and result analysis

CSDN问答标签技能树(一) —— 基本框架的构建

Copie maître - esclave MySQL, séparation lecture - écriture
随机推荐
A brief introduction to the microservice technology stack, the introduction and use of Eureka and ribbon
CSDN问答模块标题推荐任务(一) —— 基本框架的搭建
Database middleware_ MYCAT summary
Ansible practical Series III_ Task common commands
[recommended by bloggers] background management system of SSM framework (with source code)
Adaptive Bezier curve network for real-time end-to-end text recognition
Pytorch RNN actual combat case_ MNIST handwriting font recognition
Emotional classification of 1.6 million comments on LSTM based on pytoch
Are you monitored by the company for sending resumes and logging in to job search websites? Deeply convinced that the product of "behavior awareness system ba" has not been retrieved on the official w
Unicode decodeerror: 'UTF-8' codec can't decode byte 0xd0 in position 0 successfully resolved
CSDN-NLP:基于技能树和弱监督学习的博文难度等级分类 (一)
Postman uses scripts to modify the values of environment variables
Advantages and disadvantages of evaluation methods
MySQL21-用戶與權限管理
CSDN question and answer tag skill tree (II) -- effect optimization
MySQL master-slave replication, read-write separation
API learning of OpenGL (2003) gl_ TEXTURE_ WRAP_ S GL_ TEXTURE_ WRAP_ T
[recommended by bloggers] C WinForm regularly sends email (with source code)
导入 SQL 时出现 Invalid default value for ‘create_time‘ 报错解决方法
[recommended by bloggers] C # generate a good-looking QR code (with source code)