Tree Traversal Pseudocode PQ
Duration: 7 min
This video lesson is available to enrolled students.
Inside: a video lesson and guided study material.
Module outline
- About Course: About the Course
- Paper-2 | Programming & Data Structures: C Fundamentals, Control Flow, Functions, Arrays & Pointers, Storage Classes, Structures & Enums, DMA, Macros, Scoping & File Handling, Introduction to DS, Array, Stack, Queue, Linked List, Tree, Graphs, Hashing
- Paper-2 | Databases / DBMS & SQL: Basics of DBMS, ER Diagram, Relational Model & Functional Dependencies, Keys & Integrity Constraints, Normalization (1NF - BCNF), Decomposition Properties & 4NF, File Organization & Indexing, Relational Algebra, SQL, Relational Calculus, Transaction Management, Concurrency Control
- Paper-2 | Algorithms: Algorithm Analysis, Time Complexity Analysis, Sorting Algorithms, Greedy Algorithms, Dynamic Programming, Minimum Spanning Trees, Shortest Path Algos
- Paper-2 | Computer Networks & Security: 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 Access Technologies, Network Security
- Paper-2 | Digital Logic: Digital Systems & Boolean Basics, Logic Gates & Hardware, Boolean Expression, Boolean Minimization, Combinational Circuit, Sequential Circuits, Number System, Number Representation, Floating Point Rep
- Paper-2 | Operating System: Introduction to OS, Process Management, CPU Scheduling, Process Synchronization, Threads & Process Creation, Deadlock, Memory Management, Virtual Memory, Disc Scheduling, File Management
- Paper-2 | Theory of Computation: Introduction to TOC, Deterministic FA (DFA), Non-Deterministic FA, Regular Expressions, Grammar, Regular Language Properties, Moore & Mealy Machines, Pushdown Automata & CFG, Turing Machines
- Paper-2 | Computer Organization & Architecture: Basics of COA, Cache Memory Organization, Input Output Organisation, Pipelining, Instr Formats & Modes, Control Unit Design, Programming the Basic Computer
- Paper-2 | Compiler Design: Intro to Compilers, Lexical Analysis, Grammar & CFG, Syntax Analysis: Top-Down, Syntax Analysis: Bottom-Up, Semantic Analysis & SDT, Intermediate Code Gen, Code Optimization, Run Time Environment
- Paper-1 | General Awareness: Polity, Physics, Biology, Chemistry, Static General Knowledge, GK- Current Affairs, History, Geography, Indian Economy, Environment
- Paper-1 | Logical Reasoning: Series (Number and Letter Series) (Numerical Relations and Reasoning), Coding Decoding, Non Verbal Reasoning (Spatial Aptitude) (Spatial Reasoning) (Visual Reasoning), Data Interpretation, Blood Relations, Syllogisms, Deductive and Inductive Reasoning (Logical Deduction and Induction) (Prepositional Reasoning), Selection Decision Table (Decision Making), Clock, Calendar, Cubes & Dices, Directions (Direction Test), Analogy, Seating Arrangements, Analytical Reasoning (Counting Figures Reasoning)
- Paper-1 | Quantitative Aptitude: Ratio and Proportion (Ratios), Mixture and Alligation, Permutation and Combination, Number System, HCF LCM, Speed Time and Distance, Average, Age Problems, Percentage, Profit and Loss, Time and Work, Pipe and Cistern, Simple Interest and Compound Interest, Powers and Exponents (Surds and Indices), Mensuration and Geometry, Probability, Statistics, Arithmetic, Algebra
- Paper-1 | English: Vocabulary, Comprehension / Reading Comprehension / Unseen Passages (Critical Reasoning) (Paragraph Questions), Sentence Re-arrangements (Para Jumbles) (Narrative Sequencing), Sentence Correction (Error Correction), Sentence Completion (Fill in the blanks), Sentence Construction, Cloze Test (Cloze Passage)
- Coal India Previous Year Paper:
- Engineering Mathematics: Set Theory, Relations, Functions, Graph Theory, Group Theory, Propositional and Predicate Logic, Linear Algebra, Calculus
- Coal India Mock 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
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: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.
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.