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: structure
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 […]
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{ […]
[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 […]
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 […]
The implementation principle of Redis Stream data structure is really strong
Hello, I am Ma Ge, a man who embraces hard-core technologies and objects, and programs for RMB. I set stars to avoid getting lost. I said in [Pros and Cons of Using List to Implement Message Queuing in Redis] that there are many limitations to using List to implement message queue. There is no ACK […]
Binary tree sequential storage structure
Table of Contents 1. Binary tree sequential storage structure 2. Concept and structure of heap 3. Heap related interface implementation 3.1 Heap insertion and upward adjustment algorithm 3.1.1 Upward adjustment algorithm 3.1.2 Heap insertion 3.2 Heap deletion and downward adjustment algorithm 3.2.1 Downward adjustment algorithm 3.2.2 Heap deletion 3.3 Other interfaces and code implementations 4. […]
Oracle Database Architecture (2)_Physical Structure
Table of Contents 1 Overview 2 Physical structure 2.1 Data files 2.2 Control files 2.4 Archive log files 2.5 Parameter file 2.6 Alert files 2.7 Tracking files 2.8 Backup files 3 Summary 1 Overview The storage structure is one of the architectures of the Oracle database and is the basis of Oracle management. Oracle storage […]