算法的例子有O(1),O(N日志N)和O(log n)的复杂性复杂性、算法、例子、日志

2023-09-10 23:23:32 作者:時光在唱歌

什么是一些算法,我们在日常使用已经O(1),O(N日志N)和O(log n)的复杂性?

What are some algorithms which we use daily that has O(1), O(n log n) and O(log n) complexities?

推荐答案

如果你想在这个问题给出算法/组的陈述与时间复杂度的例子,这里是一个小清单 -

If you want examples of Algorithms/Group of Statements with Time complexity as given in the question, here is a small list -

O(1)时间 1.访问数组索引(中间体一个= ARR [5]) 2.插入节点链表 3.推进和坡平对堆栈 4.插入和移除从队列 5.找出存储在阵列一棵树的父母或节点的左/右孩子 6.跳转到下一首/ previous元素双向链表 你可以找到一万个以上这样的例子...

O(1) time 1. Accessing Array Index (int a = ARR[5];) 2. Inserting a node in Linked List 3. Pushing and Poping on Stack 4. Insertion and Removal from Queue 5. Finding out the parent or left/right child of a node in a tree stored in Array 6. Jumping to Next/Previous element in Doubly Linked List and you can find a million more such examples...

O(n)的时间 1.遍历数组 2.遍历链表 3.线性搜索 在一个链表(不排序) 4.删除特定元素的 5.比较两个字符串 6.检查回文 7.计数/桶排序 在这里也可以找到一万个以上这样的例子.... 概括地说,所有的蛮力算法,还是菜鸟的人需要的线性度,是基于O(n)的时间复杂度

O(n) time 1. Traversing an array 2. Traversing a linked list 3. Linear Search 4. Deletion of a specific element in a Linked List (Not sorted) 5. Comparing two strings 6. Checking for Palindrome 7. Counting/Bucket Sort and here too you can find a million more such examples.... In a nutshell, all Brute Force Algorithms, or Noob ones which require linearity, are based on O(n) time complexity

O(log n)的时间 1.二进制搜索 2.找到最大/最小号的二叉搜索树 3.某些分而基于线性功能治算法 4.计算Fibonacci数 - 最佳方法 基本$ P $这里pmise未使用的全部数据,并减少了问题的规模与每个迭代

O(log n) time 1. Binary Search 2. Finding largest/smallest number in a binary search tree 3. Certain Divide and Conquer Algorithms based on Linear functionality 4. Calculating Fibonacci Numbers - Best Method The basic premise here is NOT using the complete data, and reducing the problem size with every iteration

O(nlogn)时间 1.合并排序 2.堆排序 3.快速排序 4.某些分治法的基础上优化为O(n ^ 2)算法 日志N'的系数是通过将考虑分治介绍。一些这些算法是最好优化那些和经常使用的。

O(nlogn) time 1. Merge Sort 2. Heap Sort 3. Quick Sort 4. Certain Divide and Conquer Algorithms based on optimizing O(n^2) algorithms The factor of 'log n' is introduced by bringing into consideration Divide and Conquer. Some of these algorithms are the best optimized ones and used frequently.

为O(n ^ 2)时间 1.冒泡排序 2.插入排序 3.选择排序 4.遍历一个简单的二维数组 这些的人都应该是低效率的算法,如果他们的O(nlogn)的同行是present。一般的应用可以是蛮力这里。

O(n^2) time 1. Bubble Sort 2. Insertion Sort 3. Selection Sort 4. Traversing a simple 2D array These ones are supposed to be the less efficient algorithms if their O(nlogn) counterparts are present. The general application may be Brute Force here.

我希望这回答了你的问题很好。如果用户有更多的例子来补充,我会很乐意:)

I hope this answers your question well. If users have more examples to add, I will be more than happy :)