Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

C # basic concepts of time complexity, space complexity, recursion and interface

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "the basic concepts of time complexity, space complexity, recursion and interface of C #". In daily operation, it is believed that many people have doubts about the basic concepts of time complexity, space complexity, recursion and interface of C #. The editor consulted all kinds of materials and sorted out simple and useful operation methods. I hope it will be helpful to answer the questions of "C # time complexity, space complexity, basic concepts of recursion and interface"! Next, please follow the editor to study!

Before starting, we put forward two basic concepts of C #: time complexity and space complexity.

Time complexity refers to the corresponding relationship between the running time of the algorithm and the scale of the problem. The time complexity is expressed by T (n) = 0 (f (n), where 0 means that with the increase of the problem size n, the growth rate of the algorithm execution time is the same as that of f (n). If there is no cyclic code, the execution frequency of the algorithm will not change, recorded as 0 (1). When there is a double loop in the algorithm, the execution frequency increases linearly by 0 (n = 1). Wait.

Just looking at this expression is very abstract, here are two examples:

1 、

It is a multiple cycle with time complexity T (n) = 0 (n)}. While (x < I) {x = 0 (n)}

2 、

Int re=0; for (int ionome0 +) {for (int kryp0 +) {re=re+ (iSj); / / this is a double cycle with a time complexity of T (n) = 0 (n)}.

Space complexity refers to the amount of storage space temporarily occupied during the operation of the algorithm. The advantages and disadvantages of an algorithm are mainly measured from two aspects: the execution time of the algorithm and the storage space needed. the measurement of the execution time of the algorithm is not calculated by the absolute time of the execution of the algorithm. because the time taken by an algorithm to execute on different machines is different, and at different times, due to the different occupation of computer resources, the execution time of the algorithm on the same computer is also different. Therefore, the time complexity of the algorithm is measured by the number of times of its basic operations during the execution of the algorithm, which is called the amount of computation.

Here are two basic concepts of C # again: recursion and interface

Recursion means that the algorithm calls itself to do its work. This concept is very important both in the algorithm and in the implementation of the code. often when we go to the interview, there will be such an examination question. on the Shenzhen side, the companies I have interviewed before generally have a rabbit series. In my opinion, I use a recursive algorithm to do the problem.

Example: 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,... Ask for the 20th place

In fact, it is such a recursive relation: F (n): = f (nmur1) + f (nmur1)

An interface is a protocol that classes interact with each other.

The commonly used interfaces IComparable,IEnumerable,IEnumerator,ICollection,IDictionary,IList are listed below

Package its corresponding generic interface.

Let's look at an example of an interface:

Public interface IBook {string ShowBook (); string GetTitle (); int GetPages (); void SetPages (int pages);} public class NewBook: IBook {public string title; public int pages; public string author; public NewBook (string title, string author, int pages) {this.title = title; this.author = author; this.pages = pages } public string GetTitle () {return title;} public int GetPages () {return pages;} public void SetPages (int pages) {this.pages = pages;} public string ShowBook () {return title + "," + author + "," + pages }} private void button1_Click (object sender, EventArgs e) {NewBook nb = new NewBook ("A", "James", 200); richTextBox1.Text = nb.ShowBook ();}

Here you will output A _ mam _ James _ _ 200. In the NewBook class, you cannot write a method that has been defined by Ibook, so that you can access the method from the outside of the fully qualified class.

At this point, the study of "basic concepts of C# time complexity, space complexity, recursion and interface" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report