当前位置:网站首页>CPT 102_LEC 17
CPT 102_LEC 17
2022-06-11 01:52:00 【NONE_WHY】
1. Binary Search
2. Sorting
2.1. Ways of sorting
2.1.1. Selecting sorts
- Find the next largest/smallest item and put in place
- Builds the correct list in order
2.1.2. Inserting Sorts
- For each item, insert it into an ordered sublis
- Builds a sorted list, but keeps changing it
2.1.3. Compare and Swap Sorts
- Find two items that are out of order, and swap them
- Keeps “improving” the list
2.1.4. Radix Sorts
- Look at the item and work out where it should go
- Only works on some kinds of values
2.2. Analysing Sorting Algorithms
- Efficiency
- Requirements on Data
- Space Usage
2.3. Implementation
2.3.1. Selection Sort
- Code
public void selectionSort(E[ ] data, int size, Comparator<E> comp){ // for each position, from 0 up, find the next smallest item // and swap it into place for (int place=0; place<size-1; place++){ int minIndex = place; for (int sweep=place+1; sweep<size; sweep++){ if (comp.compare(data[sweep], data[minIndex]) < 0) minIndex=sweep; } swap(data, place, minIndex); } }
- Analysis
-

-
2.3.2. Bubble Sort
- Code
-
public void bubbleSort(E[] data, int size, Comparator<E> comp){ // Repeatedly scan array, swapping adjacent items if out of order // Builds a sorted region from the end for (int top=size-1; top>0; top--){ for (int sweep=0; sweep<top; sweep++){ if (comp.compare(data[sweep], data[sweep+1]) >0) { swap(data, sweep, sweep+1); } } } }
-
- Analysis
-

-
边栏推荐
- How to guarantee the data quality of data warehouse?
- When the interviewer opens his mouth, he comes to compose. Is this the case now?
- A collection of common ADB commands for app testing
- koa2学习笔记
- Why can some programmers get good offers with average ability?
- 2022 simulated 100 questions and answers for crane driver (limited to bridge crane) examination
- JS summary of math functions in math objects
- 378. the k-th smallest element in an ordered matrix
- 金属有机框架MOF-Al(DIBA),MOF-Zr(DIBA),MOF-Fe(DIBA)包载姜黄素/羧苄西林/MTX甲氨蝶呤/紫杉醇PTX/阿霉素DOX/顺铂CDDP/CPT喜树碱等药物
- Project - redis message queue + worker thread fetches user operation logs and stores them (2)
猜你喜欢

查看Redis内数据,除了命令行和客户端,你还有第三种选择

Epoll principle and Application & ET mode and lt mode

The most complete format description of clang format

环糊精金属有机骨架(β-CD-MOF)装载二巯丁二酸/大黄素/槲皮素/三氯蔗糖/二氟尼柳/奥美拉唑(OME)

Cyclodextrin metal organic framework( β- Cd-mof) loaded with dimercaptosuccinic acid / emodin / quercetin / sucralose / diflunisal / omeprazole (OME)

Unity animator rewind

Redis learning notes (continuously updating)

Jetpack compose scaffold and topappbar (top navigation)

13. numeric array

When the interviewer opens his mouth, he comes to compose. Is this the case now?
随机推荐
Unity3d model skin changing technology
The diligent is the laziest
[MySQL 45 lecture -12] lecture 12 the reason why MySQL has a wind attack from time to time
JS summary of math functions in math objects
Optimized dispatching (thermal power, wind energy and energy storage) [matlab code implementation]
叶酸配体的金属有机骨架材料MOFs负载5-氟尿嘧啶,西达本胺,紫杉醇,阿霉素,柔红霉素,布洛芬,喜树碱,姜黄素,藤黄酸等小分子药物
MySQL备份与恢复
378. the k-th smallest element in an ordered matrix
Unity animator rewind
Do tween record
NFT insider 61:animoca brands holds US $1.5 billion of encrypted assets in 340 investments
GCC C内联汇编
Project - redis message queue + worker thread fetches user operation logs and stores them (2)
13. numeric array
The most complete format description of clang format
Tests logiciels vocabulaire commun anglais
ShaderGraphs
STC8A8K64D4 EEPROM读写失败
Penetration test - security service system +owasp top 10
Closing method of SQL injection