Embercode
✕
TriesQuick quiz

Palindrome pairs and IP prefixes

8 questions. Covers IP longest prefix match with a binary trie.

Questions 1 to 5 of 8

  1. 1. What does this program print? ``python def parse_address(text): value = 0 for part in text.split("."): value = (value << 8) | int(part) return value print(parse_address("192.168.1.20")) ``
  2. 2. The word list is bat, tab, cat, at indexes 0, 1 and 2. Which list is the correct answer for palindrome pairs?
  3. 3. Put these steps in the order that add_route adds a route such as 10.1.0.0/16.

    Use the arrows to put the steps in order.

    1. 1.From the root, for each bit up to the prefix length, create the child for that bit if it is missing and move down
    2. 2.Store the next hop at the node reached after the last prefix bit
    3. 3.Turn the address part into one 32-bit integer with parse_address
    4. 4.Split the text at the slash into the address part and the prefix length
  4. 4. What does this program print? ``python addr = (192 << 24) | (168 << 16) | (1 << 8) | 20 bits = "" for depth in range(4): bits += str((addr >> (31 - depth)) & 1) print(bits) ``
  5. 5. The table has 0.0.0.0/0 with gw-A, 10.0.0.0/8 with gw-B, 10.1.0.0/16 with gw-C and 10.1.2.0/24 with gw-D. Which next hop does lookup return for 10.1.9.9?

4 question(s) left on this page.