id int64 0 25.6k | text stringlengths 0 4.59k |
|---|---|
25,100 | listing the tree java program /tree java /demonstrates tree /to run this programc>java tree app import java io */for / import java lang integer/for parseint(///////////////////////////////////////////////////////////////class dataitem public double ddata/one data item //public dataitem(double dd/constructor ddata dd//p... |
25,101 | node tempnode childarray[childnum]childarray[childnumnullreturn tempnode/public node getchild(int childnumreturn childarray[childnum]/public node getparent(return parent/public boolean isleaf(return (childarray[ ]==nulltrue false/public int getnumitems(return numitems/public dataitem getitem(int index/get dataitem at i... |
25,102 | numitems++double newkey newitem ddata/will add new item /key of new item for(int =order- >= --/start on right/examine items if(itemarray[ =null/if item nullcontinue/go left one cell else /not null/get its key double itskey itemarray[jddataif(newkey itskey/if it' bigger itemarray[ + itemarray[ ]/shift it right else item... |
25,103 | node curnode rootint childnumberwhile(trueif(childnumber=curnode finditem(key!- return childnumber/found it else ifcurnode isleaf(return - /can' find it else /search deeper curnode getnextchild(curnodekey)/end while //insert dataitem public void insert(double dvaluenode curnode rootdataitem tempitem new dataitem(dvalue... |
25,104 | int itemindexitemc thisnode removeitem()/remove items from itemb thisnode removeitem()/this node child thisnode disconnectchild( )/remove children child thisnode disconnectchild( )/from this node node newright new node()/make new node if(thisnode==root/if this is the rootroot new node()/make new root parent root/root i... |
25,105 | return thenode getchild( )/we're greaterso /return right child /public void displaytree(recdisplaytree(root )/private void recdisplaytree(node thisnodeint levelint childnumbersystem out print("level="+level+child="+childnumber+")thisnode displaynode()/display this node /call ourselves for each child of this node int nu... |
25,106 | puttext("enter first letter of ")puttext("showinsertor find")char choice getchar()switch(choicecase ' 'thetree displaytree()breakcase ' 'puttext("enter value to insert")value getint()thetree insert(value)breakcase ' 'puttext("enter value to find")value getint()int found thetree find(value)if(found !- system out println... |
25,107 | string getstring()return integer parseint( )///end class tree app trees and red-black trees at this point trees and red-black trees (described in probably seem like entirely different entities howeverit turns out that in certain sense they are completely equivalent one can be transformed into the other by the applicati... |
25,108 | figure shows tree and the corresponding red-black tree obtained by applying these transformations dotted lines surround the subtrees that were made from -nodes and -nodes the red-black rules are automatically satisfied by the transformation check that this is sotwo red nodes are never connectedand there is the same num... |
25,109 | each -node into two -nodes in red-black tree you perform color flips how are these operations equivalentfigure -node split and color flip in figure - we show -node in tree before it is splitfigure - shows the situation after the split the -node that was the parent of the -node becomes -node in figure - we show the red-... |
25,110 | although these arrangements are equally validyou can see that the tree in bis not balancedwhile that in cis given the red-black tree in )we would want to rotate it to the right (and perform two color changesto balance it amazinglythis rotation results in the exact same tree shown in cthus we see an equivalence between ... |
25,111 | some nodes contain itemsome and some if we estimate that the average is search times will be proportional to *log this is small constant number that can be ignored in big notation thusfor trees the increased number of items per node tends to cancel out the decreased height of the tree the search times for tree and for ... |
25,112 | stored entirely in main memory (often called ramfor random access memoryhoweverin many situations the amount of data to be processed is too large to fit in main memory all at once in this case different kind of storage is necessary disk files generally have much larger capacity than main memorythis is made possible by ... |
25,113 | pagesallocation unitsor some other namedepending on the system we'll call them blocks the disk drive always reads or writes minimum of one block of data at time block size variesdepending on the operating systemthe size of the disk driveand other factorsbut it is usually power of for our phone book examplelet' assume b... |
25,114 | searching to search sequentially ordered file for particular last name such as smithyou could use binary search you would start by reading block of records from the middle of the file the records in the block are all read at once into , -byte buffer in main memory if the keys of these records are too early in the alpha... |
25,115 | themwhich at milliseconds per read and write requires more than five minutes to insert single entry this won' be satisfactory if you have thousands of new names to add to the phone book another problem with the sequential ordering is that it only works quickly for one key our file is arranged by last names but suppose ... |
25,116 | within each node the data is ordered sequentially by keyas in tree in factthe structure of -tree is similar to that of treeexcept that there are more data items per node and more links to children the order of -tree is the number of children each node can potentially have in our example this is so the tree is an order ... |
25,117 | |
25,118 | have already been inserted into the tree new data item with key of is insertedresulting in node split here' how the split is accomplished because it' the root that' being splittwo new nodes are created (as in tree) new root and new node to the right of the one being split to decide where the data items gothe insertion ... |
25,119 | would have if we use blocks with hundreds of recordswe can reduce the number of levels in the tree and further improve access times although searching is faster in -trees than in sequentially ordered disk filesit' for insertion and deletion that -trees show the greatest advantage let' first consider -tree insertion in ... |
25,120 | index file in memory because it' so much smaller than the file containing actual recordsit may be that the index is small enough to fit entirely in main memory in our example there are , records each one has -byte entry in the indexso the index will be , or , , bytes long ( megabytesin modern computers there' no proble... |
25,121 | multiple indexes an advantage of the indexed approach is that multiple indexeseach with different keycan be created for the same file in one index the keys can be last namesin another telephone numbersin another addresses because the indexes are small compared with the filethis doesn' increase the total data storage ve... |
25,122 | written back to disk this continues until all pairs of blocks have been merged next each pair of -block sequences is merged into -block sequence each time the size of the sorted sequences doublesuntil the entire file is sorted figure shows the mergesort process on an external file the file consists of four blocks of fo... |
25,123 | these two arrays are then merge-sorted into arr howeverbecause arr holds only one blockit becomes full before the sort is completed when it becomes fullits contents are written to disk the sort then continuesfilling up arr again this completes the sortand arr is again written to disk the following lists show the detail... |
25,124 | summary multiway tree has more keys and children than binary tree tree is multiway tree with up to three keys and four children per node in multiway treethe keys in node are arranged in ascending order in treeall insertions are made in leaf nodesand all leaf nodes are on the same level three kinds of nodes are possible... |
25,125 | tree rotation in red-black tree corresponds to changing between the two possible orientations (slantswhen transforming -node the height of tree is less than log search times are proportional to the height the tree wastes space because many nodes are not even half full external storage means storing data outside of main... |
25,126 | elsewhere howeverif you don' need to visit items in orderand you can predict in advance the size of your databasehash tables are unparalleled in speed and convenience introduction to hashing in this section we'll introduce hash tables and hashing one important concept is how range of key values is transformed into rang... |
25,127 | presumably the array is made somewhat larger than the current number of employeesto allow room for expansionbut not much expansion is anticipated not always so orderly the speed and simplicity of data access using this array-based database make it very attractive howeverit works in our example only because the keys are... |
25,128 | then we add them thus in our dictionary the word cats would be stored in the array cell with index all the other english words would likewise be assigned an array index calculated by this process how well would this workfor the sake of argumentlet' restrict ourselves to -letter words then (remembering that blank is )th... |
25,129 | * * * * (an input routine in computer program performs similar series of multiplications and additions to convert sequence of digitsentered at the keyboardinto number stored in memory in this system we break number into its digitsmultiply them by appropriate powers of (because there are possible digits)and add the prod... |
25,130 | hashing what we need is way to compress the huge range of numbers we obtain from the numbers-multiplied-by-powers system into range that matches reasonably sized array how big an array are we talking about for our english dictionaryif we only have , wordsyou might assume our array should have approximately this many el... |
25,131 | to reviewwe convert word into huge number by multiplying each character in the word by an appropriate power of hugenumber ch * ch * ch * ch * ch * ch * ch * ch * ch * ch * thenusing the modulo (%operatorwe squeeze the resulting huge range of numbers into range about twice as big as the number of items we want to store ... |
25,132 | but in fact we can work around the problem in variety of ways remember that we've specified an array with twice as many cells as data items thus perhaps half the cells are empty one approachwhen collision occursis to search the array in some systematic way for an empty celland insert the new item thereinstead of at the... |
25,133 | arrayindex key this hash function is simple enough that you can solve it mentally for given keykeep subtracting multiples of until you get number under for exampleto hash subtract giving and then againgiving this is the index number where the algorithm will place thus you can easily check that the algorithm has hashed ... |
25,134 | fill it too full (for exampleif you try to put items in -cell tableyou may think the program has stoppedbut be patient it' extremely inefficient at filling an almost-full array alsonote that if the hash table becomes completely full the algorithms all stop workingin this applet they assume that the table has at least o... |
25,135 | isn' accomplished by simply removing data item from cellleaving it empty why notremember that during insertion the probe process steps along series of cellslooking for vacant one if cell is made empty in the middle of this sequence of full cellsthe find routine will give up when it sees the empty celleven if the desire... |
25,136 | next cell is occupied here' the code for find()public dataitem find(int key/(assumes table not fullint hashval hashfunc(key)/find item with key /hash the key while(hasharray[hashval!null/until empty cell/found the keyif(hasharray[hashvalidata =keyreturn hasharray[hashval]/yesreturn item ++hashval/go to next cell hashva... |
25,137 | int hashval hashfunc(key)/delete dataitem /hash the key while(hasharray[hashval!null/until empty cell/found the keyif(hasharray[hashvalidata =keydataitem temp hasharray[hashval]/save item hasharray[hashvalnonitem/delete item return temp/return item ++hashval/go to next cell hashval %arraysize/wrap around if necessary r... |
25,138 | dataitem[hasharrayint arraysizedataitem nonitem/array holds hash table /for deleted items /public hashtable(int size/constructor arraysize sizehasharray new dataitem[arraysize]nonitem new dataitem(- )/deleted item key is - /public void displaytable(system out print("table")for(int = <arraysizej++if(hasharray[ !nullsyst... |
25,139 | int hashval hashfunc(key)/hash the key while(hasharray[hashval!null/until empty cell/found the keyif(hasharray[hashvalidata =keydataitem temp hasharray[hashval]/save item hasharray[hashvalnonitem/delete item return temp/return item ++hashval/go to next cell hashval %arraysize/wraparound if necessary return null/can' fi... |
25,140 | keyspercell /make table hashtable thehashtable new hashtable(size)for(int = <nj++/insert data akey (int)(java lang math random(keyspercell size)adataitem new dataitem(akey)thehashtable insert(adataitem)while(true/interact with user puttext("enter first letter of ")puttext("showinsertdeleteor find")char choice getchar()... |
25,141 | system out print( )system out flush()//public static string getstring(throws ioexception inputstreamreader isr new inputstreamreader(system in)bufferedreader br new bufferedreader(isr)string br readline()return //public static char getchar(throws ioexception string getstring()return charat( )//public static int getint(... |
25,142 | enter first letter of showinsertdeleteor findf enter key value to find found enter first letter of showinsertdeleteor findi enter key value to insert enter first letter of showinsertdeleteor finds table * * * enter first letter of showinsertdeleteor findd enter key value to delete enter first letter of showinsertdelete... |
25,143 | widely separated cellsinstead of those adjacent to the primary hash site the step is the square of the step number in linear probeif the primary hash index is xsubsequent probes go to + + + and so on in quadratic probingprobes go to + + + + + and so on the distance from the initial probe is the square of the step numbe... |
25,144 | patienthoweveryou'll find key that requires three or four stepsand you'll see the step size lengthen for each step you can also use find to search for nonexistent keythis search continues until an empty cell is encountered importantalways make the array size prime number use instead of for example (other primes less th... |
25,145 | figure double hashing the hashdouble applet with double hashing you can use the hashdouble workshop applet to see how double hashing works it starts up automatically in double-hashing modebut if it' in quadratic mode you can switch to double by creating new table with the new button and clicking the double button when ... |
25,146 | /end class dataitem ///////////////////////////////////////////////////////////////class hashtable dataitem[hasharrayint arraysizedataitem nonitem/array is the hash table /for deleted items /hashtable(int size/constructor arraysize sizehasharray new dataitem[arraysize]nonitem new dataitem(- )/public void displaytable(s... |
25,147 | /(assumes table not fullint hashval hashfunc (key)/hash the key int stepsize hashfunc (key)/get step size /until empty cell or - while(hasharray[hashval!null &hasharray[hashvalidata !hashval +stepsizehashval %arraysizehasharray[hashvalitem/end insert(/add the step /for wraparound /insert item /public dataitem delete(in... |
25,148 | ///////////////////////////////////////////////////////////////class hashdoubleapp public static void main(string[argsthrows ioexception int akeydataitem adataitemint sizen/get sizes puttext("enter size of hash table")size getint()puttext("enter initial number of items") getint()/make table hashtable thehashtable new h... |
25,149 | adataitem thehashtable find(akey)if(adataitem !nullsystem out println("found akey)else system out println("could not find akey)breakdefaultputtext("invalid entry\ ")/end switch /end while /end main(//public static void puttext(string ssystem out print( )system out flush()//public static string getstring(throws ioexcept... |
25,150 | item number key hash value step size cells in probe sequence |
25,151 | the array gets more fullthe probe sequences become quite long here' the resulting array of keys* * table size prime number double hashing requires that the size of the hash table is prime number to see whyimagine situation where the table size is not prime number for examplesuppose the array size is (indices from to )a... |
25,152 | an array of linked listsas shown in figure figure the hashchain workshop applet each element of the array occupies one line of the displayand the linked lists extend from left to right initially there are cells in the array ( liststhis is more than fits on the screenyou can move the display up and down with the scrollb... |
25,153 | table duplicates duplicates are allowed and may be generated in the fill process all items with the same key will be inserted in the same listso if you need to discover all of themyou must search the entire list in both successful and unsuccessful searches this lowers performance the find operation in the applet only f... |
25,154 | /demonstrates hash table with separate chaining /to run this programc:>java hashchainapp import java io */for / import java util */for stack class import java lang integer/for parseint(///////////////////////////////////////////////////////////////class link /(could be other itemspublic int idata/data item public link ... |
25,155 | /delete link /(assumes non-empty listlink previous null/start at first link current first/until end of listwhile(current !null &key !current idata/or key =currentprevious currentcurrent current next/go to next link /disconnect link if(previous==null/if beginning of list first first next/delete first link else /not at b... |
25,156 | private sortedlist[hasharrayprivate int arraysize/array of lists /public hashtable(int size/constructor arraysize sizehasharray new sortedlist[arraysize]/create array for(int = <arraysizej++/fill array hasharray[jnew sortedlist()/with lists /public void displaytable(for(int = <arraysizej++/for each cellsystem out print... |
25,157 | /hash the key link thelink hasharray[hashvalfind(key)/get link return thelink/return link //end class hashtable ///////////////////////////////////////////////////////////////class hashchainapp public static void main(string[argsthrows ioexception int akeylink adataitemint sizenkeyspercell /get sizes puttext("enter siz... |
25,158 | breakcase ' 'puttext("enter key value to find")akey getint()adataitem thehashtable find(akey)if(adataitem !nullsystem out println("found akey)else system out println("could not find akey)breakdefaultputtext("invalid entry\ ")/end switch /end while /end main(//public static void puttext(string ssystem out print( )system... |
25,159 | enter initial number of items enter first letter of showinsertdeleteor finds list (first-->last) list (first-->last) list (first-->last) list (first-->last) list (first-->last) list (first-->last) list (first-->last) list (first-->last) list (first-->last) list (first-->last) list (first-->last) list (first-->last) lis... |
25,160 | compress larger range of keys into smaller range of index numbers the distribution of key values in particular database determines what the hash function needs to do in this we've assumed that the data was randomly distributed over its entire range in this situation the hash function index key arraysizeis satisfactory ... |
25,161 | we'll see how to handle overflow when we talk about hashing strings in moment to summarizethe trick is to find hash function that' simple and fastyet excludes the non-data parts of the key and uses all the data use prime number for the modulo base often the hash function involves using the modulo operator (%with the ta... |
25,162 | the hashfunc (method is not as efficient as it might be aside from the character conversionthere are two multiplications and an addition inside the loop we can eliminate multiplication by taking advantage of mathematical identity called horner' method (horner was an english mathematician - this states that an expressio... |
25,163 | of instead of so that multiplication can be effected using the shift (>>operatorwhich is faster than the modulo (%operator you can use an approach similar to this to convert any kind of string to number suitable for hashing the strings can be wordsnamesor any other concatenation of characters hashing efficiency we've n... |
25,164 | at load factor of / successful search takes comparisons and an unsuccessful search takes at load factor of / the numbers are and at higher load factors the numbers become very large the moralas you can seeis that the load factor must be kept under / and preferably under / on the other handthe lower the load factorthe m... |
25,165 | separate chaining the efficiency analysis for separate chaining is differentand generally easierthan for open addressing we want to know how long it takes to search for or insert an item into separate-chaining hash table we'll assume that the most time-consuming part of these operations is comparing the search key of t... |
25,166 | figure separate-chaining performance for an ordered listonly half the items must be examined in an unsuccessful searchso the time is the same as for successful search in separate chaining it' typical to use load factor of about (the number of data items equals the array sizesmaller load factors don' improve performance... |
25,167 | recall from the last that disk file is divided into blocks containing many recordsand that the time to access block is much larger than any internal processing on data in main memory for these reasons the overriding consideration in devising an external storage strategy is minimizing the number of block accesses on the... |
25,168 | to implement this scheme the hash function and the size of the hash table must be chosen with some careso that limited number of keys hash to the same value in our example we want only records per keyon the average full blocks even with good hash functiona block will occasionally become full this can be handled using v... |
25,169 | goes to xx+ + + + and so on quadratic probing eliminates primary clusteringbut suffers from the less severe secondary clustering secondary clustering occurs because all the keys that hash to the same value follow the same sequence of steps during probe all keys that hash to the same value follow the same probe sequence... |
25,170 | and activities should be executed sooner than others and are therefore given higher priority another example is in weapons systemssay in navy cruiser variety of threats-airplanesmissilessubmarinesand so on--are detected and must be prioritized for examplea missile that' short distance from the cruiser is assigned highe... |
25,171 | half the items in the array must be moved to insert the new one in order in this we'll describe another structure that can be used to implement priority queuethe heap heap is kind of tree it offers both insertion and deletion in (logntime thus it' not quite as fast for deletionbut much faster for insertion it' the meth... |
25,172 | loweredthe node will trickle downward remove repeatedly pressing the rem button causes the node with the highest keylocated at the rootto be removed you'll see it disappearand then be replaced by the last (rightmostnode on the bottom row finally this node will trickle down until it reaches the position that reestablish... |
25,173 | inside the while loopthe variable index will trickle up the path toward the rootpointing to each node in turn the while loop runs as long as we haven' reached the root (index> and the key (idataof index' parent is less than the new node the body of the while loop executes one step of the trickle-up process it first cop... |
25,174 | leftand if socompare the children' keyssetting largerchild appropriately then we check if the key of the original node (now in topis greater than that of largerchildif sothe trickle-down process is complete and we exit the loop public void trickledown(int indexint largerchildnode top heaparray[index]while(index current... |
25,175 | /end change(this routine first checks that the index given in the first argument is validand if sochanges the idata field of the node at that index to the value specified as the second argument thenif the priority has been raisedthe node is trickled upif it' been loweredthe node is trickled down actuallythe difficult p... |
25,176 | private node[heaparrayprivate int maxsizeprivate int currentsize/size of array /number of nodes in array /public heap(int mx/constructor maxsize mxcurrentsize heaparray new node[maxsize]/create array /public boolean isempty(return currentsize== /public boolean insert(int keyif(currentsize==maxsizereturn falsenode newno... |
25,177 | trickledown( )return root/end remove(/public void trickledown(int indexint largerchildnode top heaparray[index]/save root while(index currentsize/ /while node has at /least one childint leftchild *index+ int rightchild leftchild+ /find larger child if(rightchild currentsize &/(rightchild exists?heaparray[leftchildidata... |
25,178 | if(heaparray[ !nullsystem out printheaparray[midata ")else system out print"-")system out println()/heap format int nblanks int itemsperrow int column int /current item string dots "system out println(dots+dots)/dotted top line while(currentsize if(column = for(int = <nblanksk++system out print(')/for each heap item /f... |
25,179 | theheap insert( )theheap insert( )theheap insert( )theheap insert( )theheap insert( )theheap insert( )theheap insert( )theheap insert( )theheap insert( )/insert items while(true/until [ctrl]-[cputtext("enter first letter of ")puttext("showinsertremovechange")int choice getchar()switch(choicecase ' '/show theheap displa... |
25,180 | system out print( )system out flush()//public static string getstring(throws ioexception inputstreamreader isr new inputstreamreader(system in)bufferedreader br new bufferedreader(isr)string br readline()return //public static char getchar(throws ioexception string getstring()return charat( )//public static int getint(... |
25,181 | enter first letter of showinsertremovechangei enter value to insert enter first letter of showinsertremovechanges heaparray enter first letter of showinsertremovechanger enter first letter of showinsertremovechanges heaparray enter first letter of showinsertremovechangethe user displays the heapadds an item with key of... |
25,182 | the heap arraya new array can be createdand the data from the old array copied into it (unlike the situation with hash tableschanging the size of heap doesn' require reordering the data the copying operation takes linear timebut enlarging the array size shouldn' be necessary very oftenespecially if the array size is in... |
25,183 | howeverif all the items are already in an arraythey can be rearranged into heap with only / applications of trickledown(this offers small speed advantage two correct subheaps make correct heap to see how this worksyou should know that trickledown(will create correct heap ifwhen an out-of-order item is placed at the roo... |
25,184 | recursive approach recursive approach can also be used to form heap from an array heapify(method is applied to the root it calls itself for the root' two childrenthen for each of these children' two childrenand so on eventually it works its way down to the bottom rowwhere it returns immediately whenever it finds node w... |
25,185 | the heapsort java program we can put these two tricks--applying trickledown(without using insert()and using the same array for the initial data and the heap--together in program that performs heapsort listing shows how this looks listing the heapsort java program /heapsort java /demonstrates heap sort /to run this prog... |
25,186 | maxsize mxcurrentsize heaparray new node[maxsize]/public node remove(/delete item with max key /(assumes non-empty listnode root heaparray[ ]heaparray[ heaparray[--currentsize]trickledown( )return root/end remove(/public void trickledown(int indexint largerchildnode top heaparray[index]/save root while(index currentsiz... |
25,187 | if(column = for(int = <nblanksk++system out print(')/for each heap item /first item in row/preceding blanks /display item system out print(heaparray[jidata)if(++ =currentsizebreak/doneif(++column==itemsperrow/end of rownblanks / /half the blanks itemsperrow * /twice the items column /start over on system out println()/... |
25,188 | int sizejsystem out print("enter number of items")size getint()heap theheap new heap(size)for( = <sizej++/fill array with /random nodes int random (int)(java lang math random()* )node newnode new node(random)theheap insertat(jnewnode)theheap incrementsize()system out print("random")theheap displayarray()/display random... |
25,189 | /end class heapsortapp the heap class is much the same as in the heap java programexcept that to save space we've removed the trickleup(and insert(methodswhich aren' necessary for heapsort we've also added an insertat(method that allows direct insertion into the heap' array notice that this addition is not in the spiri... |
25,190 | priority queue is an abstract data type (adtthat offers methods for insertion of data and removal of the largest (or smallestitem heap is an efficient implementation of an adt priority queue heap offers removal of the largest itemand insertionin ( *logntime the largest item is always in the root heaps do not support or... |
25,191 | list graphs weighted graphs when to use what graphs overview graphs are one of the most versatile structures used in computer programming the sorts of problems that graphs can help solve are generally quite different from those we've dealt with thus far in this book if you're dealing with general kinds of data storage ... |
25,192 | in the graphcircles represent freeway interchanges and straight lines connecting the circles represent freeway segments the circles are verticesand the lines are edges the vertices are usually labeled in some way--oftenas shown herewith letters of the alphabet each edge is bounded by the two vertices at its ends the gr... |
25,193 | non-connected graph consists of several connected components in figure -ba and are one connected componentand and are another for simplicitythe algorithms we'll be discussing in this are written to apply to connected graphsor to one connected component of non-connected graph if appropriatesmall modifications will usual... |
25,194 | the problemmuch discussed by the townsfolkwas to find way to walk across all seven bridges without recrossing any of them we won' recount euler' solution to the problemit turns out that there is no such path howeverthe key to his solution was to represent the problem as graphwith land areas as vertices and bridges as e... |
25,195 | placed in list or some other data structure whatever structure is usedthis storage is for convenience only it has no relevance to how the vertices are connected by edges for thiswe need another mechanism edges in "red-black trees,we saw that computer program can represent trees in several ways mostly we examined trees ... |
25,196 | may seem inefficientbut there' no convenient way to create triangular array in most computer languagesso it' simpler to accept the redundancy consequentlywhen you add an edge to the graphyou must make two entries in the adjacency matrix rather than one the adjacency list the other way to represent edges is with an adja... |
25,197 | adjacency matrix adjmatyou filled it with to insert the edgeyou say adjmat[ ][ adjmat[ ][ if you were using an adjacency listyou would add to the list for and to the list for the graph class let' look at class graph that contains methods for creating vertex list and an adjacency matrixand for adding vertices and edges ... |
25,198 | //end class graph within the graph classvertices are identified by their index number in vertexlist we've already discussed most of the methods shown here to display vertexwe simply print out its one-character label the adjacency matrix (or the adjacency listprovides information that is local to given vertex specifical... |
25,199 | when we discussed binary treesvisit means to perform some operation on the vertexsuch as displaying it there are two common approaches to searching graphdepth-first search (dfsand breadth-first search (bfsboth will eventually reach all connected vertices the difference is that the depth-first search is implemented with... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.