Java autoboxing and equals(). Consider two ๐๐๐๐๐๐ values ๐ and ๐ and their corresponding <tt>Double</tt> values ๐ก and ๐ข .
- Find values such that
(๐==๐) is๐๐๐๐ but๐ก.๐๐๐๐๐๐(๐ข) is๐๐๐๐๐ . - Find values such that
(๐==๐) is๐๐๐๐๐ but๐ก.๐๐๐๐๐๐(๐ข) is๐๐๐๐ .
Hint: IEEE floating point arithmetic has some peculiar rules for ๐ถ.๐ถ , −๐ถ.๐ถ , and ๐ฝ๐๐ฝ . Java requires that ๐๐๐๐๐๐() implements an equivalence relation.
0.0 == -0.0 Double.valueOf(0.0).equals(Double.valueOf(-0.0))
Double.NaN == Double.NaN Double.valueOf(Double.NaN).equals(Double.valueOf(Double.NaN))
Check if a binary tree is a BST. Given a binary tree where each ๐ฝ๐๐๐ contains a key, determine whether it is a binary search tree. Use extra space proportional to the height of the tree.
Hint: design a recursive function ๐๐๐ฑ๐๐(๐ฝ๐๐๐๐ก,๐บ๐๐ข๐๐๐,๐บ๐๐ข๐๐๐ก) that determines whether ๐ก is the root of a binary search tree with all keys between ๐๐๐ and ๐๐๐ก .
if (Nodex == null) return true;
if ( Nodex.value < Keymin || Nodex.value > KeyMax) return false;
return isBST(Nodex.left, Keymin, Nodex.value) && isBST(Nodex.right, Nodex.value , Keymax)
Inorder traversal with constant extra space. Design an algorithm to perform an inorder traversal of a binary search tree using only a constant amount of extra space.
Hint: you may modify the BST during the traversal provided you restore it upon completion.
Web tracking. Suppose that you are tracking n web sites and m users and you want to support the following API:
- User visits a website.
- How many times has a given user visited a given site?
What data structure or data structures would you use?
Hint: maintain a symbol table of symbol tables.
ๆฒกๆ่ฏ่ฎบ:
ๅ่กจ่ฏ่ฎบ