[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-697958-105":3,"detail-sidebar-cat-0-en-105":80,"doc-detail-697958-en":130,"doc-similar-697958":161},{"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":73,"head_meta":75,"extra_data":77,"updated_unix":79},105,"en","chapter-3-linked-list-problems","Chapter-3 - Linked List Problems","","Linked list algorithm exercises address three core list operations and two classical problem statements. The first task prints selected nodes from a sorted linked list based on index positions stored in another list, requiring basic list primitives and analyzing efficiency. The next tasks compute the set difference, intersection, and union of two sorted linked lists using only fundamental operations, with linear-time running time analyses. The Josephus problem uses a circularly linked list to eliminate nodes every M passes and asks for correctness and running-time behavior.",{"@graph":14,"@context":72},[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/technology/","Technology",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/document/chapter-3-linked-list-problems/697958/",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/chapter-3-linked-list-problems/697958.png","ImageObject",300,407,{"name":42,"@type":43},"WPS_1793603815","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-11-16","2026-11-12",true,{"@type":52,"interactionType":53,"userInteractionCount":30},"InteractionCounter",{"@type":54},"ViewAction",{"@type":56,"mainEntity":57},"FAQPage",[58,64,68],{"name":59,"@type":60,"acceptedAnswer":61},"How does PrintLots(L, P) decide which elements to print?","Question",{"text":62,"@type":63},"It traverses L and P together, keeping a counter for the current position in L. When P’s current element equals the counter, it prints the corresponding L element and advances P.","Answer",{"name":65,"@type":60,"acceptedAnswer":66},"What running time is stated for Union(L1, L2) and how is it achieved?",{"text":67,"@type":63},"The running time is O(n1 + n2). The procedure merges the two sorted lists by advancing pointers and inserting elements into the result, then flushes any remaining elements.",{"name":69,"@type":60,"acceptedAnswer":70},"How is the Josephus problem modeled in the provided solution?",{"text":71,"@type":63},"A circularly linked list with N nodes simulates the circle. The algorithm repeatedly deletes the next node after counting M passes until one node remains, and returns its number as the winner.","https://schema.org",{"og:url":32,"og:type":74,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":76,"canonical":32},"index,follow",{"doc_id":78,"site_id":7},697958,1794446343,{"code":4,"msg":81,"data":82},"success",[83,87,91,95,100,104,109,114,119,122,126],{"id":22,"doc_module":4,"doc_module_name":25,"category_name":84,"show_sort_weight":85,"slug":86},"Story & Novel",90,"story-novel",{"id":26,"doc_module":4,"doc_module_name":25,"category_name":88,"show_sort_weight":89,"slug":90},"Literature",80,"literature",{"id":33,"doc_module":4,"doc_module_name":25,"category_name":92,"show_sort_weight":93,"slug":94},"Exam",70,"exam",{"id":96,"doc_module":4,"doc_module_name":25,"category_name":97,"show_sort_weight":98,"slug":99},5,"Comic",60,"comic",{"id":101,"doc_module":4,"doc_module_name":25,"category_name":29,"show_sort_weight":102,"slug":103},6,50,"technology",{"id":105,"doc_module":4,"doc_module_name":25,"category_name":106,"show_sort_weight":107,"slug":108},7,"Healthcare",40,"healthcare",{"id":110,"doc_module":4,"doc_module_name":25,"category_name":111,"show_sort_weight":112,"slug":113},8,"Research & Report",30,"research-report",{"id":115,"doc_module":4,"doc_module_name":25,"category_name":116,"show_sort_weight":117,"slug":118},9,"Religion & Spirituality",20,"religion-spirituality",{"id":117,"doc_module":4,"doc_module_name":25,"category_name":120,"show_sort_weight":117,"slug":121},"World Cup","world-cup",{"id":123,"doc_module":4,"doc_module_name":25,"category_name":124,"show_sort_weight":123,"slug":125},10,"Lifestyle","lifestyle",{"id":127,"doc_module":4,"doc_module_name":25,"category_name":128,"show_sort_weight":96,"slug":129},19,"General","general",{"code":4,"msg":81,"data":131},{"doc_id":78,"user_id":132,"nickname":42,"user_avatar":133,"doc_module":4,"category_id":101,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":134,"file_id":135,"file_url":136,"file_type":137,"file_size":138,"view_count":30,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":139,"language":140,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":141,"faqs":142,"seo_title":143,"seo_description":12,"update_tm":79,"read_time":112,"preview_page_count":33,"preview_urls":144},12232076219891,"https://eur-avatar.wpscdn.com/davatar_994ba38a5ba835b3df7d355c54d3ed8d","I Problem DS-03-02 You are given a linked list, L, and another linked list, P , containing integers sorted in ascending order. The operation PrintLots (L;P) will print elements in L that are in positions speci􀀌ed by P. For instance, if P = 1 ; 3 ; 4 ; 6, the 􀀌rst, third, fourth, and sixth elements in L are printed. Write the procedure PrintLots (L;P) . You should use only the basic list operations. What is the running time of your procedure?  \nSolution.  \nvoid PrintLots( List L, List P ){  \nPosition L_pos, P_pos;  \nint Counter = 1;  \nL_pos = L->Next;  \nP_pos = P->Next;  \n// Let L_pos point to the first element of L  \n// Let P_pos point to the first element of P  \nwhile ( L_pos != NULL && P_pos != NULL )  \n{  \nif ( P_pos->Element == Counter)  \n{  \nPrint( L_pos->Element) ;  \nP_pos = P_pos->Next;  \n}  \nL_pos = L_pos->Next;  \nCounter++;  \n}  \n}  \nFor the two linked lists L and P, we assume that the length of L is l and the length of P is p. Then the running time of the above procedure is O (l + p) .  \n􀀃  \nI Problem DS-03-04 Given two sorted lists, L 1 and L2 , write a procedure to compute L 1 \\ L2 using only the basic list operations.  \nSolution.  \nList Intersect( List L1, List L2 ){  \nPosition L1 _pos, L2 _pos, Result_pos;  \nList Result;  \nL1 _pos = L1->Next; // Let L1 _pos point to the first element of L1  \nL2 _pos = L2->Next; // Let L2 _pos point to the first element of L2 Result_pos = Result = MakeEmpty();  \nwhile ( L1_pos != NULL && L2_pos != NULL )  \n{  \nif ( L1_pos->Element \u003C L2_pos->Element )  \nL1 _pos = L1 _pos->Next;  \nelse if ( L1_pos->Element > L2_pos->Element )  \nL2 _pos = L2 _pos->Next;  \nelse  \n{  \nInsert( L1_pos->Element , Result , Result_pos );  \nL1 _pos = L1 _pos->Next;  \nL2 _pos = L2 _pos->Next;  \nResult_pos = Result_pos->Next;  \n}  \n}  \nreturn Result;}  \nFor the two linked lists L 1 and L2 , we assume that the length of L 1 is n 1 and the length of L2 is n2 . Then the running time of the above procedure is O (n1 + n2 ) .  \n􀀃  \nI Problem DS-03-05 Given two sorted lists, L 1 and L2 , write a procedure to compute L 1 [ L2 using only the basic list operations.  \nSolution.  \nList Union( List L1, List L2 ){  \nPosition L1 _pos, L2 _pos, Result_pos;  \nElementType InsertElement;  \nList Result;  \nL1 _pos = L1->Next; // Let L1 _pos point to the first element of L1  \nL2 _pos = L2->Next; // Let L2 _pos point to the first element of L2 Result_pos = Result = MakeEmpty();  \nwhile ( L1_pos != NULL && L2_pos != NULL )  \n{  \nif ( L1_pos->Element \u003C L2_pos->Element ) {  \nInsertElement = L1 _pos->Element;  \nL1 _pos = L1 _pos->Next;  \n}  \nelse if ( L1_pos->Element > L2_pos->Element ) { InsertElement = L2 _pos->Element; L2 _pos = L2 _pos->Next;  \n}  \nelse  \n{  \nInsertElement = L1 _pos->Element;  \nL1 _pos = L1 _pos->Next;  \nL2 _pos = L2 _pos->Next;  \n}  \nInsert( InsertElement , Result , Result_pos );  \nResult_pos = Result_pos->Next;  \n}  \n/* Flush out the remaining list */  \nwhile ( L1_pos != NULL ) {  \nInsert( L1_pos->Element , Result , Result_pos );  \nL1 _pos = L1 _pos->Next;  \nResult_pos = Result_pos->Next;  \n}  \nwhile ( L2_pos != NULL ) {  \nInsert( L2_pos->Element , Result , Result_pos );  \nL2 _pos = L2 _pos->Next;  \nResult_pos = Result_pos->Next;  \n}  \nreturn Result;}  \nFor the two linked lists L 1 and L2 , we assume that the length of L 1 is n 1 and the length of L2 is n2 . Then the running time of the above procedure is O (n1 + n2 ) .  \n􀀃  \nI Problem DS-03-10 The Josephus problem is the following game: N people, numbered 1 to N, are sitting in a circle. Starting at person 1, a hot potato is passed. After M passes, the person holding the hot potato is eliminated, the circle closes ranks, and the game continues with the person who was sitting after the eliminated person picking up the hot potato. The last remaining person wins. Thus, if M = 0 and N = 5, players are eliminated in order, and player 5 wins. If M = 1 and N = 5, the order of elimination is 2, 4, 1, 5 .  \n(a) Write a program to solve the Josephus problem for general val","cbCaikGkPNdZxsCh","https://ap.wps.com/l/cbCaikGkPNdZxsCh","pdf",325799,12,"English","# DS-03-02 PrintLots(L, P)\n## Problem statement and procedure idea\n## Running time analysis\n# DS-03-04 Intersect(L1, L2)\n## Procedure logic\n## Running time analysis\n# DS-03-05 Union(L1, L2)\n## Procedure logic\n## Running time analysis\n# DS-03-10 Josephus problem\n## Program approach using circular list\n## Running time questions","[{\"question\":\"How does PrintLots(L, P) decide which elements to print?\",\"answer\":\"It traverses L and P together, keeping a counter for the current position in L. When P’s current element equals the counter, it prints the corresponding L element and advances P.\"},{\"question\":\"What running time is stated for Union(L1, L2) and how is it achieved?\",\"answer\":\"The running time is O(n1 + n2). The procedure merges the two sorted lists by advancing pointers and inserting elements into the result, then flushes any remaining elements.\"},{\"question\":\"How is the Josephus problem modeled in the provided solution?\",\"answer\":\"A circularly linked list with N nodes simulates the circle. The algorithm repeatedly deletes the next node after counting M passes until one node remains, and returns its number as the winner.\"}]","Chapter-3 - Linked List Problems | PDF",[145,149,153,157],{"page_no":22,"url":146,"width":147,"height":148},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-12/aac3d323ee10d4f670bdd281ac3b6000.webp",983,1391,{"page_no":26,"url":150,"width":151,"height":152},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-12/cc9bd84efb151333e31fd264f6d49e6e.webp",982,1389,{"page_no":30,"url":154,"width":155,"height":156},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-12/fdd63cfcbcc216f061932c2e3f9918bf.webp",981,1388,{"page_no":33,"url":158,"width":159,"height":160},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-12/0d5928c8d9aaf874801710cf477e65ea.webp",980,1387,{"list":162,"token":11},[163,169,175,181,187,193,199,205,211,217],{"doc_id":164,"doc_title":165,"file_type":137,"home_preview_img_url":166,"slug":167,"view_count":96,"category_name":29,"create_tm":168},698700,"Skip Lists - CMSC 420 - Linked Lists Benefits & Drawbacks","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230010410173/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110859&Signature=duWxjp9EezhvXzsgWqCWGDg%2Fuao%3D","skip-lists-cmsc-420-linked-lists-benefits-drawbacks",1794454906,{"doc_id":170,"doc_title":171,"file_type":137,"home_preview_img_url":172,"slug":173,"view_count":30,"category_name":29,"create_tm":174},732877,"Linked Data Structures - Linked Lists","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230031413515/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110859&Signature=6VfgpSUYKovRVnq%2F8V85T%2FLuzpg%3D","linked-data-structures-linked-lists",1795382677,{"doc_id":176,"doc_title":177,"file_type":137,"home_preview_img_url":178,"slug":179,"view_count":30,"category_name":29,"create_tm":180},732880,"Linked List Basics - Linked List Basics - Insertion, Deletion, Navigation, and Advanced Operations","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230031780344/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110859&Signature=tadBF2KdVOqyhC9syJW%2Fo4m0F4c%3D","linked-list-basics-linked-list-basics-insertion-deletion-navigation-and-advanced-operations",1795382679,{"doc_id":182,"doc_title":183,"file_type":137,"home_preview_img_url":184,"slug":185,"view_count":96,"category_name":29,"create_tm":186},685726,"L6b - Linked List Variations - Lecture 6b","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000185855/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110859&Signature=VVQQcaH1u%2FKjHpn%2B1U7%2BjZ2onsU%3D","l6b-linked-list-variations-lecture-6b",1794017196,{"doc_id":188,"doc_title":189,"file_type":137,"home_preview_img_url":190,"slug":191,"view_count":33,"category_name":29,"create_tm":192},685767,"Implementation of Linked List - Lecture 7 - In C++","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000198089/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110859&Signature=HLbDQcsejilXVKvZeqCcKh5ednE%3D","implementation-of-linked-list-lecture-7-in-c",1794017950,{"doc_id":194,"doc_title":195,"file_type":137,"home_preview_img_url":196,"slug":197,"view_count":33,"category_name":29,"create_tm":198},685736,"Singly Linked List in C - C Program - Linked List Operations Menu","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000186160/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110859&Signature=5q5jMFQVECm%2FMwcr0kfKB443PXk%3D","singly-linked-list-in-c-c-program-linked-list-operations-menu",1794017213,{"doc_id":200,"doc_title":201,"file_type":137,"home_preview_img_url":202,"slug":203,"view_count":101,"category_name":29,"create_tm":204},685764,"Lists and Linked Lists - Part 1 - Introduction","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999691137/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110859&Signature=KpRz2Yvu9tpqkUmXGZpokiH2Nc8%3D","lists-and-linked-lists-part-1-introduction",1794017635,{"doc_id":206,"doc_title":207,"file_type":137,"home_preview_img_url":208,"slug":209,"view_count":101,"category_name":29,"create_tm":210},697937,"Doubly Linked List - Basic Operations and Circular Linked List","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230010136388/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110859&Signature=eEUdFSf6%2FKQHLVISOj4FTbYaGsQ%3D","doubly-linked-list-basic-operations-and-circular-linked-list",1794446062,{"doc_id":212,"doc_title":213,"file_type":137,"home_preview_img_url":214,"slug":215,"view_count":96,"category_name":29,"create_tm":216},685723,"Fundamentals of Linked Lists - Chapter Summary","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000182525/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110859&Signature=nX1HYfAmK2kR%2BKJEW%2BzjA7zVkGE%3D","fundamentals-of-linked-lists-chapter-summary",1794016982,{"doc_id":218,"doc_title":219,"file_type":137,"home_preview_img_url":220,"slug":221,"view_count":26,"category_name":29,"create_tm":222},719605,"Linked Lists - lecture notes","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230023815899/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110859&Signature=qU9YjE2jzVc30mOkCG3ieLWQxlk%3D","linked-lists-lecture-notes",1795006752]