[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-685747-105":3,"detail-sidebar-cat-0-en-105":84,"doc-detail-685747-en":134,"doc-similar-685747":162},{"code":4,"msg":5,"data":6},0,"ok",{"site_id":7,"language":8,"slug":9,"title":10,"keywords":11,"description":12,"schema_data":13,"social_meta":77,"head_meta":79,"extra_data":81,"updated_unix":83},105,"en","implementing-a-graph-adjacency-list-and-search-algorithms","Implementing a Graph - Adjacency List and Search Algorithms","","Implementing a graph using three representations—adjacency list, adjacency matrix, and node pointers/memory—then comparing their memory and lookup characteristics. The adjacency list uses space O(V+E) and sums adjacency lengths to 2|E| for undirected graphs or |E| for directed graphs, while the adjacency matrix always uses Θ(V^2) memory and suits weighted graphs by storing edge weights. It then covers graph traversal via searching, focusing on breadth-first search (BFS) with FIFO queue properties and shortest-path distance claims, and depth-first search (DFS) with recursive visitation, discover/finish timestamps, and forest results when parts are unreachable.",{"@graph":14,"@context":76},[15,34,55],{"@type":16,"itemListElement":17},"BreadcrumbList",[18,23,27,31],{"item":19,"name":20,"@type":21,"position":22},"https://docshare.wps.com","Home","ListItem",1,{"item":24,"name":25,"@type":21,"position":26},"https://docshare.wps.com/document/","Document",2,{"item":28,"name":29,"@type":21,"position":30},"https://docshare.wps.com/document/research-report/","Research & Report",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/document/implementing-a-graph-adjacency-list-and-search-algorithms/685747/",4,{"url":32,"name":10,"@type":35,"image":36,"author":41,"headline":10,"publisher":44,"fileFormat":47,"inLanguage":8,"description":12,"dateModified":48,"datePublished":49,"encodingFormat":47,"isAccessibleForFree":50,"interactionStatistic":51},"DigitalDocument",{"url":37,"@type":38,"width":39,"height":40},"https://docshare.wps.com/thumbnails/implementing-a-graph-adjacency-list-and-search-algorithms/685747.png","ImageObject",300,407,{"name":42,"@type":43},"Theodore","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-11-24","2026-11-07",true,{"@type":52,"interactionType":53,"userInteractionCount":33},"InteractionCounter",{"@type":54},"ViewAction",{"@type":56,"mainEntity":57},"FAQPage",[58,64,68,72],{"name":59,"@type":60,"acceptedAnswer":61},"What are the three main ways to implement a graph discussed here?","Question",{"text":62,"@type":63},"The document presents adjacency list, adjacency matrix, and pointers/memory for each node (described as a form of adjacency list).","Answer",{"name":65,"@type":60,"acceptedAnswer":66},"How do adjacency list and adjacency matrix differ in memory usage and suitability?",{"text":67,"@type":63},"Adjacency lists require O(V+E) space and store neighbors per vertex, while adjacency matrices always use Θ(V^2) memory. The matrix is especially useful for weighted graphs by placing weights in entries.",{"name":69,"@type":60,"acceptedAnswer":70},"What key properties and guarantees does BFS provide?",{"text":71,"@type":63},"BFS maintains a FIFO queue whose size is O(V) and runs in O(V+E). It computes the shortest-path distance between the source S and each reachable vertex I, skipping the proof.",{"name":73,"@type":60,"acceptedAnswer":74},"What does DFS produce when some nodes are unreachable from the source?",{"text":75,"@type":63},"DFS still visits all vertices; unreachable regions form additional trees, resulting in a forest of unconnected graphs without cycles.","https://schema.org",{"og:url":32,"og:type":78,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":80,"canonical":32},"index,follow",{"doc_id":82,"site_id":7},685747,1794017497,{"code":4,"msg":85,"data":86},"success",[87,91,95,99,104,109,114,118,123,126,130],{"id":22,"doc_module":4,"doc_module_name":25,"category_name":88,"show_sort_weight":89,"slug":90},"Story & Novel",90,"story-novel",{"id":26,"doc_module":4,"doc_module_name":25,"category_name":92,"show_sort_weight":93,"slug":94},"Literature",80,"literature",{"id":33,"doc_module":4,"doc_module_name":25,"category_name":96,"show_sort_weight":97,"slug":98},"Exam",70,"exam",{"id":100,"doc_module":4,"doc_module_name":25,"category_name":101,"show_sort_weight":102,"slug":103},5,"Comic",60,"comic",{"id":105,"doc_module":4,"doc_module_name":25,"category_name":106,"show_sort_weight":107,"slug":108},6,"Technology",50,"technology",{"id":110,"doc_module":4,"doc_module_name":25,"category_name":111,"show_sort_weight":112,"slug":113},7,"Healthcare",40,"healthcare",{"id":115,"doc_module":4,"doc_module_name":25,"category_name":29,"show_sort_weight":116,"slug":117},8,30,"research-report",{"id":119,"doc_module":4,"doc_module_name":25,"category_name":120,"show_sort_weight":121,"slug":122},9,"Religion & Spirituality",20,"religion-spirituality",{"id":121,"doc_module":4,"doc_module_name":25,"category_name":124,"show_sort_weight":121,"slug":125},"World Cup","world-cup",{"id":127,"doc_module":4,"doc_module_name":25,"category_name":128,"show_sort_weight":127,"slug":129},10,"Lifestyle","lifestyle",{"id":131,"doc_module":4,"doc_module_name":25,"category_name":132,"show_sort_weight":100,"slug":133},19,"General","general",{"code":4,"msg":85,"data":135},{"doc_id":82,"user_id":136,"nickname":42,"user_avatar":137,"doc_module":4,"category_id":115,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":138,"file_id":139,"file_url":140,"file_type":141,"file_size":142,"view_count":33,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":143,"language":144,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":145,"faqs":146,"seo_title":147,"seo_description":12,"update_tm":83,"read_time":148,"preview_page_count":30,"preview_urls":149},7971461740886,"https://ap-avatar.wpscdn.com/davatar_3d24733baf745e90a7e4bdd5f77d97b2","Implementing a Graph  \n• Implement a graph in three ways:  \n– Adjacency List  \n– Adjacency-Matrix  \n– Pointers/memory for each node (actually a form of adjacency list)  \nAdjacency List  \n• List of pointers for each vertex  \n1 2  \n3 4  \n5  \n􀁯  \n􀁯  \n􀁯  \n􀁯  \n􀁯  \n2  \n4 1  \n2  \n􀁯  \n􀁯  \n3  \n4  \nUndirected Adjacency List  \n1 2  \n3 4  \n5  \n􀁯  \n􀁯  \n􀁯  \n􀁯  \n􀁯  \n2 1  \n4 1  \n2  \n􀁯  \n􀁯  \n􀁯  \n􀁯  \n􀁯  \n3 5  \n1 3  \n4  \n􀁯  \n4  \nAdjacency List  \n• The sum of the lengths ofthe adjacency lists is 2|E| in an undirected graph, and |E| ina directed graph.  \n• The amount of memory to store the array for the adjacency list is  \nO(max(V,E))=O(V+E) .  \nAdjacency Matrix  \n1 2  \n3 4  \n5  \n1 0  \n0 0  \n1 0  \n2 1  \n0 0  \n0 1  \n3 1  \n0 0  \n0 0  \n4 0  \n0 1  \n0 1  \n5 0  \n0 0  \n0 0  \nUndirected Adjacency Matrix  \n1 2 3 4 5 1 0 1 1 1 0 2 1 0 0 0 1 3 1 0 0 1 0 4 1 0 1 0 1  \n5 0 1 0 1 0  \nAdjacency Matrix vs. List?  \n• The matrix always uses Θ(v2) memory. Usually easier to implement and perform lookup than anadjacency list.  \n• Sparse graph: very few edges.  \n• Dense graph: lots of edges. Up to O(v2) edges if fully connected.  \n• The adjacency matrix is a good way to represent a weighted graph. In a weighted graph, the edges have weights associated with them. Update matrix entry to contain the weight. Weights could indicate distance, cost, etc.  \nSearching a Graph  \n• Search: The goal is to methodically explore every vertex and every edge; perhaps to do some processing on each.  \n• For the most part in our algorithms we will assume an adjacency-list representation of the input graph.  \nBreadth First Search  \n• Example 1: Binary Tree. This is a special case of a graph.  \n– The order of search is across levels.  \n– The root is examined first; then both children of the root; then the children of those nodes, etc.  \n2 3  \n4 5 6 7  \nBreadth First Search  \n• Example 2: Directed Graph  \n• Pick a source vertex S to start.  \n• Find (or discover) the vertices that are adjacent to S.  \n• Pick each child of S in turn and discover their vertices adjacent to that child.  \n• Done when all children have been discovered and examined.  \n• This results in a tree that is rooted at the source vertex S.  \n• The idea is to find the distance from some Source vertex by expanding the “frontier” of what we have visited.  \nBreadth First Search Algorithm  \n• Pseudocode: Uses FIFO Queue Q  \nBFS Example  \n• Final State shown  \nCan create tree out of order we visit nodes  \n0  \nb c 1  \ne f 2  \nd h i g 3  \nBFS Properties  \n• Memory required: Need to maintain Q, which contains a list of all fringe vertices we need to explore, O(V)  \n• Runtime: O(V+E) ; O(E) to scan through adjacency list and O(V) to visit each vertex. This is considered linear time in the size of G.  \n• Claim: BFS always computes the shortest path distance ind[i] between S and vertex I. We will skip the proof.  \n• What if some nodes are unreachable from the source?(reverse c-e,f-h edges) . What values do these nodes get?  \nDepth First Search  \n• Example 1: DFS on binary tree. Specialized case of more general graph. The order of the search is down paths and from left to right.  \n– The root is examined first; then the left child of the root; then the left child of this node, etc. until a leaf is found. At a leaf, backtrack to the lowest right child and repeat.  \n1  \n2 5  \n3 4 6 7  \nDepth First Search  \n• Example 2: DFS on directed graph.  \n• Start at some source vertex S.  \n• Find (or explore) the first vertex that is adjacent to S.  \n• Repeat with this vertex and explore the first vertex that is adjacent to it.  \n• When a vertex is found that has no unexplored vertices adjacent to it then backtrack up one level  \n• Done when all children have been discovered and examined.  \n• Results in a forest of trees.  \nDFS Algorithm  \n• Pseudocode  \nDFS(s)  \nfor each vertex u 􀂏V  \ndo color[u] 􀁭 White ; not visited  \ntime 􀁭 1 ; time stamp  \nfor each vertex u 􀂏V  \ndo if color[u]=White  \nthen DFS-Visit(u,time)  \nDFS-Visit(u,time)  \ncolor[u] 􀁭 Gray ;","cbCaivSP4OrI40hH","https://ap.wps.com/l/cbCaivSP4OrI40hH","pdf",331740,29,"English","# Implementing a Graph\n## Adjacency List\n## Undirected Adjacency List\n## Adjacency Matrix\n## Undirected Adjacency Matrix\n## Adjacency Matrix vs. List\n## Searching a Graph\n## Breadth First Search\n## Breadth First Search Algorithm\n## BFS Properties\n## Depth First Search\n## DFS Algorithm\n## DFS Example","[{\"question\":\"What are the three main ways to implement a graph discussed here?\",\"answer\":\"The document presents adjacency list, adjacency matrix, and pointers/memory for each node (described as a form of adjacency list).\"},{\"question\":\"How do adjacency list and adjacency matrix differ in memory usage and suitability?\",\"answer\":\"Adjacency lists require O(V+E) space and store neighbors per vertex, while adjacency matrices always use Θ(V^2) memory. The matrix is especially useful for weighted graphs by placing weights in entries.\"},{\"question\":\"What key properties and guarantees does BFS provide?\",\"answer\":\"BFS maintains a FIFO queue whose size is O(V) and runs in O(V+E). It computes the shortest-path distance between the source S and each reachable vertex I, skipping the proof.\"},{\"question\":\"What does DFS produce when some nodes are unreachable from the source?\",\"answer\":\"DFS still visits all vertices; unreachable regions form additional trees, resulting in a forest of unconnected graphs without cycles.\"}]","Implementing a Graph - Adjacency List and Search Algorithms | PDF",73,[150,154,158],{"page_no":22,"url":151,"width":152,"height":153},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/06b31047461413120a8711eebde63a35.webp",983,1290,{"page_no":26,"url":155,"width":156,"height":157},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/4a30fa953f9e49f2508b476aa2543cb5.webp",982,1289,{"page_no":30,"url":159,"width":160,"height":161},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/b1360d0fe334208117b88f47a22e8537.webp",981,1287,{"list":163,"token":11},[164,171,177,183,189,195,201,208,214,221],{"doc_id":165,"doc_title":166,"file_type":141,"home_preview_img_url":167,"slug":168,"view_count":169,"category_name":29,"create_tm":170},83056,"Breadth-First Search in Succinct Planar Graphs","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229808930398/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796108879&Signature=qCxP%2BfkfAcWcY2MqUukqWUIp%2Fog%3D","breadth-first-search-in-succinct-planar-graphs",25,1784184907,{"doc_id":172,"doc_title":173,"file_type":141,"home_preview_img_url":174,"slug":175,"view_count":105,"category_name":29,"create_tm":176},698895,"CMANNS - GPU-Accelerated Graph Index Construction for ANNS via Compute–Memory Disaggregation","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230010468133/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796108879&Signature=YZu7pbDLFyzf32rmZLghvts2PL0%3D","cmanns-gpu-accelerated-graph-index-construction-for-anns-via-computememory-disaggregation",1794456535,{"doc_id":178,"doc_title":179,"file_type":141,"home_preview_img_url":180,"slug":181,"view_count":33,"category_name":29,"create_tm":182},685895,"GPU-based Graph Traversal on Compressed Graphs","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000265087/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796108879&Signature=OyufBzVgxe1ZU%2BKWFbiv0ZDkiWQ%3D","gpu-based-graph-traversal-on-compressed-graphs",1794021617,{"doc_id":184,"doc_title":185,"file_type":141,"home_preview_img_url":186,"slug":187,"view_count":33,"category_name":29,"create_tm":188},686408,"Large-Scale Graph Processing Algorithms on the GPU","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000814097/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796108879&Signature=30zVWGG47HGRORw%2F2LCp3W%2FX%2FF8%3D","large-scale-graph-processing-algorithms-on-the-gpu",1794042463,{"doc_id":190,"doc_title":191,"file_type":141,"home_preview_img_url":192,"slug":193,"view_count":119,"category_name":29,"create_tm":194},654481,"Chapter 18 - Spectral Graph Drawing - Graph Drawing and Energy Minimization","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229974402626/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796108879&Signature=UXgReb26v7AzcISMn9dBfmaJWtc%3D","chapter-18-spectral-graph-drawing-graph-drawing-and-energy-minimization",1792919879,{"doc_id":196,"doc_title":197,"file_type":141,"home_preview_img_url":198,"slug":199,"view_count":116,"category_name":29,"create_tm":200},83793,"Beyond Trees: The Weighted Center Problem on Gromov Hyperbolic Graphs","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229809096489/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796108879&Signature=qcF1F9BSNFBNPBSokmSnJWycXjc%3D","beyond-trees-the-weighted-center-problem-on-gromov-hyperbolic-graphs",1784190443,{"doc_id":202,"doc_title":203,"file_type":141,"home_preview_img_url":204,"slug":205,"view_count":206,"category_name":29,"create_tm":207},81960,"The Minimum Dominating Set Problem on Bipartite Circle Graphs: Complexity and Approximation","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229808698421/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796108879&Signature=w11QYk3IL7RoP7%2BbZKIvoltGD1g%3D","the-minimum-dominating-set-problem-on-bipartite-circle-graphs-complexity-and-approximation",23,1784177297,{"doc_id":209,"doc_title":210,"file_type":141,"home_preview_img_url":211,"slug":212,"view_count":116,"category_name":29,"create_tm":213},84971,"A General Reduction from Near-Additive Emulators to Near-Exact Hopsets","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229809227191/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796108879&Signature=Lpqm3M1Gzep3Lc6H%2FvUTj5jYkWg%3D","a-general-reduction-from-near-additive-emulators-to-near-exact-hopsets",1784199867,{"doc_id":215,"doc_title":216,"file_type":141,"home_preview_img_url":217,"slug":218,"view_count":219,"category_name":29,"create_tm":220},86504,"Independent Set Reconfiguration on Threshold Signed Graphs","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229809526955/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796108879&Signature=0rXrvmhJSUCZazpYp8LNdrLXNsc%3D","independent-set-reconfiguration-on-threshold-signed-graphs",22,1784212241,{"doc_id":222,"doc_title":223,"file_type":141,"home_preview_img_url":224,"slug":225,"view_count":226,"category_name":29,"create_tm":227},83808,"GORIO GPU-Centered Remote I/O for Graph ANNS over NVMe-oF Technical Report","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229809001096/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796108879&Signature=td47O3rtVpd1rA8gZ6vN3bGTJTI%3D","gorio-gpu-centered-remote-io-for-graph-anns-over-nvme-of-technical-report",37,1784190545]