Friday, 26 April 2013

The power of find command in linux

This is power full command in linux , which can be used for multiple purpose find some

1. find the files which modified  less than one day or exactly one day or more than one day


command: find . -mtime 1  ---> to find exactly one day

command: find . -mtime +1  ---> to find more than one day

command: find . -mtime -1  ---> to find less than one day


2. find the files which have only read permissions

command : find . -mperm 444

How to find top 5 process which are using more memory in linux

One of my friend asked this question in a company

use below command to find top n process which are using more process



ps -eo pmem,pcpu,vsize,pid,cmd | sort -k 1 -nr | head -5


here e --- means every process i.e all process
       o --- optional format
       k --- memory in killo bytes
       n --- sorting on number
       r --- revert the sort i.e descending order

How you update two columns in a table

How you update two columns in  a table ? write a query to update two columns in a table ?

It is simple if we want to update a single  column in a table we can use the below query

UPDATE TABLE "table-name" SET "column-name" = [new value] WHERE {condition}

e.g:
UPDATE TABLE employee SET ename="madhava" WHERE eid='1';

but the query to update multiple columns is as below

UPDATE TABLE "table-name" SET ("column1" , "column2") = ([new value1],[new value2])
WHERE ={condition }.

whcih data structure you use for mobile contact list

which data structure will be used for storing mobile contact list and If enter "ma" it should show all contacts in sorted list starting with ma letters.


Many people give answers we can use Hashtable or Array list but those are suitable but that is wrong answers , try with Binary search tree.

A hash table can insert and retrieve elements in O(1) .
A BST can insert and retrieve elements in O(log(n)), which is quite a bit slower than the hash table which can do it in O(1).


Try using Hash table :

When designing a cell phone, we need to think much about memory. A hash table is an unordered data structure –  which means that it does not keep its elements in any particular order. So, if you use a hash table for a cell phone address book, then you would need additional memory to sort the values when user enters input  So, by using a hash table you have to set aside memory to sort elements . i.e it requires more memory.

Try with BST(Binary Search tree)

Because a binary search tree is already sorted, there will be no need to waste memory or processing time sorting records in a cell phone. As  mentioned earlier, making a lookup or an insert on a binary tree is slower than doing it with a hash table, but a cell phone address book will almost never have more than 5,000 entries. With such a small number of entries, a binary search tree’s O(log(n)) will definitely be fast enough. So, given all that information, a binary search tree is the data structure that you should use in this scenario, since it is a better choice than a hash table or Array list