SlideShare a Scribd company logo
1 of 1
Download to read offline
1) What data structure will you use for iterative post-order tree traversal? Explain how.
2) Given a binary tree (not necessarily a BST), return all root-to-leaf paths. Explain two
solutions: one using stack, another one using queue.
No code, just psuedocode + Description
Solution
1) stack data structure is used for iterative post-order tree traversal.
The idea is to move down to leftmost node using left pointer. While moving down, push root and
root’s right child to stack. Once we reach leftmost node, print it if it doesn’t have a right child. If
it has a right child, then change root so that the right child is processed before.
Algorithm
2)DFS uses stack
In depth-first search the idea is to travel as deep as possible from neighbour to neighbour before
backtracking. What determines how deep is possible is that you must follow edges, and you
don't visit any vertex twice.
pseudocode:
BFS uses queue
BFS starting from vertex v:
create a queue Q
mark v as visited and put v into Q
while Q is non-empty
remove the head u of Q
mark and enqueue all (unvisited)
neighbours of u

More Related Content

Similar to 1) What data structure will you use for iterative post-order tree tr.pdf

trees in data structure
trees in data structure trees in data structure
trees in data structure shameen khan
 
Advanced data structures using c++ 3
Advanced data structures using c++ 3Advanced data structures using c++ 3
Advanced data structures using c++ 3Shaili Choudhary
 
Biary search Tree.docx
Biary search Tree.docxBiary search Tree.docx
Biary search Tree.docxsowmya koneru
 
Tree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal KhanTree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal KhanDaniyal Khan
 
Riya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptx
Riya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptxRiya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptx
Riya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptxRIYABEPARI
 
Bsc cs ii dfs u-3 tree and graph
Bsc cs  ii dfs u-3 tree and graphBsc cs  ii dfs u-3 tree and graph
Bsc cs ii dfs u-3 tree and graphRai University
 
Binary tree and operations
Binary tree and operations Binary tree and operations
Binary tree and operations varagilavanya
 
(5) collections algorithms
(5) collections algorithms(5) collections algorithms
(5) collections algorithmsNico Ludwig
 

Similar to 1) What data structure will you use for iterative post-order tree tr.pdf (12)

trees in data structure
trees in data structure trees in data structure
trees in data structure
 
Advanced data structures using c++ 3
Advanced data structures using c++ 3Advanced data structures using c++ 3
Advanced data structures using c++ 3
 
Biary search Tree.docx
Biary search Tree.docxBiary search Tree.docx
Biary search Tree.docx
 
Data structure
Data structureData structure
Data structure
 
Tree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal KhanTree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal Khan
 
BINARY SEARCH TREE
BINARY SEARCH TREEBINARY SEARCH TREE
BINARY SEARCH TREE
 
Riya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptx
Riya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptxRiya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptx
Riya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptx
 
Bsc cs ii dfs u-3 tree and graph
Bsc cs  ii dfs u-3 tree and graphBsc cs  ii dfs u-3 tree and graph
Bsc cs ii dfs u-3 tree and graph
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 
Unit 4.1 (tree)
Unit 4.1 (tree)Unit 4.1 (tree)
Unit 4.1 (tree)
 
Binary tree and operations
Binary tree and operations Binary tree and operations
Binary tree and operations
 
(5) collections algorithms
(5) collections algorithms(5) collections algorithms
(5) collections algorithms
 

More from arkurkuri

Find an artticle or advertisment that exemplifies the use of the sta.pdf
Find an artticle or advertisment that exemplifies the use of the sta.pdfFind an artticle or advertisment that exemplifies the use of the sta.pdf
Find an artticle or advertisment that exemplifies the use of the sta.pdfarkurkuri
 
A researcher is studying the mean weight of a killer whale. She coll.pdf
A researcher is studying the mean weight of a killer whale. She coll.pdfA researcher is studying the mean weight of a killer whale. She coll.pdf
A researcher is studying the mean weight of a killer whale. She coll.pdfarkurkuri
 
Date Due Feb 8. 2017 Students Name Please name and fill in t.pdf
Date Due Feb 8. 2017 Students Name Please name and fill in t.pdfDate Due Feb 8. 2017 Students Name Please name and fill in t.pdf
Date Due Feb 8. 2017 Students Name Please name and fill in t.pdfarkurkuri
 
Compare and contrast passive transport and active transport Compare .pdf
Compare and contrast passive transport and active transport  Compare .pdfCompare and contrast passive transport and active transport  Compare .pdf
Compare and contrast passive transport and active transport Compare .pdfarkurkuri
 
42. What does a coefficient of correlation of 0.70 infer A) Almost .pdf
42. What does a coefficient of correlation of 0.70 infer A) Almost .pdf42. What does a coefficient of correlation of 0.70 infer A) Almost .pdf
42. What does a coefficient of correlation of 0.70 infer A) Almost .pdfarkurkuri
 
4. On an illegal wolf ranch in Wyoming, gray wolves are bred and sol.pdf
4. On an illegal wolf ranch in Wyoming, gray wolves are bred and sol.pdf4. On an illegal wolf ranch in Wyoming, gray wolves are bred and sol.pdf
4. On an illegal wolf ranch in Wyoming, gray wolves are bred and sol.pdfarkurkuri
 
Use the given information to find the values of sin 2theta. cos2theta.pdf
Use the given information to find the values of sin 2theta. cos2theta.pdfUse the given information to find the values of sin 2theta. cos2theta.pdf
Use the given information to find the values of sin 2theta. cos2theta.pdfarkurkuri
 
What is the command to transfer the file stored in ~lab3README fro.pdf
What is the command to transfer the file stored in ~lab3README fro.pdfWhat is the command to transfer the file stored in ~lab3README fro.pdf
What is the command to transfer the file stored in ~lab3README fro.pdfarkurkuri
 
2.51. Why does earth have seasons2. What is the origin of the t.pdf
2.51. Why does earth have seasons2. What is the origin of the t.pdf2.51. Why does earth have seasons2. What is the origin of the t.pdf
2.51. Why does earth have seasons2. What is the origin of the t.pdfarkurkuri
 
Write the product as a sum or difference. Write the product as a sum.pdf
Write the product as a sum or difference. Write the product as a sum.pdfWrite the product as a sum or difference. Write the product as a sum.pdf
Write the product as a sum or difference. Write the product as a sum.pdfarkurkuri
 
Which osmotic and ionic strategies must marine teleost fishes employ.pdf
Which osmotic and ionic strategies must marine teleost fishes employ.pdfWhich osmotic and ionic strategies must marine teleost fishes employ.pdf
Which osmotic and ionic strategies must marine teleost fishes employ.pdfarkurkuri
 
What types of social and culture trends affect REISolution1. .pdf
What types of social and culture trends affect REISolution1. .pdfWhat types of social and culture trends affect REISolution1. .pdf
What types of social and culture trends affect REISolution1. .pdfarkurkuri
 
Which of the following are in the order Primates (Multiple answers).pdf
Which of the following are in the order Primates (Multiple answers).pdfWhich of the following are in the order Primates (Multiple answers).pdf
Which of the following are in the order Primates (Multiple answers).pdfarkurkuri
 
What are the issues and benefits of employing older workers Wh.pdf
What are the issues and benefits of employing older workers Wh.pdfWhat are the issues and benefits of employing older workers Wh.pdf
What are the issues and benefits of employing older workers Wh.pdfarkurkuri
 
What is current I1What is current I2What is current I3 14 V 1.pdf
What is current I1What is current I2What is current I3 14 V 1.pdfWhat is current I1What is current I2What is current I3 14 V 1.pdf
What is current I1What is current I2What is current I3 14 V 1.pdfarkurkuri
 
Use your thoughts about the essay, , and your own reflections on y.pdf
Use your thoughts about the essay, , and your own reflections on y.pdfUse your thoughts about the essay, , and your own reflections on y.pdf
Use your thoughts about the essay, , and your own reflections on y.pdfarkurkuri
 
12-1 Group Work Preliminary and Program Development ResearchPurp.pdf
12-1 Group Work Preliminary and Program Development ResearchPurp.pdf12-1 Group Work Preliminary and Program Development ResearchPurp.pdf
12-1 Group Work Preliminary and Program Development ResearchPurp.pdfarkurkuri
 
This homework consists of 8 problems. The first 7ask that .pdf
This homework consists of 8 problems. The first 7ask that .pdfThis homework consists of 8 problems. The first 7ask that .pdf
This homework consists of 8 problems. The first 7ask that .pdfarkurkuri
 
this is verilog HDL classWhat are the basic components of a module.pdf
this is verilog HDL classWhat are the basic components of a module.pdfthis is verilog HDL classWhat are the basic components of a module.pdf
this is verilog HDL classWhat are the basic components of a module.pdfarkurkuri
 
The Hox genes are responsible for determining the anterior-posterior.pdf
The Hox genes are responsible for determining the anterior-posterior.pdfThe Hox genes are responsible for determining the anterior-posterior.pdf
The Hox genes are responsible for determining the anterior-posterior.pdfarkurkuri
 

More from arkurkuri (20)

Find an artticle or advertisment that exemplifies the use of the sta.pdf
Find an artticle or advertisment that exemplifies the use of the sta.pdfFind an artticle or advertisment that exemplifies the use of the sta.pdf
Find an artticle or advertisment that exemplifies the use of the sta.pdf
 
A researcher is studying the mean weight of a killer whale. She coll.pdf
A researcher is studying the mean weight of a killer whale. She coll.pdfA researcher is studying the mean weight of a killer whale. She coll.pdf
A researcher is studying the mean weight of a killer whale. She coll.pdf
 
Date Due Feb 8. 2017 Students Name Please name and fill in t.pdf
Date Due Feb 8. 2017 Students Name Please name and fill in t.pdfDate Due Feb 8. 2017 Students Name Please name and fill in t.pdf
Date Due Feb 8. 2017 Students Name Please name and fill in t.pdf
 
Compare and contrast passive transport and active transport Compare .pdf
Compare and contrast passive transport and active transport  Compare .pdfCompare and contrast passive transport and active transport  Compare .pdf
Compare and contrast passive transport and active transport Compare .pdf
 
42. What does a coefficient of correlation of 0.70 infer A) Almost .pdf
42. What does a coefficient of correlation of 0.70 infer A) Almost .pdf42. What does a coefficient of correlation of 0.70 infer A) Almost .pdf
42. What does a coefficient of correlation of 0.70 infer A) Almost .pdf
 
4. On an illegal wolf ranch in Wyoming, gray wolves are bred and sol.pdf
4. On an illegal wolf ranch in Wyoming, gray wolves are bred and sol.pdf4. On an illegal wolf ranch in Wyoming, gray wolves are bred and sol.pdf
4. On an illegal wolf ranch in Wyoming, gray wolves are bred and sol.pdf
 
Use the given information to find the values of sin 2theta. cos2theta.pdf
Use the given information to find the values of sin 2theta. cos2theta.pdfUse the given information to find the values of sin 2theta. cos2theta.pdf
Use the given information to find the values of sin 2theta. cos2theta.pdf
 
What is the command to transfer the file stored in ~lab3README fro.pdf
What is the command to transfer the file stored in ~lab3README fro.pdfWhat is the command to transfer the file stored in ~lab3README fro.pdf
What is the command to transfer the file stored in ~lab3README fro.pdf
 
2.51. Why does earth have seasons2. What is the origin of the t.pdf
2.51. Why does earth have seasons2. What is the origin of the t.pdf2.51. Why does earth have seasons2. What is the origin of the t.pdf
2.51. Why does earth have seasons2. What is the origin of the t.pdf
 
Write the product as a sum or difference. Write the product as a sum.pdf
Write the product as a sum or difference. Write the product as a sum.pdfWrite the product as a sum or difference. Write the product as a sum.pdf
Write the product as a sum or difference. Write the product as a sum.pdf
 
Which osmotic and ionic strategies must marine teleost fishes employ.pdf
Which osmotic and ionic strategies must marine teleost fishes employ.pdfWhich osmotic and ionic strategies must marine teleost fishes employ.pdf
Which osmotic and ionic strategies must marine teleost fishes employ.pdf
 
What types of social and culture trends affect REISolution1. .pdf
What types of social and culture trends affect REISolution1. .pdfWhat types of social and culture trends affect REISolution1. .pdf
What types of social and culture trends affect REISolution1. .pdf
 
Which of the following are in the order Primates (Multiple answers).pdf
Which of the following are in the order Primates (Multiple answers).pdfWhich of the following are in the order Primates (Multiple answers).pdf
Which of the following are in the order Primates (Multiple answers).pdf
 
What are the issues and benefits of employing older workers Wh.pdf
What are the issues and benefits of employing older workers Wh.pdfWhat are the issues and benefits of employing older workers Wh.pdf
What are the issues and benefits of employing older workers Wh.pdf
 
What is current I1What is current I2What is current I3 14 V 1.pdf
What is current I1What is current I2What is current I3 14 V 1.pdfWhat is current I1What is current I2What is current I3 14 V 1.pdf
What is current I1What is current I2What is current I3 14 V 1.pdf
 
Use your thoughts about the essay, , and your own reflections on y.pdf
Use your thoughts about the essay, , and your own reflections on y.pdfUse your thoughts about the essay, , and your own reflections on y.pdf
Use your thoughts about the essay, , and your own reflections on y.pdf
 
12-1 Group Work Preliminary and Program Development ResearchPurp.pdf
12-1 Group Work Preliminary and Program Development ResearchPurp.pdf12-1 Group Work Preliminary and Program Development ResearchPurp.pdf
12-1 Group Work Preliminary and Program Development ResearchPurp.pdf
 
This homework consists of 8 problems. The first 7ask that .pdf
This homework consists of 8 problems. The first 7ask that .pdfThis homework consists of 8 problems. The first 7ask that .pdf
This homework consists of 8 problems. The first 7ask that .pdf
 
this is verilog HDL classWhat are the basic components of a module.pdf
this is verilog HDL classWhat are the basic components of a module.pdfthis is verilog HDL classWhat are the basic components of a module.pdf
this is verilog HDL classWhat are the basic components of a module.pdf
 
The Hox genes are responsible for determining the anterior-posterior.pdf
The Hox genes are responsible for determining the anterior-posterior.pdfThe Hox genes are responsible for determining the anterior-posterior.pdf
The Hox genes are responsible for determining the anterior-posterior.pdf
 

Recently uploaded

How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 

Recently uploaded (20)

Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 

1) What data structure will you use for iterative post-order tree tr.pdf

  • 1. 1) What data structure will you use for iterative post-order tree traversal? Explain how. 2) Given a binary tree (not necessarily a BST), return all root-to-leaf paths. Explain two solutions: one using stack, another one using queue. No code, just psuedocode + Description Solution 1) stack data structure is used for iterative post-order tree traversal. The idea is to move down to leftmost node using left pointer. While moving down, push root and root’s right child to stack. Once we reach leftmost node, print it if it doesn’t have a right child. If it has a right child, then change root so that the right child is processed before. Algorithm 2)DFS uses stack In depth-first search the idea is to travel as deep as possible from neighbour to neighbour before backtracking. What determines how deep is possible is that you must follow edges, and you don't visit any vertex twice. pseudocode: BFS uses queue BFS starting from vertex v: create a queue Q mark v as visited and put v into Q while Q is non-empty remove the head u of Q mark and enqueue all (unvisited) neighbours of u