Q:-How will you search for a word in a very large database ?
1. First the group of related files are stored in different bucket using hashing . Then in particular bucket we sort the files using some sorting method if the files are not in alphabetical order .
2. Now comes the searching part . Using hash function we can reach to bucket in O(1) time.
3. As we have already sorted the files in particular bucket so we will apply binary search to reach to exact file. Binary Search will take O(logn) time .
Then in the file we can apply different searching algorithm to reach to the word .
Q:- Explain the database to your 5 year old child in three sentence.
1. It is like shelf in which you put your toys with number of drawer for different kind of toys. for eg for green toys you put them in drawer no 1 and to the red toys you put them in drawer no .2.
2. Every drawer has a name slip on it like green ,yellow etc so that you can easily search different color toy.
3.Your self has a lock and you are having key of that lock such that without your permission no can open your shelf and see your toys .
Q:-Design a database schema for college elections and how will you make sure at database end that one user can vote for one person standing for one post only.
There will be four table as follows :->
1. Candidate(name ,c_id ,phone_no., Address )
2. Voter(name , v_id, phone_no,address,no_of_votes(auto_increment and check constraint <=1)
3. Voting(v_id,c_id)
4.Post(id,name,c_id(unique))
Here comes the important question where did we make sure that one user can vote for one person standing for one post only.
If you will see carefully in the database schema you will notice that i have made no_of_votes attribute in table Voter auto_incremented i.e when a voter will vote for a particular candidate .His
no_of_votes will be incremented automatically and next time if comes he comes to vote again then check constraint will show that it has already been incremented hence cant vote anymore.
Now for a candidate can apply for one post only :- we have made c_id in the post table unique hence he can't apply for more than one post.
1. First the group of related files are stored in different bucket using hashing . Then in particular bucket we sort the files using some sorting method if the files are not in alphabetical order .
2. Now comes the searching part . Using hash function we can reach to bucket in O(1) time.
3. As we have already sorted the files in particular bucket so we will apply binary search to reach to exact file. Binary Search will take O(logn) time .
Then in the file we can apply different searching algorithm to reach to the word .
Q:- Explain the database to your 5 year old child in three sentence.
1. It is like shelf in which you put your toys with number of drawer for different kind of toys. for eg for green toys you put them in drawer no 1 and to the red toys you put them in drawer no .2.
2. Every drawer has a name slip on it like green ,yellow etc so that you can easily search different color toy.
3.Your self has a lock and you are having key of that lock such that without your permission no can open your shelf and see your toys .
Q:-Design a database schema for college elections and how will you make sure at database end that one user can vote for one person standing for one post only.
There will be four table as follows :->
1. Candidate(name ,c_id ,phone_no., Address )
2. Voter(name , v_id, phone_no,address,no_of_votes(auto_increment and check constraint <=1)
3. Voting(v_id,c_id)
4.Post(id,name,c_id(unique))
Here comes the important question where did we make sure that one user can vote for one person standing for one post only.
If you will see carefully in the database schema you will notice that i have made no_of_votes attribute in table Voter auto_incremented i.e when a voter will vote for a particular candidate .His
no_of_votes will be incremented automatically and next time if comes he comes to vote again then check constraint will show that it has already been incremented hence cant vote anymore.
Now for a candidate can apply for one post only :- we have made c_id in the post table unique hence he can't apply for more than one post.
No comments:
Post a Comment