I was asked the following Question: How would you store the data given below(which data structure would u pick):
A-1-2-3-4-5-6
|
B-7-8-9-10-11
|
C-12-14-15-16-17
My ans: Since this looks like a bunch of lists with its head nodes linked together. Use two node types one id the regular node type with the following definition:
Struct node1
{
int val;
struct node*next;
};
// to store the numerical part of the data
struct node2
{
int val;
struct node *down;
struct node* next;
};
//this is the heads of each list.. for the alphabet part of the question.
The Interviewer's reaction: Is this the best data structure u can think of . How abt in terms of traversal and memory needed for each node?
My answer to that: We can traverse better if we create some sort of hash table.
My question to you comrades: Can we do a better job ?? Is there a better way to store this type of data?
we assume that the data is all numbers (even the ones at each head node) and non serial with repetitions possible . What would be the right answer ? Looking for answers in C/C++