GradePack

    • Home
    • Blog
Skip to content
bg
bg
bg
bg

Author Archives: Anonymous

A student wrote the following inorder method (buggy). Identi…

A student wrote the following inorder method (buggy). Identify the bug:public static void inorder(BinaryTreeNode node) { if (node.getLeft() != null) inorder(node.getLeft()); System.out.print(node.element + ” “); if (node.getRight() == null) inorder(node.getRight()); } What is the bug?

Read Details

When deleting a node v from a Binary Search Tree that has tw…

When deleting a node v from a Binary Search Tree that has two internal children, what is the standard procedure to maintain the BST property? 

Read Details

The LinkedTree.iterator() implementation builds a snapshot v…

The LinkedTree.iterator() implementation builds a snapshot via preorderSubtree(root, snapshot). Given the implementation below, what order will the iterator return elements?private void preorderSubtree(Node node, List snapshot) { if (node == null) return; snapshot.add(node.getElement()); for (Node child : node.children) preorderSubtree(child, snapshot); }

Read Details

In LinkedTree.addRoot(e) the code throws IllegalStateExcepti…

In LinkedTree.addRoot(e) the code throws IllegalStateException if root != null. Why?

Read Details

Which of the following data structures guarantees O(log n) w…

Which of the following data structures guarantees O(log n) worst-case time complexity for search, insertion, and deletion? (Select all that apply)

Read Details

If a sorted array contains approximately 1,000,000 elements…

If a sorted array contains approximately 1,000,000 elements (roughly 220), what is the maximum number of comparisons a binary search will make in a worst-case scenario?

Read Details

Which statement best describes the root of a tree?

Which statement best describes the root of a tree?

Read Details

Given the BinaryTreeTraversal building expression tree for (…

Given the BinaryTreeTraversal building expression tree for (2 * (a – 1)) + (3 * b), what does preorder(tree.root) print (space-separated)?// snippet from BinaryTreeTraversal.java Node plus = tree.addRoot(“+”); Node mult1 = tree.addLeft(plus, “*”); Node mult2 = tree.addRight(plus, “*”); tree.addLeft(mult1, “2”); Node minus = tree.addRight(mult1, “-“); tree.addLeft(minus, “a”); tree.addRight(minus, “1”); tree.addLeft(mult2, “3”); tree.addRight(mult2, “b”); // call: tree.preorder(tree.root);

Read Details

What is the single most important prerequisite for performin…

What is the single most important prerequisite for performing a binary search on an array?

Read Details

What is the worst-case time complexity of a sequential searc…

What is the worst-case time complexity of a sequential search on an unsorted array of N elements?

Read Details

Posts pagination

Newer posts 1 … 8 9 10 11 12 … 96,572 Older posts

GradePack

  • Privacy Policy
  • Terms of Service
Top