Counting sort is a sorting algorithm with a time complexity of O(n), which was proposed by Harold H. Seward in 1954. When sorting a range of integers, its complexity is O(n + k) (where k is the range size of integers). Pseudo counting sort We need to sort an array where each element is an […]
Tag: struct
Frame structured serial data receiver – Verilog implementation
Use Verilog to implement a frame-structured serial data receiver; Serial data input is: NRZ data plus bit clock (BCL) format, high-order bit first The frame structure is: 8 bits constitute a word, and 64 words constitute a frame. The first word of each frame is the synchronization word. The sync word pattern is stored in […]
[Key Points] Selenium + Nightwatch automated test environment construction
Start building 1. Create project Let’s find a place to create a new directory, name it “my-test-toolkit”, and then use the terminal in the directory to run npm init -y to generate the project configuration file< strong>package.json. 2. Installation tools Then we will install Selenium and Nightwatch. Install selenium-standalone: npm install selenium-standalone –save-dev Install Nightwatch: […]
Data structure – sorting algorithm – merge sort
Merge two ordered arrays into one ordered array In the process of inserting the second list into the first list one by one, since the second list is already sorted, the subsequently inserted elements will not be before the previously inserted elements. In the process of inserting one by one, each time you insert, you […]
[Data structure] PriorityQueue and heap
Whenthereisanincomingcallonthemobilephone,themobilephonewillalwaysgiveprioritytotheincomingcall.Inthiscase,aqueuewithpriorityisused.Inadatastructure,astructurethatcanaddnewobjectsandreturnthehighestpriorityobjectiscalledapriorityqueue.TheheapandPriorityQueueareapriorityqueue. Heap Whatisaheap Aheapisacompletebinarytree,andthevalueofeachnodeisalwaysnogreaterthanornolessthanthevalueofitsparentnode.Aheapthatisgreaterthanitsparentnodeiscalledabigrootheap,andaheapthatislessthanitsparentnodeiscalledaheap.Smallrootpile. Heapstoragemethod Becausetheheapisacompletebinarytree,itcanbestoredinthearrayinasequentialmanneraccordingtotheorderoflayer-ordertraversal(ifitisnotacompletebinarytree,emptynodesmustbestoredinthespace,whichwillleadtorelativelylowspaceutilization). Thecompletebinaryisstoredinthearrayinorder.Thesubscriptoftheleftchildnodeofnodeiis2*i+1,thesubscriptoftherightchildnodeis2*i+2,andthesubscriptoftheparentnodeis(i-1)/2. Thefollowingisthestoragestructureofthesimulatedheap: publicclassHeap{ //arraytostoreheap privateint[]elem; //Thenumberofvalidelementsintheheap privateintusedSize; //Defaultsizeofarray privatestaticfinalintDEFAULT_SIZE=10; //Constructorinitializesthearray publicHeap(){ elem=newint[DEFAULT_SIZE]; } } Creationofheap Aheapisaspecialcompletebinarytree.Wecancreateaheapbyadjustingdownwardanordinarybinarytree.Herewetakecreatingasmallrootheapasanexample. Thepicturebelowisaschematicdiagramofadownwardadjustment: Toconvertanordinarybinarytreeintoaheaprequiresmultipledownwardadjustments.Thespecificstepsareasfollows: Twolabels,parentandchild,arerequired.Letparentmarkthenodethatneedstobeadjusted,andchildmarktheleftchildofparent(ifparenthasachild,itmusthavealeftchildfirst).Ifparenthasaleftchild,performthefollowingoperations: 1.Determinewhethertheparent’srightchildexists.Ifitexists,letthechildmarkthesmallestnodeamongtheleftandrightchildnodes. 2.Compareparentandchild.Ifparentissmallerthanchild,theadjustmentends;ifparentislargerthanchild,swapparentandchild. 3.Aftertheexchangeiscompleted,thelargeelementsintheparentmovedownward,whichmaycausethesubtreetonotmeetthepropertiesoftheheap,soitneedstocontinuetoadjustdownward,thatis,parent=child;child=parent*2+1;andthencontinuewith1,2,3steps. //Buildaheap publicvoidcreateHeap(){ //Findthefirstnon-leafnodefromthelast,startfromthenodepositionandgoforwardtotherootnode.Whenencounteringanode,applydownwardadjustment for(intparent=(usedSize-1-1)/2;parent>=0;parent–){ //Adjustdownward shiftDown(parent,usedSize); } } //Adjustdownward publicvoidshiftDown(intparent,intlen){ //childfirstmarkstheleftchildoftheparent,becausetheparentmayhavealeftbutnotarightchild intchild=parent*2+1; while(child<len){ //Iftherightchildexists,findthesmallerchildamongtheleftandrightchildrenandmarkitwithchild if(child+1<len&&elem[child]>elem[child+1]){ child++; } if(elem[parent]>elem[child]){ //Theparentnodeislargerthanitssmallestchildnode //Swapparentnodewithsmallerchildnode inttmp=elem[child]; elem[child]=elem[parent]; elem[parent]=tmp; //Movinglargeelementsintheparentdownwardmaycausethesubtreetonotmeetthepropertiesoftheheap,soitneedstocontinuetobeadjusteddownward. parent=child; child=2*parent+1; }else{ […]
Python interface automated construction process, including request request encapsulation
Some thoughts at the beginning Interface test automation benefits The obvious benefit is freeing your hands. Can automatically execute a large number of test cases in a short time Improve test coverage by changing test data in a parameterized and data-driven manner Quick feedback on test execution results and reports Processes that support continuous integration […]
[Data structure] Implementation of binary tree chain structure (3)
Table of Contents 1. Chain structure of binary tree 2. Interface implementation of binary chain 1. Creation of binary chain 2. Interface function 3. Dynamically create new nodes 4. Create a binary tree 5. Preorder traversal 6. In-order traversal 7. Post-order traversal Third, the number and height of nodes, etc. 1. Interface function 2. Number […]
Data structure – sequence table
Article directory 1. Linear table 2. Sequence table 2.1 Concept and structure 2.2 Interface implementation (1) Sequence table initialization (2)Sequence table destruction (3) Sequence table expansion (4) Tail insertion data (5)Head plug data (6) Insert x before the data with subscript pos (7) Tail deleted data (8) Header deletion data (9) Delete the data with […]
[MySQL installation and cluster construction in Linux environment]
Article directory 1. Install MySQL8.X in Linux environment 1.1. Configure network card information in Linux environment 1.2. Remotely pull the MySQL8.x installation package 1.3. MySQL installation and related parameter configuration 1.4. MySQL startup and remote connection settings 2. MySQL master-slave cluster construction 2.1. Purpose and reasons for cluster construction 2.2. Problems in building a MySQL […]
Lesson 21 Data storage & structure in memory
Storage of floating point numbers in memory How floating point numbers are stored According to the IEEE 754 standard, floating point numbers can be written as: (-1)^S *M*2 ^E. Just store S, M, and E in the memory. S, M, and E are all binary numbers, so when storing decimal floating-point numbers, they need to […]