Skip to content

Latest commit

 

History

History
38 lines (25 loc) · 618 Bytes

Ex_1_4_11.md

File metadata and controls

38 lines (25 loc) · 618 Bytes
title date draft tags categories
Algorithm4 Java Solution 1.4.11
2019-08-06 15:54:00 +0800
false
JAVA
TECH
archives

1.4.11

Problem:

Add an instance method howMany() to StaticSETofInts (page 99) that finds the number of occurrences of a given key in time proportional to log N in the worst case.

Solution:

find the minimum index key occurs in the array, then find the maximum index.

if key is in the array
    the number of occurrences = max_index - min_index + 1
else
    the number of occurrences = 0

code:

Ex_1_4_11.java

Reference: