Data Structures & AlgorithmsHardProduct-company placement
A 3-ary max-heap is stored in a 0-indexed array (children of i at 3i + 1 … 3i + 3): [51, 43, 34, 20, 27, 18, 3, 8, 17, 10]. After inserting 59 (append, then sift up), what is the array?
- A. [59, 51, 34, 20, 43, 18, 3, 8, 17, 10, 27]
- B. [51, 43, 34, 20, 27, 18, 3, 8, 17, 10, 59]
- C. [59, 43, 51, 20, 27, 18, 3, 8, 17, 10, 34]
- D. [59, 43, 34, 51, 27, 18, 3, 8, 17, 10, 20]
Correct answer: D. [59, 43, 34, 51, 27, 18, 3, 8, 17, 10, 20]
In a 3-ary heap the parent of i is ⌊(i − 1)/3⌋; 59 starts at index 10 and swaps up while it beats its parent. Using the binary parent formula ⌊(i − 1)/2⌋ is the trap.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- What is the minimum number of edges m such that EVERY simple undirected graph with 9 vertices and m edges is guaranteed to be connected?
- In the grid 01210 / 11111 / 11121 / 01111 (rows top to bottom; 2 = rotten, 1 = fresh, 0 = empty), every minute each rotten orange rots its…
- A binary tree with distinct labels has INORDER E D I C A G H B F and LEVEL-ORDER I D H E G B C F A. What is its postorder traversal?
- The boolean expression F & T | T & T (T = true, F = false, & = AND, | = OR, ^ = XOR) can be fully parenthesised in 5 ways. In how many of…
- What is the maximum flow from S to T in the network with directed capacities A→C (5), B→A (10), B→C (13), B→T (9), C→T (12), S→A (14), S→B…
- The boolean expression F & F & T ^ T (T = true, F = false, & = AND, | = OR, ^ = XOR) can be fully parenthesised in 5 ways. In how many of…