Oracle Interview Question
Software Engineer / DevelopersNeed more info on the relationships between the fields - 1:n, n:1, n:n, so on.
For example, can an address have multiple phone numbers? Can a phone number belong to multiple addresses? Etc.
With that info, I believe, you'd need 3 lookup tables - one for each of the searchable fields - where each entry contains the hash key of the related fields values.
Two hash tables with key as phone number as it will be unique for each person. In one table <phone number, name> and other table <phone number, address>
from what i think is that each node in the trie will have three fields phno, address and name. Phone number are supposed to be unique so we can search the ph no to get to the node and then have the address and the name.
So, in short trie data structure on ph no.
There might be 100's of millions of numbers . We need a space and time efficient solution .
Soln
a) Hash Map :::- Only Mobile number is unique, so it can work as key. Name and Address might be delimiter separated or can be part of a user defined object
Pros :- O(1) search
:- Search based on number will be used 99% of the time as it will return unique names/addresses
b) Address and Name can be searched in O(n) where n is total number of mobile numbers
eg
public class Address
{
String first Name;
String Middle Name;
String Address;
String City ……
}
HashMap< String MobileNumber,Address> = new HashMap…..
Benefits, Search on even last name can be done…
{{
#!/usr/bin/env python
# Jorge Niedbalski <jnr@pyrosome.org>
class Query:
(c,d) = ([],[])
def __init__(self):
pass
def a(self, d):
self.d.append(d)
return self
def f(self, k, v):
self.c.append((k, v))
return self
def g(self):
for entry in self.d:
cc = []
for k,v in self.c:
try:
cc.append(entry[k] == v)
except KeyError:
pass
if any(cc):
yield entry
def f():
persons = Query() \
.a({'name': 'tester', 'address': 'test avenue 99'})\
.a({'name': 'tester1', 'address': 'test avenue 100'})\
.a({'name': 'tester2', 'address': 'test avenue 101'})\
.f('name', 'tester').g()
for person in persons:
print person
f()
}}
Trie.
- anshulzunke September 12, 2011i can make key of in the tree which is not a single key but rather 3 keys. 1 for name another for address and one more for surname
Lets say my number is 8888888 then this will be saved in Anshul as well as Zunke and also with Address. All the three will have an identifier with which attribute the number has been saved in the node i.e whether the key is as per name surname or address