Tree Traversal Pseudocode PQ

Duration: 7 min

This video lesson is available to enrolled students.

Return to /learn/COCUBES-PREPARATION/data-structures/tree/traversals-construction/asset-tree-traversal-pseudocode-pq after enrolling

Inside: a video lesson and guided study material.

Module outline

  1. Quantitative Aptitude: Number System, Divisibility Rules, HCF LCM, Percentage, Ratio and Proportion (Ratios), Average, Profit and Loss, Simple Interest and Compound Interest, Mixture and Alligation, Partnership, Age Problems, Time and Work, Pipe and Cistern, Speed Time and Distance, Algebra, Arithmetic, Data Interpretation, Sequence and Series (Series), Logarithm, Powers and Exponents (Surds and Indices), Permutation and Combination, Probability, Speed Mathematics and Basic Mathematics, Trigonometry
  2. Logical Reasoning: Coding Decoding, Blood Relations, Directions (Direction Test), Ranking, Order and Sequence, Seating Arrangements, Puzzle Solving (Puzzles), Data Arrangement, Syllogisms, Inequality, Data Sufficiency, Deductive and Inductive Reasoning (Logical Deduction and Induction) (Prepositional Reasoning), Series (Number and Letter Series) (Numerical Relations and Reasoning), Venn Diagram, Logical Sequence Of Words, Calendar, Clock, Cubes & Dices, Non Verbal Reasoning (Spatial Aptitude) (Spatial Reasoning) (Visual Reasoning)
  3. Verbal Ability: Noun, Pronoun, Adjectives, Verb, Adverb, Tenses, Subject Verb Agreement (Verb Noun Agreement), Articles, Preposition, Conjunction, Modals, Determiner, Vocabulary, Comprehension / Reading Comprehension / Unseen Passages (Critical Reasoning) (Paragraph Questions), Cloze Test (Cloze Passage), Sentence Correction (Error Correction), Sentence Completion (Fill in the blanks), Sentence Re-arrangements (Para Jumbles) (Narrative Sequencing), Active Passive Voice (Voice), Direct and Indirect Speech, Sentence Construction
  4. Data Structures (Domain Test): Introduction to DS, Array, Stack, Queue, Linked List, Tree, Graphs, Hashing
  5. Algorithms (Domain Test): Algorithm Analysis, Sorting Algorithms, Time Complexity Analysis, Greedy Algorithms
  6. OOPs (Domain Test): Object Oriented Programming (OOPS)
  7. DBMS (Domain Test): Basics of DBMS, ER Diagram, Relational Model & Functional Dependencies, Keys & Integrity Constraints, Normalization (1NF - BCNF), Decomposition Properties & 4NF, File Organization & Indexing, Relational Algebra, Relational Calculus, Transaction Management, Concurrency Control, Database Recovery, ORDBMS, Database Security & Authorization, Query Processing & Optimization, Enhanced Data Models, Data Warehousing & Mining, Big Data Systems, NoSQL
  8. SQL (Domain Test): SQL
  9. Operating Systems (Domain Test): Introduction to OS, Process Management, CPU Scheduling, Process Synchronization, Deadlock, Threads & Process Creation, Memory Management, Virtual Memory, Disc Scheduling, File Management, Windows OS, Linux OS, Security, Distributed Systems, Virtual Machines
  10. Computer Networks (Domain Test): Introduction to CN, Data Communication, DLL: Access Control, DLL: Flow Control, DLL: Error Control, DLL: Framing, Data Link Layer - Ethernet, Net Layer: IPv4 & Proto, Net Layer: IP Addressing, Net Layer:Routing Protocol, Transport Layer Services, TL: Congestion & UDP, Application Layer, Hardware basics, Network Security, Mobile Technology, Cloud Computing and IoT, Cyber and Info Security
  11. Coding: Coding Questions by Yash Sir, C Programming by Yash Sir, Programming in C++, Java, Python for Placements by Yash Sir
  12. Written English Test: English Writing Ability
  13. Psychometric Test: Behavioral Assessment (Behavioral Competency Profiling) (Psychometric Test)
AI summary & chapters

AI Summary

An AI-generated summary of this video lecture.

The video lecture analyzes a recursive C function named `what` designed to traverse a binary tree. The instructor begins by displaying the code, which contains three `printf` statements and two recursive calls to `what` for the left and right children. He draws a sample binary tree on the whiteboard with a root node of value 1, a left child 2 (which has a left child 4), and a right child 3. The instructor then performs a step-by-step trace of the function execution. He demonstrates that for every node visited, the data is printed three times: once before the left child recursion, once between the left and right child recursions, and once after the right child recursion. By following the call stack, he derives the final output sequence: 1 2 4 4 4 2 2 1 3 3 3 1. The lesson emphasizes understanding the order of operations in recursive tree traversals.

Chapters

  1. 0:00 – 2:00 00:00-02:00

    The video opens with the code snippet for the function `void what(struct Bnode *t)`. The instructor introduces the problem of determining the function's behavior. He draws a binary tree on the right side of the screen, starting with a root node labeled 1. He adds a left child labeled 2 and a right child labeled 3. He further extends the tree by adding a left child labeled 4 to node 2. The instructor begins tracing the function by writing `what(1)` on the board, indicating the initial call with the root node. He underlines the first line of code inside the `if (t)` block, which is `printf("%d', t->data);`, explaining that this will print the data of the current node.

  2. 2:00 – 5:00 02:00-05:00

    The instructor continues the trace by underlining the next line, `what(t->LC);`, which represents a recursive call to the left child. He writes `what(2)` below `what(1)` to show the next step in the recursion. Inside the call for node 2, he explains that the data 2 is printed first. Then, the function calls `what(t->LC)` again, moving to node 4. For node 4, the data 4 is printed. Since node 4 has no left child, `what(NULL)` is called and returns immediately. The function then prints 4 again (the second `printf`), calls `what(t->RC)` (which is NULL and returns), and finally prints 4 a third time. The instructor writes the sequence `4 4 4` on the board to represent the output for node 4. Back in node 2, after the left child returns, the second `printf` prints 2 again. The right child call is NULL, so it returns, and the final `printf` prints 2 a third time.

  3. 5:00 – 7:17 05:00-07:17

    The trace returns to the root node 1. After the left subtree (node 2) finishes, the second `printf` in the root function executes, printing 1 again. Next, the function calls `what(t->RC)`, moving to the right child, node 3. The instructor explains that node 3 follows the same pattern: print 3, call left (NULL), print 3, call right (NULL), print 3. This results in the sequence `3 3 3`. Finally, the function returns to the root node 1 one last time, where the final `printf` statement executes, printing 1 for the third time. The instructor writes the complete output sequence on the board: `1 2 4 4 4 2 2 1 3 3 3 1`. He concludes by summarizing that the function prints each node's data three times in a specific order: pre-order, in-order, and post-order relative to the recursive calls.

The lecture provides a clear, visual method for tracing recursive functions on binary trees. By breaking down the code into its constituent parts—printing data and making recursive calls—the instructor shows how the execution flow determines the output. The key learning point is that the position of `printf` statements relative to the recursive calls dictates the traversal order. In this specific case, the function performs a custom traversal where every node is visited and printed three times: before descending left, between left and right descents, and after descending right. This reinforces the concept that recursive functions execute code sequentially, and the 'return' from a recursive call resumes execution at the line immediately following the call.

Loading lesson…