<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4138177214764955465</id><updated>2011-11-27T17:07:51.964-08:00</updated><category term='php testing'/><category term='php codes'/><title type='text'>interview questions and answers</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default?start-index=101&amp;max-results=100'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>208</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-4731294539794574343</id><published>2007-10-27T12:14:00.001-07:00</published><updated>2007-10-27T12:14:17.626-07:00</updated><title type='text'>Computer System Structures Interview Questions Part5</title><content type='html'>59) Question: From the given data&lt;br /&gt;              Bytes/Sector = 500&lt;br /&gt;              Sectors/Track = 50&lt;br /&gt;              Tracks/Platter = 150&lt;br /&gt;              Platters/ Hard Disk = 10&lt;br /&gt;              Data Transfer rate = 10 millisecs per byte&lt;br /&gt;Total number of millisecs taken to transfer all the bytes in the hard disk?&lt;br /&gt;                     1) 500 x 50 x 10 x 10&lt;br /&gt;                     2) 500 x 50 x 150 x 10 &lt;br /&gt;                     3) 500 x 50 x 150 x 10 x10 &lt;br /&gt;                     4) 500 x 150 x 10 x10&lt;br /&gt;                 Answer: 3&lt;br /&gt;60) From the given data&lt;br /&gt;              Bytes/Sector = 500&lt;br /&gt;              Sectors/Track = 50&lt;br /&gt;              Tracks/Platter = 150&lt;br /&gt;              Platters/ Hard Disk = 10&lt;br /&gt;              Data Transfer rate = 10 millisecs per byte&lt;br /&gt;Total number of millisecs taken to transfer the bytes from one single platter?&lt;br /&gt;                     1) 500 x 50 x 150 x 10&lt;br /&gt;                     2) 500 x 50 x 10&lt;br /&gt;                     3) 500 x 150 x 50 x 10&lt;br /&gt;                    4) 500 x 150 x 10 x10&lt;br /&gt;                Answer: 1&lt;br /&gt;61) From the given data&lt;br /&gt;              Bytes/Sector = 500&lt;br /&gt;              Sectors/Track = 50&lt;br /&gt;              Tracks/Platter = 150&lt;br /&gt;              Platters/ Hard Disk = 10&lt;br /&gt;              Data Transfer rate = 10 millisecs per byte&lt;br /&gt; Total number of milliseconds taken to transfer all the bytes from a cylinder cylinder? &lt;br /&gt;1) 500 x 50 x 10 x 10&lt;br /&gt;2) 500 x 150 x 50&lt;br /&gt;3) 500 x 150 x 10 x10&lt;br /&gt;4) 50 x 150 x 10 x10&lt;br /&gt;Answer: 1&lt;br /&gt;62) In a Hard disk, &lt;br /&gt;Bytes per sector = 512&lt;br /&gt;Sectors/track = 63&lt;br /&gt;Number of Magnetic disks = 5&lt;br /&gt;Tracks / platter = 50&lt;br /&gt;Total number of bytes in a cylinder is ________&lt;br /&gt;13) 512X 63X 5&lt;br /&gt;14) 512X 50X 5&lt;br /&gt;15) 512X 63 X 50&lt;br /&gt;16) 512 X 5&lt;br /&gt;Answer: 1&lt;br /&gt;63) In a Hard disk, &lt;br /&gt;Bytes per sector = 512&lt;br /&gt;Sectors/track = 63&lt;br /&gt;Number of Magnetic disks = 5&lt;br /&gt;Tracks / platter = 50&lt;br /&gt;The total number of bytes/platter is _____&lt;br /&gt;17) 512X 63X 5&lt;br /&gt;18) 512X 50X 5&lt;br /&gt;19) 512X 63 X 50&lt;br /&gt;20) 512 X 5&lt;br /&gt;Answer: 3&lt;br /&gt;64) In a Hard disk, &lt;br /&gt;Bytes per sector = 512&lt;br /&gt;Sectors/track = 63&lt;br /&gt;Number of Magnetic disks = 5&lt;br /&gt;Tracks / platter = 50&lt;br /&gt;The total number of cylinders in the hard disk is_______.&lt;br /&gt;1) 63&lt;br /&gt;2) 50&lt;br /&gt;3) 512&lt;br /&gt;4) 63 X 5&lt;br /&gt;Answer: 2&lt;br /&gt;65)The size of single unit of allocation on disk is called ____.&lt;br /&gt;5) Sector size&lt;br /&gt;6) Page size&lt;br /&gt;7) Segment size&lt;br /&gt;8) File size&lt;br /&gt;Answer: 1&lt;br /&gt;66) MS-DOS supports multiprogramming fully. True / False?&lt;br /&gt;Answer: False&lt;br /&gt;67) Which of the following is crucial time while accessing data on the disk?  &lt;br /&gt;&lt;br /&gt;1)  Seek time  &lt;br /&gt;2)  Rotational time   &lt;br /&gt;3)  Transmission time   &lt;br /&gt;4)  Waiting time   &lt;br /&gt;&lt;br /&gt;  Ans: 1   &lt;br /&gt;&lt;br /&gt;68)  A __________ is software that manages the time of a microprocessor to ensure that all time critical events are processed as efficiently as possible. This software allows the system activities to be divided into multiple independent elements called tasks.  &lt;br /&gt;&lt;br /&gt;1)  Kernel  &lt;br /&gt;2)  Shell   &lt;br /&gt;3)  Processor   &lt;br /&gt;4)  Device Driver   &lt;br /&gt; &lt;br /&gt; Ans: - 1&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-4731294539794574343?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/4731294539794574343/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=4731294539794574343' title='38 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4731294539794574343'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4731294539794574343'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/computer-system-structures-interview_8389.html' title='Computer System Structures Interview Questions Part5'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>38</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-6247707678832206665</id><published>2007-10-27T12:13:00.001-07:00</published><updated>2007-10-27T12:13:41.738-07:00</updated><title type='text'>Computer System Structures Interview Questions Part4</title><content type='html'>47) ________ is/are  only storage media that the CPU can access directly.&lt;br /&gt;1) Main memory&lt;br /&gt;2) Storage memory&lt;br /&gt;3) both&lt;br /&gt;4) None&lt;br /&gt;Answer: 1&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;48) _________ is the extension of main memory that provides large non volatile storage capacity.&lt;br /&gt;1) Secondary storage&lt;br /&gt;2) RAM&lt;br /&gt;3) Cache&lt;br /&gt;4) None&lt;br /&gt;Answer: 1&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;49) Which of the following is a volatile storage medium?&lt;br /&gt;1) Hard disc&lt;br /&gt;2) RAM&lt;br /&gt;3) Magnetic tapes&lt;br /&gt;4) Compact disc&lt;br /&gt;Answer: 2 &lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;50) Which of the following is a non- volatile storage medium?&lt;br /&gt;1) Cache&lt;br /&gt;2) RAM&lt;br /&gt;3) CPU Registers&lt;br /&gt;4) Hard disc&lt;br /&gt;Answer: 4&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;51) DMA stands for______&lt;br /&gt;1) Direct Memory Access&lt;br /&gt;2) Directory Memory Access&lt;br /&gt;3) Differential  Memory Access&lt;br /&gt;4) All the above&lt;br /&gt;Answer: 1&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;52) A _____ is a memory that stores data while they are transferred between two devices or between a device and an application.&lt;br /&gt;1) Buffer&lt;br /&gt;2) Cache&lt;br /&gt;3)   Hard disc&lt;br /&gt;4) Compact disc&lt;br /&gt;Answer: 1&lt;br /&gt;Level:1&lt;br /&gt; &lt;br /&gt;               53) Question: From the given data&lt;br /&gt;              Bytes/Sector = 500&lt;br /&gt;              Sectors/Track = 50&lt;br /&gt;              Tracks/Platter = 150&lt;br /&gt;              Platters/ Hard Disk = 10&lt;br /&gt;              Total number of bytes in the hard disk?&lt;br /&gt;                     1) 500 x 50 x 10&lt;br /&gt;                     2) 500 x 50 x 150&lt;br /&gt;                     3) 500 x 50 x 150 x 10&lt;br /&gt;                     4) 500 x 150 x 10&lt;br /&gt;                 Answer: 3&lt;br /&gt;           54) Question: From the given data&lt;br /&gt;              Bytes/Sector = 500&lt;br /&gt;              Sectors/Track = 50&lt;br /&gt;              Tracks/Platter = 150&lt;br /&gt;              Platters/ Hard Disk = 10&lt;br /&gt;&lt;br /&gt;Total number bytes in a platter?&lt;br /&gt;                     1) 500 x 50 x 150 &lt;br /&gt;                     2) 500 x 50 x 10&lt;br /&gt;                     3) 500 x 150 x 50 x 10&lt;br /&gt;                    4) 500 x 150 x 10&lt;br /&gt;                Answer: 1&lt;br /&gt;55) Question: From the given data&lt;br /&gt;              Bytes/Sector = 500&lt;br /&gt;              Sectors/Track = 50&lt;br /&gt;              Tracks/Platter = 150&lt;br /&gt;              Platters/ Hard Disk = 10&lt;br /&gt;Total number of bytes per cylinder? &lt;br /&gt;1) 500 x 50 x 10&lt;br /&gt;2) 500 x 150 x 50&lt;br /&gt;3) 500 x 150 x 10&lt;br /&gt;4) 50 x 150 x 10&lt;br /&gt;Answer: 1&lt;br /&gt;56) Question: From the given data&lt;br /&gt;              Bytes/Sector = 750&lt;br /&gt;              Sectors/Track = 100&lt;br /&gt;              Tracks/Platter = 150&lt;br /&gt;              Platters/ Hard Disk = 50&lt;br /&gt;          Total number of bytes in the hard disk?&lt;br /&gt;                     1) 750 x 100 x 50&lt;br /&gt;                     2) 750 x 100 x 150&lt;br /&gt;                     3) 750 x 100 x 150 x 50&lt;br /&gt;                     4) 750 x 150 x 50&lt;br /&gt;                 Answer: 3&lt;br /&gt;57) From the given data&lt;br /&gt;              Bytes/Sector = 750&lt;br /&gt;              Sectors/Track = 100&lt;br /&gt;              Tracks/Platter = 150&lt;br /&gt;              Platters/ Hard Disk = 50&lt;br /&gt; Total number bytes in a platter?&lt;br /&gt;                     1) 750 x 100 x 150 &lt;br /&gt;                     2) 750 x 100 x 50&lt;br /&gt;                     3) 750 x 150 x 100 x 50 &lt;br /&gt;                    4) 750 x 150 x 50&lt;br /&gt;                Answer: 1&lt;br /&gt;58) From the given data&lt;br /&gt;              Bytes/Sector = 750&lt;br /&gt;              Sectors/Track = 100&lt;br /&gt;              Tracks/Platter = 150&lt;br /&gt;              Platters/ Hard Disk = 50&lt;br /&gt;Total number of bytes per cylinder? &lt;br /&gt;1) 750 x 100 x 50&lt;br /&gt;2) 750 x 150 x 100&lt;br /&gt;3) 750 x 150 x 50&lt;br /&gt;4) 100 x 150 x 50&lt;br /&gt;Answer: 1&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-6247707678832206665?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/6247707678832206665/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=6247707678832206665' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/6247707678832206665'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/6247707678832206665'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/computer-system-structures-interview_6417.html' title='Computer System Structures Interview Questions Part4'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-7617097890595850435</id><published>2007-10-27T12:12:00.001-07:00</published><updated>2007-10-27T12:12:48.911-07:00</updated><title type='text'>Computer System Structures Interview Questions Part3</title><content type='html'>24) Recursion or large arrays of local variables avoided by kernel programmers because The kernel stack is usually a limited resource. A stack overflow crashes the entire machine. &lt;br /&gt;T/F&lt;br /&gt; Answer: True&lt;br /&gt;Exp: by def&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;25) What is the purpose of system calls?&lt;br /&gt;a) system calls allow user-level processes to request services of the operating system.&lt;br /&gt;b) system calls acts as traps.&lt;br /&gt;c) both a and b&lt;br /&gt;d) none of the above&lt;br /&gt;answer : a&lt;br /&gt;Exp: by def&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;26) What are the major activities of an operating system in regard to process management?&lt;br /&gt;a. The creation and deletion of both user and system processes&lt;br /&gt;b. The suspension and resumption of processes&lt;br /&gt;c. The provision of mechanisms for process synchronization&lt;br /&gt;d. The provision of mechanisms for process communication&lt;br /&gt;e. The provision of mechanisms for deadlock handling&lt;br /&gt;&lt;br /&gt;a) a,b,c&lt;br /&gt;b) a,b,d&lt;br /&gt;c) a,b,c,e&lt;br /&gt;d) a,b,c,d,e&lt;br /&gt;answer:d&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;27) What are the major activities of an operating system in regard to memory management?&lt;br /&gt;a. Keep track of which parts of memory are currently being used and by whom.&lt;br /&gt;b. Decide which processes are to be loaded into memory when memory space becomes available.&lt;br /&gt;c. Allocate and deallocate memory space as needed.&lt;br /&gt;d. Interrupt processes when executing&lt;br /&gt;&lt;br /&gt;1) a and b&lt;br /&gt;2) a,b and c&lt;br /&gt;3) a and c&lt;br /&gt;4) Only c&lt;br /&gt;&lt;br /&gt;Answer:2&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;28) The major activities of an operating system in regard to secondary-storage management?&lt;br /&gt;a)  Free-space management.&lt;br /&gt;b)  Storage allocation.&lt;br /&gt;c) Interrupt processes while executing&lt;br /&gt;d) Disk scheduling.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1) a and b&lt;br /&gt;2) a,b and c&lt;br /&gt;3) a,b and d&lt;br /&gt;4) Only c&lt;br /&gt;&lt;br /&gt;Answer:3&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;29) Which of the following are true regarding the command interpreter? &lt;br /&gt;a) the command interpreter reads commands from the user or from a file of commands and executes them&lt;br /&gt;b)  command interpreter is subject to changes&lt;br /&gt;c)   acts as an interface between primary and secondary memory&lt;br /&gt;&lt;br /&gt;1) a and b&lt;br /&gt;2) a,b and c&lt;br /&gt;3) a and c&lt;br /&gt;4) Only a&lt;br /&gt;&lt;br /&gt;. Answer:1&lt;br /&gt;It reads commands from the user or from a file of commands&lt;br /&gt;and executes them, usually by turning them into one or more system&lt;br /&gt;calls. It is usually not part of the kernel since the command interpreter&lt;br /&gt;is subject to changes.&lt;br /&gt;Level:2&lt;br /&gt;&lt;br /&gt;30) What system calls have to be executed by a command interpreter or shell in order to start a new process in unix?&lt;br /&gt;a)  fork &lt;br /&gt;b) ps&lt;br /&gt;c) fork followed by exec&lt;br /&gt;d) none of the above&lt;br /&gt;Answer:c &lt;br /&gt;process. The fork call clones the currently executing process, while the exec call overlays a new process based on a different executable over the calling process.&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;31) Which of the following are trueregarding  system programs and system calls?&lt;br /&gt;a) System programs can be thought of as bundles of useful&lt;br /&gt;system calls.&lt;br /&gt;b) system calls  provide basic functionality to users so that users do not need to write their own programs to solve common problems.&lt;br /&gt;c) system calls can be defined by the user&lt;br /&gt;&lt;br /&gt;1) a and b&lt;br /&gt;2) a,b and c&lt;br /&gt;3) a,b and d&lt;br /&gt;4) Only b&lt;br /&gt;&lt;br /&gt;Answer:1&lt;br /&gt;Level:2&lt;br /&gt;&lt;br /&gt;32) What is the main advantage of the layered approach to system design?&lt;br /&gt;a) the system is easier to debug and modify because changes affect only limited sections of the system rather than touching all sections of the operating system.&lt;br /&gt;b) Information is kept only where it is needed and is accessible only within a defined and restricted area, so any bugs affecting that data must be limited to a specific module or layer. c) microkernel approach helps increases the degree of multiprogramming.&lt;br /&gt;&lt;br /&gt;1) a,b,c&lt;br /&gt;2) a,b&lt;br /&gt;3) Only a&lt;br /&gt;4) None&lt;br /&gt;&lt;br /&gt;Answer: 2&lt;br /&gt;Level:2&lt;br /&gt;&lt;br /&gt;33) what are  the services provided by an operating system.&lt;br /&gt;a. Program execution. &lt;br /&gt;b. I/O handling &lt;br /&gt;c. File-system manipulation.&lt;br /&gt;d. commmunications &lt;br /&gt;e. error detection&lt;br /&gt;&lt;br /&gt;a) a,b,c,d&lt;br /&gt;b) b,c,d,e&lt;br /&gt;c) a,b,c,d,e&lt;br /&gt;d) b,c,e &lt;br /&gt;Answer:c&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;34) What are the main advantages of the microkernel approach to system design?&lt;br /&gt;&lt;br /&gt;a) adding a new service does not require modifying the kernel&lt;br /&gt;(b) it is more secure as more operations are done in user mode than in kernel mode&lt;br /&gt;(c) microkernel approach helps increases the degree of multiprogramming.&lt;br /&gt;d) a simpler kernel design and functionality typically results in a more reliable operating system.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1) a,b,d&lt;br /&gt;2) b,c,d&lt;br /&gt;3) a,b,c,d&lt;br /&gt;4) Only a&lt;br /&gt;&lt;br /&gt;Answer:1&lt;br /&gt;Level:2&lt;br /&gt;&lt;br /&gt;35) some systems store the operating system in firmware, and others on disk?&lt;br /&gt;for PDAs,cellular telephones etc a disk with a file system may be not be available for the device.hence they are stored in firmaware.&lt;br /&gt;T/F.&lt;br /&gt;Answer: True&lt;br /&gt;Level:2&lt;br /&gt;&lt;br /&gt;36) How could a system be designed to allow a choice of operating systems to boot from? What would the bootstrap program need to do?&lt;br /&gt;a) during boot-up, a special program (which we will call the boot manager) will determine which operating system to boot into. &lt;br /&gt;b)  the boot-strap loader will load the operating system selected at the start-up.&lt;br /&gt;c) only a&lt;br /&gt;d) both a and b.&lt;br /&gt;&lt;br /&gt;Answer:c&lt;br /&gt;&lt;br /&gt;Exp: Consider a system that would like to run both Windows&lt;br /&gt;XP and three different distributions of Linux (e.g., RedHat, Debian, and&lt;br /&gt;Mandrake). Each operating system will be stored on disk. During system&lt;br /&gt;boot-up, a special program (which we will call the boot manager) will&lt;br /&gt;determine which operating system to boot into. This means that rather&lt;br /&gt;initially booting to an operating system, the boot manager will first run&lt;br /&gt;during system startup. It is this boot manager that is responsible for&lt;br /&gt;determining which system to boot into. Typically boot managers must&lt;br /&gt;be stored at certain locations of the hard disk to be recognized during&lt;br /&gt;system startup. Boot managers often provide the user with a selection of&lt;br /&gt;systems to boot into; boot managers are also typically designed to boot&lt;br /&gt;into a default operating system if no choice is selected&lt;br /&gt;Level:2&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;37) The following are the secondary storage media.&lt;br /&gt;1) Magnetic tapes&lt;br /&gt;2) Magnetic disks&lt;br /&gt;3) Ram&lt;br /&gt;4) None&lt;br /&gt;&lt;br /&gt;Answer: 1 and 2&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;38) Which of the following are Non volatile storage devices&lt;br /&gt;a) Magnetic Tapes&lt;br /&gt;b) Main memory&lt;br /&gt;c) Optical disk&lt;br /&gt;d) Secondary Memory&lt;br /&gt;&lt;br /&gt;1) a and b&lt;br /&gt;2) a,b and c&lt;br /&gt;3) a,b and d&lt;br /&gt;4) Only c&lt;br /&gt;&lt;br /&gt;Answer: 3&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;39) Electronic disk, Main memory, Magnetic disk and Cache are volatile. True/False&lt;br /&gt;Answer: False&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;40) ______: a secondary storage device, which holds data in bulk and it, holds data in magnetic medium of the disk.&lt;br /&gt;1) Hard disc&lt;br /&gt;2) Compact disc&lt;br /&gt;3) RAM&lt;br /&gt;4) CPU Registers&lt;br /&gt;Answer: 1&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;41) A ________ is a secondary (optical) storage device.&lt;br /&gt;1) Hard disc&lt;br /&gt;2) Compact disc&lt;br /&gt;3) RAM &lt;br /&gt;4) CPU Register&lt;br /&gt;Answer: 2 &lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;   42) ________ is the type of memory access in main memory (RAM).&lt;br /&gt;1) Sequential access&lt;br /&gt;2) DMA&lt;br /&gt;3) Both&lt;br /&gt;4) None&lt;br /&gt;Answer: 2&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;43) Which of the following is a volatile storage medium?&lt;br /&gt;1) Hard disc&lt;br /&gt;2) Cache&lt;br /&gt;3) Magnetic tapes&lt;br /&gt;4) Compact disc&lt;br /&gt;Answer: 2 &lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;44) The _________ is the additional time waiting for the disc to rotate the desired sector to the disc head &lt;br /&gt;1) Rotational latency&lt;br /&gt;2) Bandwidth&lt;br /&gt;3) Seek time&lt;br /&gt;4) None&lt;br /&gt;Answer: 1&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;45) ________: keep in memory only those instructions and data that are needed at any given time.&lt;br /&gt;Needed when the process is larger than the amount of memory allocated to it.&lt;br /&gt;1) Overlays&lt;br /&gt;2) Studs&lt;br /&gt;3) Cache&lt;br /&gt;4) None&lt;br /&gt;Answer: 1&lt;br /&gt;Level:2&lt;br /&gt;&lt;br /&gt;46) For Virtual memory implementation the OS uses ________&lt;br /&gt;1) Compact disc&lt;br /&gt;2) Floppy drives&lt;br /&gt;3) Hard disc&lt;br /&gt;4) Cache&lt;br /&gt;Answer: 3&lt;br /&gt;Level:2&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-7617097890595850435?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/7617097890595850435/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=7617097890595850435' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7617097890595850435'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7617097890595850435'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/computer-system-structures-interview_9297.html' title='Computer System Structures Interview Questions Part3'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-1148162955117755914</id><published>2007-10-27T12:11:00.000-07:00</published><updated>2007-10-27T12:12:00.245-07:00</updated><title type='text'>Computer System Structures Interview Questions Part12</title><content type='html'>10) the memory hierarchy is &lt;br /&gt;a. Registers, cache, main memory, magnetic disk, CDROM, tape &lt;br /&gt;b. Cache, , main memo ry, magnetic disk, Registers, CDROM, tape&lt;br /&gt;c. Cache, Registers, main memory, magnetic disk, CDROM, tape&lt;br /&gt;                 4) Main memory, Registers, cache, magnetic disk, CDROM, tape&lt;br /&gt;                 Answer: 1&lt;br /&gt;Exp: internal architecture&lt;br /&gt;Level:2&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;11) The CPU uses poling to watch the control bit, constantly looping to see whether the device is ready. This method of operations is called___________&lt;br /&gt;1) Progrmmed I/O&lt;br /&gt;2) I/O interrupt &lt;br /&gt;3) I/O operation request&lt;br /&gt;4) None&lt;br /&gt;Answer: 1 &lt;br /&gt;Exp: by the definition of the Programmed I/O&lt;br /&gt;Level:2&lt;br /&gt;&lt;br /&gt;12) The memory buffer used to accommodate a speed differential is called a _____&lt;br /&gt;1) Main memory&lt;br /&gt;2) Cache memery&lt;br /&gt;3) CPU Register&lt;br /&gt;4) Optical disk&lt;br /&gt;Answer: 2&lt;br /&gt;Exp: by def&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;13) The set of tracks that are at one arm position forms a ________&lt;br /&gt;1) sector&lt;br /&gt;2) cylinder&lt;br /&gt;3) platter&lt;br /&gt;4) Spindel&lt;br /&gt;Answer: Cylinder&lt;br /&gt;Exp: by def&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;14) ____ is the rate at which data flow between the drive and the computer.&lt;br /&gt;1) bit rate&lt;br /&gt;2) transfer rate&lt;br /&gt;3) data rate&lt;br /&gt;4) None&lt;br /&gt;Answer: Transfer rate&lt;br /&gt;Exp: by def&lt;br /&gt;Level:1&lt;br /&gt;15) The positioning time is also called ___&lt;br /&gt;a. Seek time&lt;br /&gt;b. Rotational latency&lt;br /&gt;c. Transfer rate&lt;br /&gt;d. Random access time&lt;br /&gt;   Answer:4&lt;br /&gt;Exp: ( by definition of random access time)&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;16) Time to move the disc arm to the desired cylinder is called____&lt;br /&gt;1) seek time&lt;br /&gt;2) wait time&lt;br /&gt;3) turn around time&lt;br /&gt;4) None&lt;br /&gt;Answer: Seek time&lt;br /&gt;Exp: ( by definition of the seek time)&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;17) The time for the desired sector to rotate to the disc head is called ____&lt;br /&gt;1) seek time&lt;br /&gt;2) rotational latency&lt;br /&gt;3) sweep time&lt;br /&gt;4) None&lt;br /&gt;Answer: Rotational latency&lt;br /&gt;Exp:  ( by definition of rotational latency)&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;18) Even though disc platters are coated with a thin protective layer, sometimes the head will damage the magnetic surface. This accident is called______&lt;br /&gt;1) system crash&lt;br /&gt;2) hardware crash&lt;br /&gt;3) head crash&lt;br /&gt;4) None&lt;br /&gt;Answer: Head crash&lt;br /&gt;Exp: by def&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;19) EIDE stands for&lt;br /&gt;1) Extended indexed directory extensions&lt;br /&gt;2) Enhanced Integrated Drive Electronics&lt;br /&gt;3) Enhanced Integrated Disk Electronics&lt;br /&gt;4) None&lt;br /&gt;Answer: 2&lt;br /&gt;Exp: acronym&lt;br /&gt;Level:2&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;20) Cache memory is divided into (and loaded in) blocks also called ________&lt;br /&gt;a. Cache blocks&lt;br /&gt;b. Cache lines&lt;br /&gt;c. Both the above&lt;br /&gt;d. None of the above&lt;br /&gt;Answer: 2&lt;br /&gt;Exp: by def&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;21) Modem can convert &lt;br /&gt;                1) Digital data to analog signals &lt;br /&gt;                2) Analog signals to digital signals.&lt;br /&gt;                3) Both the above&lt;br /&gt;                4) 2 only &lt;br /&gt;          Answer: 3&lt;br /&gt;          Exp:n by def&lt;br /&gt;&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;22) ______________is the rapid switching of the CPU between processes given the illusion of all processes running concurrently.&lt;br /&gt;a. Multiprogramming&lt;br /&gt;b. Multitasking&lt;br /&gt;c. Timesharing&lt;br /&gt;d. None&lt;br /&gt;                Answer: a and b&lt;br /&gt;Exp: by def&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt; 23) Which of the following instructions (or instruction sequences) should only be allowed in kernel mode? &lt;br /&gt;1. Disable all interrupts. &lt;br /&gt;2. Read the time of day clock. &lt;br /&gt;3. Set the time of day clock. &lt;br /&gt;4. Change the memory map. &lt;br /&gt;5. Write to the hard disk controller register. &lt;br /&gt;6. Write all buffered blocks associated with a file back to disk (fsync). &lt;br /&gt;1) 1,3,4,5 need to be restricted to kernel mode. &lt;br /&gt;2) 1, 6, 3, 2&lt;br /&gt;3) 1, 2, 3, 4, 5&lt;br /&gt;4) 3, 4, 1, 2&lt;br /&gt;Answer: 1&lt;br /&gt;Exp: properties of the kernel mode&lt;br /&gt;Level:2&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-1148162955117755914?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/1148162955117755914/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=1148162955117755914' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/1148162955117755914'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/1148162955117755914'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/computer-system-structures-interview_27.html' title='Computer System Structures Interview Questions Part12'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-5293645764419420673</id><published>2007-10-27T11:57:00.000-07:00</published><updated>2007-10-27T12:10:59.243-07:00</updated><title type='text'>Computer System Structures Interview Questions Part1</title><content type='html'>1) Which program gets loaded first when a computer is booted?&lt;br /&gt;1) Operating System&lt;br /&gt;2) Bootstrap loader&lt;br /&gt;3) Device drivers&lt;br /&gt;4) All of the above &lt;br /&gt;&lt;br /&gt;Answer: 2&lt;br /&gt;Exp: Bootstrap loader is the first program to be loaded into main memory from the ROM&lt;br /&gt;Level:2&lt;br /&gt;&lt;br /&gt;2) System Call is also known as?&lt;br /&gt;1) Monitor call&lt;br /&gt;2) User call&lt;br /&gt;3) Software call&lt;br /&gt;4) None of the above&lt;br /&gt;&lt;br /&gt;Answer: 1&lt;br /&gt;Exp: by def&lt;br /&gt;Level:2&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3) Modern OS are &lt;br /&gt;1) procedure driven&lt;br /&gt;2) Interrupt driven&lt;br /&gt;3) Function call driven&lt;br /&gt;4) None of the above&lt;br /&gt;                 &lt;br /&gt;Answer: 2&lt;br /&gt;Exp: derived from today’s application OS&lt;br /&gt;Level:2&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;4) Exception is also known as &lt;br /&gt;1) Interrupt &lt;br /&gt;                 2) Handler&lt;br /&gt;                 3) Trap&lt;br /&gt;                 4) None of the above&lt;br /&gt;                Answer: 1 and 3&lt;br /&gt;Exp: alternate names&lt;br /&gt;Level:2&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;5) The smallest addressable portion of a disc is called &lt;br /&gt;1) Track&lt;br /&gt;2) Cylinder&lt;br /&gt;3) Sector&lt;br /&gt;4) Platter&lt;br /&gt;&lt;br /&gt;Answer:3&lt;br /&gt;Exp: by def&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;6) SCSI stands for&lt;br /&gt;1) Super Computer- Systems Interface&lt;br /&gt;2) Small Computer- Systems Interface&lt;br /&gt;3) Single Computer- Systems Interface&lt;br /&gt;4) Simple Computer- Systems Interface&lt;br /&gt;&lt;br /&gt;Answer: 2&lt;br /&gt;Exp: by def&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;      7) DMA stands for&lt;br /&gt;               1) Disc Memory Allocation&lt;br /&gt;               2) Direct Memory Allocation&lt;br /&gt;               3) Dynamic Memory Allocation&lt;br /&gt;               4) Disc Memory Access&lt;br /&gt;               &lt;br /&gt;Answer: 3&lt;br /&gt;Exp: by def&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;8) DRAM stands for&lt;br /&gt;               1) Direct Random Access Memory&lt;br /&gt;               2) Dynamic Random Access Memory&lt;br /&gt;               3) Distributed Random Access Memory&lt;br /&gt;               4) Dynamic Random Allocation of Memory &lt;br /&gt;&lt;br /&gt;               Answer: 2&lt;br /&gt;               Exp: acronym&lt;br /&gt;Level:1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;9) An instruction will be stored in _____________&lt;br /&gt;1) Instruction Register&lt;br /&gt;2) Program Counter&lt;br /&gt;3) Stack Pointer&lt;br /&gt;4) Data Segment&lt;br /&gt;Answer: 1&lt;br /&gt;Exp: by def of instruction register&lt;br /&gt;Level:1&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-5293645764419420673?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/5293645764419420673/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=5293645764419420673' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5293645764419420673'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5293645764419420673'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/computer-system-structures-interview.html' title='Computer System Structures Interview Questions Part1'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-6855605302569553463</id><published>2007-10-27T11:01:00.002-07:00</published><updated>2007-10-27T11:02:47.365-07:00</updated><title type='text'>Sorting Interview Questions Part 9</title><content type='html'>36. According to the max-heap property, each node in a tree has a key which is _______ than or equal to the key of its parent.&lt;br /&gt; Ans. less&lt;br /&gt;&lt;br /&gt;37. A sort algorithm that repeatedly looks through remaining itemsto find the least one and moves it to its final location is&lt;br /&gt;  a. Quick sort&lt;br /&gt;  b. Insertion sort&lt;br /&gt;  c. Selection sort&lt;br /&gt;  d. Merge sort&lt;br /&gt; Ans. c&lt;br /&gt;&lt;br /&gt; 38. __________ is a specialization of selection sort.&lt;br /&gt;   a. quick sort&lt;br /&gt;   b. selection sort&lt;br /&gt;   c. bingo sort &lt;br /&gt;   d. strand sort&lt;br /&gt; Ans. c&lt;br /&gt;  Bingo sort is a variant of selection sort that orders items by repeatedly looking through remaining items to find the greatest value and moving all items with that value to their final location. This is more efficient if there are many duplicate values.&lt;br /&gt;&lt;br /&gt;39. __________ can be seen as a variant of selection sort in which sorted items are arranged in a heap to quickly find the next item.&lt;br /&gt;  a. heap sort&lt;br /&gt;  b. bingo sort&lt;br /&gt;  c. shell sort&lt;br /&gt;  d.none of the above&lt;br /&gt;Ans. a&lt;br /&gt;&lt;br /&gt;40. ___________ is a kind of quicksort&lt;br /&gt;  a. balanced quicksort&lt;br /&gt;  b. multikey quicksort&lt;br /&gt;  c. retrospective sort&lt;br /&gt;  d. all the above&lt;br /&gt; Ans. d&lt;br /&gt; &lt;br /&gt;41. ___________ is a part of or used in quicksort.&lt;br /&gt;    a. divide and conquer&lt;br /&gt;    b. partition &lt;br /&gt;    c. recursion&lt;br /&gt;    d. all the above&lt;br /&gt;Ans. d&lt;br /&gt;&lt;br /&gt;42. Insertion sort is also known as __________.&lt;br /&gt;  Ans. Linear insertion sort&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;43. Given the following sequence of elements 11,2,9,13,57,25,17,1,90,3 what will be the output after MAX_HEAPIFY(A,2) where heap-size[A]=10.&lt;br /&gt; a. 11,2,9,13,25,57,17,1,90,3&lt;br /&gt; b. 11,2,9,90,57,25,17,1,13,3&lt;br /&gt; c. 11,90,9,13,57,25,17,1,2,3&lt;br /&gt; d. 90,57,25,13,11,9,17,1,2,3&lt;br /&gt;ans. c&lt;br /&gt;&lt;br /&gt;44. Given the following set of elements 16,4,10,14,7,9,3,2,8,1 what will be the output after MAX_HEAPIFY(A,2) where heap-size[A]=10.&lt;br /&gt; a. 16,4,10,14,7,9,3,2,8,1&lt;br /&gt; b. 16,14,10,4,7,9,3,2,8,1&lt;br /&gt; c. 16,14,10,8,7,9,3,2,4,1&lt;br /&gt; d. 16,14,10,8,7,3,9,2,4,1&lt;br /&gt;Ans. c&lt;br /&gt;&lt;br /&gt;45. Give the output of MAX_HEAPIFY(A,3) in the array A=( 27,17,3,16,13,10,1,5,7,12,4,8,9,0).&lt;br /&gt; a. 27,17,3,16,13,10,1,5,7,12,4,8,9,0&lt;br /&gt; b. 27,17,10,16,13,3,1,5,7,12,4,8,9,0&lt;br /&gt; c. 27,17,10,16,13,9,1,5,7,12,4,8,3,0&lt;br /&gt; d. 27,17,3,16,13,7,1,5,10,12,4,8,9,0&lt;br /&gt;Ans. c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;46. If the sequence: (2,2) (0,4) (1,4) (0,1) (1,2) (0,6) (2,1) (1,1) were sorted using a&lt;br /&gt;stable sort by ascending order on the first key and then using the same method were&lt;br /&gt;sorted again on the second key, the result would be:&lt;br /&gt;8.a). (0,4) (0,1) (0,6) (1,4) (1,2) (1,1) (2,2) (2,1)&lt;br /&gt;8.b). (0,1) (2,1) (1,1) (2,2) (1,2) (0,4) (1,4) (0,6)&lt;br /&gt;8.c). (2,1) (1,1) (0,1) (2,2) (1,2) (1,4) (0,4) (0,6)&lt;br /&gt;8.d). (0,1) (1,1) (2,1) (1,2) (2,2) (0,4) (1,4) (0,6) ***&lt;br /&gt;8.e). (0,1) (0,4) (0,6) (1,1) (1,2) (1,4) (2,1) (2,2)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;47. Mergesort always runs faster than bubblesort. (T/F)&lt;br /&gt;false -- depends on the constants and the size of the input.  Given a large enough input, mergesort will most likely run faster than bubblesort.&lt;br /&gt;48. Selection sort and quicksort both fall into the same category of sorting algorithms. What is this category? &lt;br /&gt;A. O(n log n) sorts &lt;br /&gt;B. Divide-and-conquer sorts &lt;br /&gt;C. Interchange sorts &lt;br /&gt;D. Average time is quadratic&lt;br /&gt;Ans:c&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-6855605302569553463?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/6855605302569553463/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=6855605302569553463' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/6855605302569553463'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/6855605302569553463'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/sorting-interview-questions-part-9.html' title='Sorting Interview Questions Part 9'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-2611832129676495523</id><published>2007-10-27T11:01:00.001-07:00</published><updated>2007-10-27T11:01:26.833-07:00</updated><title type='text'>Sorting Interview Questions Part 8</title><content type='html'>21. If p &lt; r then &lt;br /&gt;    q Partition (A, p, r) &lt;br /&gt;    Recursive call to Sort (A, p, q) &lt;br /&gt;    Recursive call to Sort (A, q + r, r) &lt;br /&gt; Which sorting algorithm does SORT represent&lt;br /&gt;a.Selection sort  b.quick sort  c.Bubble sort  d.Merge sort&lt;br /&gt;Ans:b&lt;br /&gt;22. _____Sort chooses as pivot one of the items in the array to be sorted.&lt;br /&gt;a.Selection sort  b.quick sort  c.Bubble sort  d.Merge sort&lt;br /&gt;Ans:b&lt;br /&gt;23.Selection sort is&lt;br /&gt;a.inplace&lt;br /&gt;b.noninplace&lt;br /&gt;c.out place&lt;br /&gt;d.none&lt;br /&gt;Ans:a&lt;br /&gt;24.Bubble sort is&lt;br /&gt;a.inplace&lt;br /&gt;b.noninplace&lt;br /&gt;c.out place&lt;br /&gt;d.none&lt;br /&gt;Ans:a&lt;br /&gt;25.Which of the following are stable algorithms&lt;br /&gt;a.Bubble b.Insertion c.Both d.none&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;26. An array in sorted order is in __________.&lt;br /&gt;a.Max-heap&lt;br /&gt;b.Min-heap&lt;br /&gt;c.Random heap&lt;br /&gt;d.none&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;27. Assuming all the elements to be distinct, where in the Max-heap might the smallest element reside ?&lt;br /&gt;&lt;br /&gt;a.In the root position&lt;br /&gt;b.In the left sub tree of the root&lt;br /&gt;c.In the right sub tree of the root&lt;br /&gt;d.In some leaf node&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;28. Assuming all the elements to be distinct, where in the Min-heap might the smallest element reside ?&lt;br /&gt;&lt;br /&gt;a.In the root position&lt;br /&gt;b.In the left sub tree of the root&lt;br /&gt;c.In the right sub tree of the root&lt;br /&gt;d.In some leaf node&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;29. Assuming all the elements to be distinct, where in the Max-heap might the largest element reside ?&lt;br /&gt;&lt;br /&gt;a.In the root position&lt;br /&gt;b.In the left sub tree of the root&lt;br /&gt;c.In the right sub tree of the root&lt;br /&gt;d.In some leaf node&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;30. Assuming all the elements to be distinct, where in the Min-heap might the largest element reside ?&lt;br /&gt;&lt;br /&gt;a.In the root position&lt;br /&gt;b.In the left sub tree of the root&lt;br /&gt;c.In the right sub tree of the root&lt;br /&gt;d.In some leaf node&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;31.Which of the following is useful in implementing quick sort&lt;br /&gt;a.Stack&lt;br /&gt;b.List&lt;br /&gt;c.Queue&lt;br /&gt;d.Set&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;32.Which of the following algorithm design technique is used for quick sort&lt;br /&gt;a.Dynamic programming&lt;br /&gt;b.Backtracking&lt;br /&gt;c.Divide and conquer&lt;br /&gt;d.Greedy method&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;33. If the records that it's sorting are in main memory then the sort is called as&lt;br /&gt; a. internal&lt;br /&gt; b. external&lt;br /&gt; c. stable&lt;br /&gt; d. none of this&lt;br /&gt; Ans. a&lt;br /&gt;&lt;br /&gt;34. An array of elements is sorted by choosing a pivot element &amp; by partition.The sorting process is called&lt;br /&gt; a. Partition exchange sort&lt;br /&gt; b. Quick sort&lt;br /&gt; c. a and b&lt;br /&gt; d. selection sort&lt;br /&gt;Ans. c&lt;br /&gt;&lt;br /&gt;35. In min-heap property,each node in a tree has a key which is _______ than or equal to the key of its parent.&lt;br /&gt; Ans. greater&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-2611832129676495523?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/2611832129676495523/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=2611832129676495523' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2611832129676495523'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2611832129676495523'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/sorting-interview-questions-part-8.html' title='Sorting Interview Questions Part 8'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-804711402840205161</id><published>2007-10-27T10:59:00.002-07:00</published><updated>2007-10-27T11:00:43.988-07:00</updated><title type='text'>Sorting Interview Questions Part 7</title><content type='html'>11. In bubble sort algorithm the number of comparison is irrespective of data set i.e., input whether best or worst.(T/F)&lt;br /&gt;Ans:True&lt;br /&gt;12. The basic procedures related to heap are&lt;br /&gt;a.Heapify, which runs in O(lg n) time. &lt;br /&gt;b.Build-Heap, which runs in linear time. &lt;br /&gt;c.Heap Sort, which runs in O(n lg n) time. &lt;br /&gt;d.Extract-Max, which runs in O(lg n) time. &lt;br /&gt;Ans:a,b,c,d&lt;br /&gt;13. Heapify runs in O(lg n) time while build-heap runs in _____time.&lt;br /&gt;Ans: linear&lt;br /&gt;14. A process picks the largest child key and compares it to the parent key and if parent key is larger then the process quits, otherwise it swaps the parent key with the largest child key, so that the parent now becomes larger than its children.Such a process is called&lt;br /&gt;a.Heap sort&lt;br /&gt;b.Heapify&lt;br /&gt;c.Build heap&lt;br /&gt;d.none&lt;br /&gt;Ans:b&lt;br /&gt;15. Process (A, i)&lt;br /&gt;1. l ← left [i] &lt;br /&gt;2. r ← right [i] &lt;br /&gt;3. if l ≤ Process-size [A] and A[l] &gt; A[i] &lt;br /&gt;4.     then largest ← l &lt;br /&gt;5.     else largest ← i &lt;br /&gt;6. if r ≤ Process -size [A] and A[i] &gt; A[largest] &lt;br /&gt;7.     then largest ← r &lt;br /&gt;8. if largest  ≠ i &lt;br /&gt;9.     then exchange A[i] ↔ A[largest] &lt;br /&gt;10.        Process (A, largest) &lt;br /&gt;The above process indicates&lt;br /&gt;a.Heap sort&lt;br /&gt;b.Heapify&lt;br /&gt;c.Build heap&lt;br /&gt;d.none&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;16.The output of heapify of the following tree is&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;a. 15 8 4 7 5 3 1 2 6  b. 8 15 4 7 5 3 1 2 6 c. 15 8 4 7 5 3 1 6 2  d. 15 8 4 5 7 3 1 2 6&lt;br /&gt;Ans:a&lt;br /&gt;17. Process (A)&lt;br /&gt;1. BUILD_HEAP (A) &lt;br /&gt;2. for i ← length (A) down to 2 do&lt;br /&gt;exchange A[1] ↔ A[i]&lt;br /&gt;heap-size [A] ← heap-size [A] - 1&lt;br /&gt;Heapify (A, 1)&lt;br /&gt;The process here denotes&lt;br /&gt;a.Selection sort  b.Heap sort  c.Bubble sort  d.none&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;18. The time taken for build heap is&lt;br /&gt;a.O(n)&lt;br /&gt;b.O(log n)&lt;br /&gt;c.O(nlogn)&lt;br /&gt;d.none&lt;br /&gt;Ans:a&lt;br /&gt;The HEAPSORT procedure takes time O(n lg n), since the call to BUILD_HEAP takes time O(n) and each of the n -1 calls to Heapify takes time O(lg n).&lt;br /&gt;19. Process (A1, A2, A)&lt;br /&gt;i.← j 1&lt;br /&gt;A1[m+1], A2[n+1] ← INT_MAX&lt;br /&gt;For k ←1 to m + n do&lt;br /&gt;    if A1[i] &lt; A2[j] &lt;br /&gt;        then A[k] ← A1[i]&lt;br /&gt;            i ← i +1&lt;br /&gt;        else&lt;br /&gt;            A[k] ← A2[j]&lt;br /&gt;                j ← j + 1 &lt;br /&gt;SORT (A)&lt;br /&gt;A1[1 . .  n/2 ] ← A[1 . .  n/2 ] &lt;br /&gt;A2[1 . .  n/2 ] ← A[1 +  n/2  . . n] &lt;br /&gt;Process (A1)&lt;br /&gt;Process (A1)&lt;br /&gt;Process (A1, A2, A)&lt;br /&gt;Which sorting algorithm does SORT represent&lt;br /&gt;a.Selection sort  b.Heap sort  c.Bubble sort  d.Merge sort&lt;br /&gt;Ans:d&lt;br /&gt;20.Quick sort is recursive.(T/F)&lt;br /&gt;Ans:True&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-804711402840205161?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/804711402840205161/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=804711402840205161' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/804711402840205161'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/804711402840205161'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/sorting-interview-questions-part-7.html' title='Sorting Interview Questions Part 7'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-5069150954480408803</id><published>2007-10-27T10:59:00.001-07:00</published><updated>2007-10-27T10:59:53.040-07:00</updated><title type='text'>Sorting Interview Questions Part 6</title><content type='html'>1. Divide-and-conquer is a &lt;br /&gt;a.top-down technique&lt;br /&gt;b.Bottom-up technique&lt;br /&gt;c.Both&lt;br /&gt;d.none&lt;br /&gt;Ans:a&lt;br /&gt;2.The technique for designing algorithms that consists of dividing the problem into smaller subproblems hoping that the solutions of the subproblems are easier to find and then composing the partial solutions into the solution of the original problem is _____&lt;br /&gt;Ans:Divide and conquer&lt;br /&gt;3. Divide-and-conquer paradigm consists of following major phases:Arrange them in order&lt;br /&gt;a.Solve the sub-problem recursively (successively and independently), and then &lt;br /&gt;b.Breaking the problem into several sub-problems that are similar to the original problem but smaller in size, &lt;br /&gt;c.Combine these solutions to subproblems to create a solution to the original problem. &lt;br /&gt;a. bac&lt;br /&gt;b. abc&lt;br /&gt;c. cab&lt;br /&gt;d. none&lt;br /&gt;Ans:a&lt;br /&gt;4. Bubble sort requires extra memory.(T/F)&lt;br /&gt;Ans:False&lt;br /&gt;5. Insertion sort is an example of &lt;br /&gt;a.incremental sort&lt;br /&gt;b.decremental sort&lt;br /&gt;c.non-stable sort&lt;br /&gt;d.none&lt;br /&gt;Ans:a&lt;br /&gt; Insertion sort is an example of an incremental algorithm; it builds the sorted sequence one number at a time. &lt;br /&gt;6. An algorithm considering the elements one at a time, inserting each in its suitable place among those already considered (keeping them sorted) is called&lt;br /&gt;a.selection sort&lt;br /&gt;b.insertion sort&lt;br /&gt;c.bubble sort &lt;br /&gt;d.none&lt;br /&gt;Ans:b&lt;br /&gt;7.The following process depicts which sorting algorithm: first find the smallest in the array and exchange it with the element in the first position, then find the second smallest element and exchange it with the element in the second position, and continue in this way until the entire array is sorted.&lt;br /&gt;a.selection sort&lt;br /&gt;b.insertion sort&lt;br /&gt;c.bubble sort &lt;br /&gt;d.none&lt;br /&gt;Ans:a&lt;br /&gt;8. Selection sort is quadratic in both the worst and the average case, and requires no extra memory.(T/F)&lt;br /&gt;Ans:True&lt;br /&gt;9. For each i from 1 to n - 1, there are ____ exchanges for selection sort.&lt;br /&gt;a.1&lt;br /&gt;b.n-1&lt;br /&gt;c.n &lt;br /&gt;d.none&lt;br /&gt;Ans:a &lt;br /&gt;10.For each i from 1 to n - 1, there is  _______comparisons for selection sort.&lt;br /&gt;a.n&lt;br /&gt;b.n-i&lt;br /&gt;c.i&lt;br /&gt;d.n-1&lt;br /&gt;Ans:b &lt;br /&gt;For each i from 1 to n - 1, there is one exchange and n - i comparisons, so there is a total of n -1 exchanges and (n -1) + (n -2) + . . . + 2 + 1 = n(n -1)/2 comparisons. These observations hold no matter what the input data is.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-5069150954480408803?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/5069150954480408803/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=5069150954480408803' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5069150954480408803'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5069150954480408803'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/sorting-interview-questions-part-6.html' title='Sorting Interview Questions Part 6'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-49946641307597420</id><published>2007-10-27T10:58:00.001-07:00</published><updated>2007-10-27T10:58:57.325-07:00</updated><title type='text'>Sorting Interview Questions Part 5</title><content type='html'>68. Which of these is the correct big-O expression for 1+2+3+...+n? &lt;br /&gt;A. O(log n) &lt;br /&gt;B. O(n) &lt;br /&gt;C. O(n log n) &lt;br /&gt;D. O(n²) &lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;69. Consider the following polynomial&lt;br /&gt;&lt;br /&gt;       aknk+ak-1nk-1+………….a0 .&lt;br /&gt;&lt;br /&gt;What is the Big –O representation of the above polynomial? &lt;br /&gt;(a)O(n)  (b) O(nk)  (c)  O(nk+1)   (d) O(log k)&lt;br /&gt;Ans:b&lt;br /&gt;70. Consider the program segment given below:&lt;br /&gt;Int i,j,sum;&lt;br /&gt;for ( i=0 ; i &lt; n; i++) {&lt;br /&gt;   for (j = 1,sum=a[0]; j &lt; = i; j++)&lt;br /&gt;        Sum+=a[j];&lt;br /&gt;     printf(“ sum for sub-array  through %d is %d”,i , sum);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The running time of the above algorithm is &lt;br /&gt;&lt;br /&gt;(a) n.  (b) n log n .  (c) log n.  (d) n2.&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;71. Consider the following algorithm:&lt;br /&gt;&lt;br /&gt;Step 1 : If S has zero or one element, return S immediately; it is already sorted. Otherwise, split S into two parts S1 and S2, such that S1 contains the first [n/2] elements of S, and S2 contains the remaining elements of S.&lt;br /&gt;Step 2: Recursively sort sequences S1 and S2&lt;br /&gt;Step 3: put back the elements into S by merging the sorted sequences S1 and S2 into a sorted sequence.&lt;br /&gt;&lt;br /&gt;Which of the following describe(s) the above algorithm?&lt;br /&gt;&lt;br /&gt;(a) Sorting by insertion&lt;br /&gt;(b) Sorting by selection&lt;br /&gt;(c) Sorting by exchange&lt;br /&gt;(d) Divide and conquer&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;72. Consider the following algorithm :&lt;br /&gt;abc(data[])&lt;br /&gt;Transform data into a heap&lt;br /&gt;for ( i=data.length-1; i&gt; 1 ; i--)&lt;br /&gt;Swap the root with the element in position i;&lt;br /&gt;Restore the heap property for the tree data[0],…….. data[i-1];&lt;br /&gt;Which of the following are not the intermediate functions of the above algorithm?&lt;br /&gt;(a) Transforming data into either an ascending order or descending order of a heap&lt;br /&gt;(b) Transforming data into a maximum heap&lt;br /&gt; (c) The 1st step of the sorting process is exchanging the last element and the first element, and decreasing the array size by one.&lt;br /&gt;(d) Finally, get either the ascending order or the descending order of nodes&lt;br /&gt;Ans: b&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-49946641307597420?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/49946641307597420/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=49946641307597420' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/49946641307597420'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/49946641307597420'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/sorting-interview-questions-part-5.html' title='Sorting Interview Questions Part 5'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-5322568276146587469</id><published>2007-10-27T10:57:00.000-07:00</published><updated>2007-10-27T10:58:04.151-07:00</updated><title type='text'>Sorting Interview Questions Part 4</title><content type='html'>61.How many passes are required to sort the set of integers using the bubble sort algorithm? {20,60,50,37,16,92,70,35}.&lt;br /&gt;&lt;br /&gt;(a) 6 (b) 7 (c) 8&lt;br /&gt;(d) 9 (e) 5&lt;br /&gt;  Ans. b&lt;br /&gt;&lt;br /&gt;       62.Consider the following pseudo code algorithm&lt;br /&gt;found = false;&lt;br /&gt;i=1;&lt;br /&gt;while (i =&lt; n ) and ( not found)&lt;br /&gt;{&lt;br /&gt;if key=k[i] then&lt;br /&gt;{&lt;br /&gt;search =i;&lt;br /&gt;found =true;&lt;br /&gt;else&lt;br /&gt;i++;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;if not found&lt;br /&gt;{&lt;br /&gt;search=0;&lt;br /&gt;}&lt;br /&gt;What is the above algorithm intended to do?&lt;br /&gt;(a) Sequential Search (b) Depth First Algorithm&lt;br /&gt;(c) Shell sort algorithm (d) Index sequential search&lt;br /&gt;(e) Breadth first search&lt;br /&gt;Ans.  a&lt;br /&gt;&lt;br /&gt;    63. Consider the following (iv) conditions:&lt;br /&gt;(i) Sorts which cannot be performed in the main memory, can be done on disk or tape. These are also quite important.  This type of sorting is called external sorting.&lt;br /&gt;(ii) The simplest algorithms usually take O(n2) time to sort in objects and are only useful for sorting short lists.&lt;br /&gt;(iii) One of the most popular sorting algorithm is quicksort; which takes O(log n) time on average.&lt;br /&gt;(iv) Merge sort is well suited for external sorting.&lt;br /&gt;        Which of the above conditions are applied for the sorting algorithm?&lt;br /&gt;a. (i),(ii) and (iii) only&lt;br /&gt;b. (i),(ii) and (iv) only&lt;br /&gt;c. (ii),(iii) and (iv) only&lt;br /&gt;d. (i) and (iii) only&lt;br /&gt;&lt;br /&gt;Ans. b&lt;br /&gt;&lt;br /&gt;64. Which sorting method(s) runs fastest for file which is already sorted?&lt;br /&gt;a.Selection sort&lt;br /&gt;b.insertion sort&lt;br /&gt;c.quick sort&lt;br /&gt;d.bubble sort&lt;br /&gt;Ans:b&lt;br /&gt;65.&lt;br /&gt;(i) Quick Sort can be implemented in recursive way.&lt;br /&gt;(ii) Heap Sort is the best sorting method compared to bubble, selection, insertion sort on the basis of complexity.&lt;br /&gt;&lt;br /&gt;Correct statement(s) is/are?&lt;br /&gt;A(i) only&lt;br /&gt;b (ii) only&lt;br /&gt;c.(i) and (ii) &lt;br /&gt;d.none&lt;br /&gt;Ans:c&lt;br /&gt;66. In calculating the time complexity of an algorithm, we use some rules.&lt;br /&gt;&lt;br /&gt;Rule 1.&lt;br /&gt;If   T1 (N)=O(f(N)) and T2(N)=O(g(N)) then &lt;br /&gt;Statement 1 T1(N) + T2 (N)=Max(O(f(N)),O(g(N)))&lt;br /&gt;Statement 2 T1(N)* T2(N)=O(f(N)*g(N))&lt;br /&gt;Rule 2&lt;br /&gt;If  T1(N)=O(f(N)) and T2(N)=O(g(N)) then&lt;br /&gt;Statement 1 T1(N)+ T2(N)=Min(O(f(N)),O(g(N)))&lt;br /&gt;Statement 2 T1(N)* T2(N)=O(f(N))+O(g(N))&lt;br /&gt;Rule 3&lt;br /&gt;O(C f(N))=O(f(N)) if C is a constant&lt;br /&gt;Rule 4&lt;br /&gt;If   T1 (N)=O(f(N)) and T2(N)=O(g(N))  and If g(N) &lt; = f(N) then&lt;br /&gt;T1(N)+ T2(N)=O(f(N))&lt;br /&gt;&lt;br /&gt;What are the correct rules out of the above?&lt;br /&gt;a.Rule 1 , Rule 2 and Rule 3 only&lt;br /&gt;b.Rule 1 and Rule 4 only&lt;br /&gt;c.Rule 1 , Rule 3 and Rule 4 only&lt;br /&gt;d.Rule 2, Rule 3 and Rule 4 only&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;67. What is the name of the following algorithm?&lt;br /&gt;&lt;br /&gt;Initialize marker to 1 (2nd element in the list)&lt;br /&gt;If element[marker1] &lt; element [marker1-1] , store element[marker1] in a temporary location temp, initialize marker2  to marker1-1 (the location just before marker1).&lt;br /&gt;While element [marker2] &gt; temp and marker2 &gt;= 0 shift element [marker2] to location marker2+1. [this slides the element over to make room to its left) Decrease marker2 by 1.&lt;br /&gt;Insert temp into the location just vacated by a shift.&lt;br /&gt;Increase marker1 by 1.&lt;br /&gt;a. Insertion sort   b. bubble sort c. selection sort   d. none&lt;br /&gt;Ans: d&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-5322568276146587469?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/5322568276146587469/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=5322568276146587469' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5322568276146587469'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5322568276146587469'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/sorting-interview-questions-part-4.html' title='Sorting Interview Questions Part 4'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-3940627061657102384</id><published>2007-10-27T10:56:00.000-07:00</published><updated>2007-10-27T10:57:31.250-07:00</updated><title type='text'>Sorting Interview Questions Part 3</title><content type='html'>41.Sorting is not useful for&lt;br /&gt;   a. report generation&lt;br /&gt;   b. minimizing the storage needed&lt;br /&gt;   c. making searching easier and efficient&lt;br /&gt;   d. responding to queries easily&lt;br /&gt;Ans. b&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   42. Choose the correct statements&lt;br /&gt;  a.  Internal sorting is used if the number of items to be sorted is very large&lt;br /&gt;  b.  External sorting is used if the number of items to be sorted is very large&lt;br /&gt;  c.  External sorting does not need auxiliary storage&lt;br /&gt;  d. Internal sorting  need auxiliary storage&lt;br /&gt;Ans. b &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;  43. A sorting technique that guarantees that records with the same primary key occurs in the same order in the sorted list as in the original unsorted list is said to be&lt;br /&gt; a. stable     b. consistent     c. external      d. linear&lt;br /&gt;Ans.  a&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; 44.The running time of an algorithm is given by&lt;br /&gt;                     T(n) = T(n-1) + T(n-2) – T(n-3),if n&gt;3&lt;br /&gt;                             = n,otherwise.&lt;br /&gt;        The order is&lt;br /&gt;  a. n          b. log n        c. n^n       d. n^2&lt;br /&gt;Ans. a&lt;br /&gt;  Let us find what is T(4) and T(5) &lt;br /&gt;        T(4) = T(3) + T(2) – T(1) = 3+2-1=4&lt;br /&gt;       T(5) = T(4)+ T(3) –(2) = 4+3-2=5&lt;br /&gt;By induction it can be proved that T(n) = n.Hence order is n.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; 45.The order of an algorithm that finds whether a given Boolean function of ‘n’ variables,produces a 1 is&lt;br /&gt;a.  constant        b. linear        c. logarithmic       d. exponential&lt;br /&gt;Ans.  d&lt;br /&gt;  In the worst case it has to be check all the 2^n possible input combinations,which is exponential .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     46.You want to check whether a given set of items is sorted or not.Which of the following sorting methods will be the most efficient if it is already in sorted order?&lt;br /&gt;a. Bubble sort       b. Selection sort      c. Insertion sort       d.Merge sort&lt;br /&gt;Ans.  c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     47. The average number of comparisons performed by the merge sort algorithm,in merging two sorted lists of length 2 is&lt;br /&gt; a. 8/3        b. 8/5       c. 11/7       d.11/6&lt;br /&gt;Ans. a&lt;br /&gt;Merge sort combines 2 given sorted lists into one sorted list.For this problem let the final sorted order be a,b,c and d.The 2 lists(of length 2 each) should fall into one of the following 3 categories:&lt;br /&gt;i)a,b and c,d         ii)a,c and b,d       iii)a,d and b,c&lt;br /&gt;The number of comparisons needed in each case will be 2,3,3.So,average number of comparisons will be (2+3+3)/3=8/3.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;      48.Which of the following sorting methods will be the best if the number of swappings done is the only measure of efficiency?&lt;br /&gt;a. bubble sort      b. selection sort        c. insertion sort      d.quick sort&lt;br /&gt;Ans. b&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;       49.You are asked to sort 15 numbers randomly.You should prefer&lt;br /&gt;  a. bubble sort       b. quick sort       c. merge sort       d. heap sort&lt;br /&gt;Ans. a&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     50. As part of the maintenance work,you are entrusted with the work of rearranging the library books in a shelf in proper order,at the end of each day.The ideal choice will be&lt;br /&gt;  a. bubble sort         b. insertion sort       c. selection sort       d. heap sort &lt;br /&gt;Ans. b&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    51. Which of the following algorithms exhibits the unnatural behavior that,minimum number of comparisons are neede if the list to be sorted is in the reverse order and maximum number of comparisons are neede if they are already in order.&lt;br /&gt;a. heap sort        b. radix sort        c. binary insertion sort          d. there can’t be any such sorting method.&lt;br /&gt;Ans. c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     52.Which of the following sorting methods sorts a given set of items that is already in order or in reverse order with equal speed?&lt;br /&gt;  a. Heap sort         b. Quick sort          c. Insertion sort         d. selection sort&lt;br /&gt;Ans. b&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;      53. A machine needs  a minimum of 100 sec to sort 1000 names by quick sort.The minimum time needed to sort 100 names will be approx&lt;br /&gt;   a. 50.2 sec         b. 6.7 sec        c.72.7 sec        d. 11.2 sec&lt;br /&gt;Ans. b&lt;br /&gt; In the best case quick sort  algorithm makes nlogn comparisons.so,1000 * log(1000) = 9000 comparisons,which takes 100s.To sort 100 names a minimum of 100 * log(100)=600 comparisons are needed.This takes 100*600/9000 = 6.7 sec&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     54.A machine took 200 sec to sort 200 names,using bubble sort.In 800 sec,it can approximately sort&lt;br /&gt;   a. 400 names        b. 800 names        c. 750 names        d. 850 names&lt;br /&gt;Ans. a&lt;br /&gt; For sorting 200 anmes bubble sort makes 200 * 199/2 = 19900 comparisons.So,the time needed for 1 comparison is 200 sec approx.In 800 sec it can make 80,000 comparisons.We have to find n,such that n(n-1)/2=80,000.solving n is approx 400.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;       55.The correct order of arrangement of the names Bradman,Lamb,May,Boon,Border,Underwood and Boycott,so that the quicksort algorithm makes the least number of comparisons is&lt;br /&gt; a. Bradman,Border,Boon,Boycott,May,Lamb,Underwood&lt;br /&gt; b. Bradman,Border,Boycott,Boon,May,Underwood,Lamb&lt;br /&gt; c. Underwood,Border,Boon,Boycott,May,Lamb,Bradman&lt;br /&gt; d. Bradman,May,Lamb,Border,Boon,Boycott,Underwood&lt;br /&gt;Ans. a and b&lt;br /&gt;Let the first element be the pivot element always.The best way is the one that splits the list into two equal parts each time.This is possible if the pivot elemnt is the median.Consider the given set of names or the equivalent set 1,2,3,4,5,6,7.4 is the median and hence should be the pivot element.Since the first element is the pivot element,4 should be the first element.so after the first pass,4 will be put in the correct place and we are left with 2 sublists 1,2,3 and 5,6,7.Since 2 is the median of 1,2,3 the list should be rearranged as 2,1,3 or 2,3,1.For similar reasons 5,6,7 should be rearranged as 6,5,7 or 6,7,5.Hence the answer.   &lt;br /&gt;      &lt;br /&gt;    56. Which of the following is/are correct in connection with sorting methods?&lt;br /&gt;(a) Bubble sort uses sorting by an insertion technique to sort a file of numbers.&lt;br /&gt;(b) Quick sort uses sorting by an exchange technique to sort a file of numbers.&lt;br /&gt;(c) Shell sort uses sorting by an exchange technique to sort a file of numbers.&lt;br /&gt;(d) Heap sort does not use sorting by an exchange technique to sort a file of numbers.&lt;br /&gt;Ans. b&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     {2,8,13,6,7,27,18}&lt;br /&gt;   57)the maximum heap is created using the above set of integers, what would be the value at the 6th&lt;br /&gt;position of the heap?&lt;br /&gt;(a) 2 (b) 8 (c) 6&lt;br /&gt;(d) 13 (e) 7&lt;br /&gt;Ans. b&lt;br /&gt;&lt;br /&gt;   58.If one uses the quick sort algorithm to sort the following integers, how many pivot values are&lt;br /&gt;required? You may assume that the pivot element is always selected as the last element of the respective&lt;br /&gt;sub arrays. {50,22,11,78,16,95,7,75,51,41}.&lt;br /&gt;&lt;br /&gt;(a) 7 (b) 8 (c) 4&lt;br /&gt;(d) 6 (e) 5&lt;br /&gt;  Ans. d&lt;br /&gt;&lt;br /&gt;    59.If one uses the quick sort algorithm to sort the following set of integers how many pivot values are required?You may assume that the pivot element is always selected as the first element of the respective&lt;br /&gt;sub arrays. {50,22,11,78,16,95,7,75,51,41}.&lt;br /&gt;&lt;br /&gt;(a) 7 (b) 8 (c) 4&lt;br /&gt;(d) 6 (e) 5&lt;br /&gt;  Ans. e&lt;br /&gt;&lt;br /&gt;     60.If one uses the bubble sort algorithm in ascending order ,in which of the following pairs will the data values not interchange during the first pass? {20,60,50,37,16,92,70,35}.&lt;br /&gt;(a) 20,60 (b) 60,50 (c) 60,37&lt;br /&gt;(d) 50,37 (e) 60,16&lt;br /&gt;  Ans. a&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-3940627061657102384?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/3940627061657102384/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=3940627061657102384' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/3940627061657102384'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/3940627061657102384'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/sorting-interview-questions-part-3.html' title='Sorting Interview Questions Part 3'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-5829596697786857569</id><published>2007-10-27T10:55:00.000-07:00</published><updated>2007-10-27T10:56:21.107-07:00</updated><title type='text'>Sorting Interview Questions Part 2</title><content type='html'>25.Selectionsort and quicksort both fall into the same category of sorting algorithms. What is this category? &lt;br /&gt;A. O(n log n) sorts &lt;br /&gt;B. Divide-and-conquer sorts &lt;br /&gt;C. Interchange sorts  &lt;br /&gt;D. Average time is quadratic. &lt;br /&gt;Ans:C&lt;br /&gt;26. Which of the following is applicable for any constant ‘c’&lt;br /&gt;   a.c*log n=O(1)&lt;br /&gt;  b.c*log n =O(logn)&lt;br /&gt;  c.c*log n =O(nlogn) &lt;br /&gt;  d.c*log n =O(n)&lt;br /&gt;  Ans:b&lt;br /&gt;27.Which of the following is applicable for any constants‘c,k’&lt;br /&gt;   a.c*(n^k)=O(n^k)&lt;br /&gt;  b.c*(n^k) =O(logn)&lt;br /&gt;  c.c*(n^k) =O(nlogn) &lt;br /&gt;  d.c*(n^k) =O(1)&lt;br /&gt;  Ans:a&lt;br /&gt;28.The process of combining two or more sorted files into a third sorted file is _____&lt;br /&gt;Ans:merging&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;29.Which Sort Algorithm has same time complexity as Heap sort in all cases?&lt;br /&gt;a.Merge sort&lt;br /&gt;b.Bubble sort&lt;br /&gt;c.Selection sort&lt;br /&gt;d.none of these&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;30.Selection sort is faster than bubble sort(T/F)&lt;br /&gt;Ans:True&lt;br /&gt;Because a selection sort looks at progressively smaller parts of the array each time (as it knows to ignore the front of the array because it is already in order), a selection sort is slightly faster than bubble sort, and can be better than a modified bubble sort.&lt;br /&gt; &lt;br /&gt;      31.The worst-case time complexity of heap sort is same as the average-case                        time complexity of quick sort. &lt;br /&gt;a.        True&lt;br /&gt;b.       False&lt;br /&gt;            Ans.  b&lt;br /&gt; &lt;br /&gt;     32.Which of the following statements is FALSE?&lt;br /&gt;a.        Merge Sort is an unstable sort&lt;br /&gt;b.       Worst case time complexity of Merge Sort is O(NlogN)&lt;br /&gt;c.        Merge Sort takes more space than Quick Sort&lt;br /&gt;d.       Average case time complexity of Merge Sort is O(NlogN)&lt;br /&gt;            Ans.  c    &lt;br /&gt;                 &lt;br /&gt;   33.Both merge sort and quick sort are in-place sorts.&lt;br /&gt;a.       True&lt;br /&gt;b.      False &lt;br /&gt;               Ans.  b  &lt;br /&gt;&lt;br /&gt;   34.Sorting is not possible by using which of the following methods?&lt;br /&gt; (a) Insertion     &lt;br /&gt; (b) Selection     &lt;br /&gt; (c) Exchange      &lt;br /&gt; (d) Deletion&lt;br /&gt;&lt;br /&gt; Ans:d&lt;br /&gt;Using insertion we can perform insertion sort, using selection we can perform selection sort, using exchange we can perform the bubble sort (and other similar sorting methods). But no sorting method can be done just using deletion.&lt;br /&gt;&lt;br /&gt;  35.What are the methods available in storing sequential files ?&lt;br /&gt;a.Straight merging,&lt;br /&gt;b.Natural merging,&lt;br /&gt;c.Polyphase sort,&lt;br /&gt;d. all the above&lt;br /&gt;Ans: d&lt;br /&gt;&lt;br /&gt;    36.An algorithm is made up of 2 modules M1 and M2.If order of M1 is f(n) and M2 is g(n) then the order of the algorithm is&lt;br /&gt;a.max(f(n),g(n))&lt;br /&gt;b.min(f(n),g(n))&lt;br /&gt;c.f(n)+g(n)&lt;br /&gt;d.f(n)*g(n)&lt;br /&gt;Ans:a&lt;br /&gt;By definition of order,there exists constants c1,c2,n1,n2 such that &lt;br /&gt;T(n)&lt;=c1*f(n),for all n&gt;=n1&lt;br /&gt; T(n)&lt;=c2*g(n),for all n&gt;=n2&lt;br /&gt; Let  N=max(n1,n2)  and C=max(c1,c2),so &lt;br /&gt;T(n)&lt;=c*f(n),for all n&gt;=N&lt;br /&gt;T(n)&lt;=c*g(n),for all n&gt;=N&lt;br /&gt;Adding&lt;br /&gt;T(n)&lt;=c/2 (f(n)+g(n))&lt;br /&gt;Let max(f(n),g(n))=f(n)&lt;br /&gt;T(n)&lt;=c/2 (f(n)+f(n))&lt;=c*f(n)&lt;br /&gt;So order is f(n) which is max(f(n),g(n)) by the assumption.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;      37.The concept of order (Big O) is important because&lt;br /&gt;a.It can be used to decide the best algorithm that solves a given problem&lt;br /&gt;b.It determines the maximum size of a problem that can be solved in a given system in a given amount of time.&lt;br /&gt;c.it is the lower bound of the growth rate of the algorithm&lt;br /&gt;d. a and b&lt;br /&gt;Ans: d&lt;br /&gt;&lt;br /&gt;    38.The running time T(n) where n is the input size of a recursive algorithm is&lt;br /&gt;  T(n)=c+T(n-1),if n&gt;1&lt;br /&gt;            d,if n&lt;=1&lt;br /&gt;   The order of the algorithm is&lt;br /&gt;a.n*n  b.n  c.n^3 d.n^n&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;By recursively applying the relation we can arrive at&lt;br /&gt;T(n-1)=c(n-1)+d&lt;br /&gt;So,order is n&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    39.There are four different algorithms A1,A2,A3 and A4 to solve a given problem with the order  log(n),loglog(n),nlog(n),n/log(n) respectively.Which is the best algorithm?&lt;br /&gt; a. A1     b.A2    c.A3    d.A4&lt;br /&gt;Ans.  b&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   40.The time complexity of an algorithm  T(n),where n is the input size is given by&lt;br /&gt;                T(n)=T(n-1)+1/n,if n&gt;1&lt;br /&gt;                       = 1,otherwise&lt;br /&gt;        The order of this algorithm is&lt;br /&gt;      a. log n      b. n     c. n^2    d. n^n&lt;br /&gt;  Ans.  a&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-5829596697786857569?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/5829596697786857569/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=5829596697786857569' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5829596697786857569'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5829596697786857569'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/sorting-interview-questions-part-2.html' title='Sorting Interview Questions Part 2'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-6974839664351284424</id><published>2007-10-27T10:54:00.000-07:00</published><updated>2007-10-27T10:55:30.457-07:00</updated><title type='text'>Sorting Interview Questions Part 1</title><content type='html'>1.Which of the following algorithms can be used for sorting large data sets based on time complexity?&lt;br /&gt;   a. Bubble sort   b. Merge sort   c. Heap sort    d. Quick sort&lt;br /&gt;Ans:c&lt;br /&gt;Heap sort does not require massive recursion or multiple arrays.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. Which of the following algorithms is the slowest&lt;br /&gt;     a. Bubble sort   b. Merge sort    c. Quick sort   d. Heap sort&lt;br /&gt;Ans:a&lt;br /&gt;The bubble sort works by comparing each item in the list with the item next to it, and swapping them if required. The algorithm repeats this process until it makes a pass all the way through the list without swapping any items&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3.The sorting algorithms belonging to quadratic complexity includes &lt;br /&gt;a. bubble sort   b. insertion sort   c .selection sort   d. All the above&lt;br /&gt;Ans:d&lt;br /&gt;4. The sorting algorithms not having complexity O(n log n)includes&lt;br /&gt;a. heap sort   b. quick sort   c. bubble sort  d.merge sort&lt;br /&gt;Ans: a&lt;br /&gt;&lt;br /&gt;5.An algorithm to find the shortest paths from a single source vertex to all other vertices in a weighted,directed graph.. &lt;br /&gt;a.Dijkstra’s   b.Prim’s  c. Kruskal  d.none of the above&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;6.Time complexity of Dijkstra’s algorithm&lt;br /&gt; a.O(VlogV)  b.O(E+VlogV)   c.O(ElogV)  d.none of the above&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;7.In the time complexity O(E+VlogV)  V is the number of  _____&lt;br /&gt;Ans:vertices &lt;br /&gt;&lt;br /&gt;8.In the time complexity O(E+VlogV)  E is the number of  _____&lt;br /&gt;Ans:edges &lt;br /&gt;&lt;br /&gt;9.In Dijkstra’s algorithm,all weights must be nonnegative(T/F)&lt;br /&gt;Ans:True&lt;br /&gt;&lt;br /&gt;10.A step-by-step problem-solving procedure, especially an established, recursive computational procedure for solving a problem in a finite number of steps is called&lt;br /&gt;a.Structure   b.Queue  c.Algorithm   d.Data structure&lt;br /&gt;Ans:c &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;11.Big O notation is used for&lt;br /&gt;a.Asymptotic upper bound&lt;br /&gt;b. Asymptotic lower bound&lt;br /&gt;c. Tight bound&lt;br /&gt;d.none of these&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;12. θ notation is used for&lt;br /&gt;a.Asymptotic upper bound&lt;br /&gt;b. Asymptotic lower bound&lt;br /&gt;c. Tight bound&lt;br /&gt;d.none of these&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;13.Ω notation is used for&lt;br /&gt;a.Asymptotic upper bound&lt;br /&gt;b. Asymptotic lower bound&lt;br /&gt;c. Tight bound&lt;br /&gt;d.none of these&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;14.For inplace sorting no extra memory is required.(T/F)&lt;br /&gt;    Ans:True&lt;br /&gt;&lt;br /&gt;15.Which of the following do not use inplace sorting&lt;br /&gt;    a.Selection  b.Bubble  c.Insertion  d.Merge&lt;br /&gt;    Ans: d&lt;br /&gt;&lt;br /&gt;16.The operations which directly affect the output of an algorithm are ______&lt;br /&gt;   Ans:Key operations&lt;br /&gt;&lt;br /&gt;17.Number of times a key operation executes is&lt;br /&gt;    a.Complexity  b.Frequency count  c.Time  d.None&lt;br /&gt;  Ans:b&lt;br /&gt;&lt;br /&gt;18.What are the advantages of sorting&lt;br /&gt;   a.Used in algorithms as a key subroutine.&lt;br /&gt;   b.Used for engineering issues.&lt;br /&gt;   c.Both&lt;br /&gt;   d.None&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;19.A sorting technique where some of the records are in auxiliary storage is&lt;br /&gt;a.Internal sorting&lt;br /&gt;b.External sorting&lt;br /&gt;c.inplace sorting&lt;br /&gt;d.Non inplace sorting&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;20.A sorting technique where the records are in main memory is&lt;br /&gt;a.Internal sorting&lt;br /&gt;b.External sorting&lt;br /&gt;c.inplace sorting&lt;br /&gt;d.Non inplace sorting&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;21.Each item in a file is called a record.(T/F)&lt;br /&gt; Ans:True&lt;br /&gt;&lt;br /&gt;22.A sort takes place either on the records themselves or on an auxiliary table of pointers.(T/F)&lt;br /&gt;Ans:True&lt;br /&gt;&lt;br /&gt;23.Suppose the amount of data stored in the records is so large that the overhead involved in moving the actual data is prohibitive,then the auxiliary table of pointers may be used so that these pointers are moved instead of the actual data,this is called _______&lt;br /&gt;Ans:sorting by address&lt;br /&gt;&lt;br /&gt;24.Which of the following is applicable for any constant ‘c’&lt;br /&gt;   a.c=O(1)&lt;br /&gt;  b.c=O(logn)&lt;br /&gt;  c.c=O(nlogn) &lt;br /&gt;  d.c=O(n)&lt;br /&gt;  Ans:a&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-6974839664351284424?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/6974839664351284424/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=6974839664351284424' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/6974839664351284424'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/6974839664351284424'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/sorting-interview-questions-part-1.html' title='Sorting Interview Questions Part 1'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-3546680864760674720</id><published>2007-10-27T10:53:00.000-07:00</published><updated>2007-10-27T10:54:19.661-07:00</updated><title type='text'>Linear Search Interview Questions Part 2</title><content type='html'>23.The average successful search time for sequential search on ‘n’ items is&lt;br /&gt;          a. n/2&lt;br /&gt;          b. (n-1)/2&lt;br /&gt;          c. (n+1)/2&lt;br /&gt;          d. log (n) + 1&lt;br /&gt;     Ans. c&lt;br /&gt;     If the search key matches the very first item, with one comparison we can terminate.If it is second,two comparisons ,etc.So,average is (1+2+3+…+n)/n , i.e.,(n+1)/2&lt;br /&gt;&lt;br /&gt;24. 6 files F1,F2,F3,F4,F5 and F6 have 100,200,50,80,120,150 number of records respectively.In what order should they be stored so as to optimize access time .Assume each file is accessed with the same frequency.&lt;br /&gt;a. F3,F4,F1,F5,F6,F2&lt;br /&gt;b. F2,F6,F5,F1,F4,F3&lt;br /&gt;c. F1,F2,F3,F4,F5,F6&lt;br /&gt;d. Ordering is immaterial as all files are accessed with the same frequency&lt;br /&gt;Ans. a&lt;br /&gt;Since the access is sequential,greater the distance,greater will be the access time.Since all the files are referenced with equal frequency,overall access time can be reduced by arranging them as in option (a).&lt;br /&gt;&lt;br /&gt;25. For small arrays, _____________ is a good solution because it's straightforward.&lt;br /&gt;a. binary search&lt;br /&gt;b. linear search&lt;br /&gt;c. fibonacci search&lt;br /&gt;d. none of the above&lt;br /&gt; Ans. b&lt;br /&gt;&lt;br /&gt;26. If the loop in a linear search finishes without finding a match,the search is failed and _____ is returned.&lt;br /&gt;Ans. -1&lt;br /&gt;    If the loop finishes without finding a match, the search failed and -1 is returned.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;27. What is the output of the following program using linear search&lt;br /&gt;#include &lt;iostream&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int LinearSearch(const int *Array, const int Size, const int ValToSearch)&lt;br /&gt;{&lt;br /&gt; bool NotFound = true;&lt;br /&gt; int i = 0;&lt;br /&gt;&lt;br /&gt; while(i &lt; Size &amp;&amp; NotFound)&lt;br /&gt; {&lt;br /&gt;  if(ValToSearch != Array[i])&lt;br /&gt;   i++;&lt;br /&gt;  else&lt;br /&gt;   NotFound = false;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; if( NotFound == false )&lt;br /&gt;  return i;&lt;br /&gt; else&lt;br /&gt;  return -1;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt; int Number[] = { 67, 278, 463, 2, 4683, 812, 236, 38 };&lt;br /&gt; int Quantity = sizeof(Number) / sizeof(int);&lt;br /&gt; int NumberToSearch = 0;&lt;br /&gt;&lt;br /&gt; cout &lt;&lt; "Enter the number to search: "; cin &gt;&gt; NumberToSearch;&lt;br /&gt; int i = LinearSearch(Number, Quantity, NumberToSearch);&lt;br /&gt;&lt;br /&gt; if(i == -1)&lt;br /&gt;  cout &lt;&lt; NumberToSearch &lt;&lt; " was not found in the collection\n\n";&lt;br /&gt; else&lt;br /&gt; {&lt;br /&gt;  cout &lt;&lt; NumberToSearch &lt;&lt; " is at the " &lt;&lt; i+1;&lt;br /&gt;  if( i == 0 )&lt;br /&gt;   cout&lt;&lt; "st position of the collection\n\n";&lt;br /&gt;  else if( i == 1 )&lt;br /&gt;   cout&lt;&lt; "nd position of the collection\n\n";&lt;br /&gt;  else if( i == 2 )&lt;br /&gt;   cout&lt;&lt; "rd position of the collection\n\n";&lt;br /&gt;  else&lt;br /&gt;   cout&lt;&lt; "th position of the collection\n\n";&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Enter the number to search: 278&lt;br /&gt;a. 278 is at the 1st position of the collection&lt;br /&gt;b. 278 is at the 2nd position of the collection&lt;br /&gt;c. 278 is at the 3rd position of the collection&lt;br /&gt;d. 278 was not found in the collection&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;28.For the above program what is the output for&lt;br /&gt;Enter the number to search: 288&lt;br /&gt;a. 288 is at the 1st position of the collection&lt;br /&gt;b. 288 is at the 2nd position of the collection&lt;br /&gt;c. 288 is at the 3rd position of the collection&lt;br /&gt;d. 288 was not found in the collection&lt;br /&gt;Ans:d&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-3546680864760674720?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/3546680864760674720/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=3546680864760674720' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/3546680864760674720'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/3546680864760674720'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/linear-search-interview-questions-part_27.html' title='Linear Search Interview Questions Part 2'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-1829911129980301319</id><published>2007-10-27T10:52:00.000-07:00</published><updated>2007-10-27T10:53:45.246-07:00</updated><title type='text'>Linear Search Interview Questions Part 1</title><content type='html'>1.The sequential search, also known as the linear search.&lt;br /&gt;&lt;br /&gt;2.Every element in the data set is examined in the order presented until the value being searched for is found, the following technique is called as&lt;br /&gt;a. Binary search.&lt;br /&gt;b. Quick search.&lt;br /&gt;c. Linear search. &lt;br /&gt;d. None of these.&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;3.Best case time complexity of Sequential search is &lt;br /&gt;a. O(1) &lt;br /&gt;b. O(n)&lt;br /&gt;c. O(n×n)&lt;br /&gt;d. None of these.&lt;br /&gt;Ans:a&lt;br /&gt;4.Average case time complexity of Sequential search is &lt;br /&gt;e. O(1)&lt;br /&gt;f. O(n) &lt;br /&gt;g. O(n×n)&lt;br /&gt;h. None of these.&lt;br /&gt;Ans:b&lt;br /&gt;5. Worst case time complexity of Sequential search is &lt;br /&gt;i. O(1)&lt;br /&gt;j. O(n) &lt;br /&gt;k. O(n×n)&lt;br /&gt;l. None of these.&lt;br /&gt;Ans:b&lt;br /&gt;6. Best case time complexity of linear search is &lt;br /&gt;m. O(1) &lt;br /&gt;n. O(n)&lt;br /&gt;o. O(n×n)&lt;br /&gt;p. None of these.&lt;br /&gt;Ans:a&lt;br /&gt;7.Average case time complexity of Linear search is &lt;br /&gt;q. O(1)&lt;br /&gt;r. O(n) &lt;br /&gt;s. O(n×n)&lt;br /&gt;t. None of these.&lt;br /&gt;Ans:b&lt;br /&gt;8.Worst case time complexity of Linear search is &lt;br /&gt;u. O(1)&lt;br /&gt;v. O(n) &lt;br /&gt;w. O(n×n)&lt;br /&gt;x. None of these.&lt;br /&gt;Ans:b&lt;br /&gt;9. Efficiency is usually measured in terms of abstract computations, such as data moves and the memory used. True.&lt;br /&gt;&lt;br /&gt;10.Sorting is the process of putting items in a predetermined order, such as increasing or decreasing order.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;11.The simplest form of search is …&lt;br /&gt;y. Binary search&lt;br /&gt;z. Linear search&lt;br /&gt;aa. Both&lt;br /&gt;bb. None of these&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;12.Linear search is applicable to a table organized in&lt;br /&gt;cc. Array&lt;br /&gt;dd. Linked list&lt;br /&gt;ee. Tree&lt;br /&gt;ff. None of these&lt;br /&gt;Ans:a,b&lt;br /&gt;13.Sequential search is applicable to a table organized in&lt;br /&gt;gg. Array&lt;br /&gt;hh. Linked list&lt;br /&gt;ii. Tree&lt;br /&gt;jj. None of these&lt;br /&gt;kk. Ans:a,b&lt;br /&gt;&lt;br /&gt;14.The algorithm for sequential search is…&lt;br /&gt;ll. for(i=0;i&lt;n;i++)&lt;br /&gt;if (key != k (i))&lt;br /&gt;      return (i);&lt;br /&gt;      return (-1);&lt;br /&gt;mm. for(i=0;i&lt;n;i++)  &lt;br /&gt;if (key == k (i))&lt;br /&gt;      return (i);&lt;br /&gt;      return (-1);&lt;br /&gt;nn. None of these&lt;br /&gt;oo. All of these&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;15.An efficient linear search method involves inserting the argument key at the end of the array before beginning the search, thus guaranteeing that the key will be found. The algorithm for this is …&lt;br /&gt;pp. for(i=0;i&lt;n;i++)&lt;br /&gt;if (key == k (i))&lt;br /&gt;      return (i);&lt;br /&gt;      return (-1);&lt;br /&gt;qq. k(n) = key;    &lt;br /&gt;for (i=0;key != k(i);i++);&lt;br /&gt;if( i&lt;n )&lt;br /&gt;return( i );&lt;br /&gt;else&lt;br /&gt;return (-1);&lt;br /&gt;rr. None of these&lt;br /&gt;ss. All of these&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;16.The efficiency of searching a list is ___________ by adding a sentinel node containing the argument key at the end of the list.&lt;br /&gt;tt. Decreased&lt;br /&gt;uu. Improved  (as the for loop condition is simplified “k(p) != key”)&lt;br /&gt;vv. None of these&lt;br /&gt;ww. All of these&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;17.An efficient linear search method involves inserting the argument key at the end of the array before beginning the search, thus guaranteeing that the key will be found. The extra key inserted at the end of the array is called as &lt;br /&gt;xx. Metical&lt;br /&gt;yy. Sentinel &lt;br /&gt;zz. Ultimo&lt;br /&gt;aaa. All of these&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;18.The sentinel method of linear search requires an…&lt;br /&gt;bbb. Additional external pointer  &lt;br /&gt;ccc. Additional internal pointer&lt;br /&gt;ddd. None of these&lt;br /&gt;eee. All of these&lt;br /&gt;Ans:a&lt;br /&gt;19.Linear search is a kind of  _____________ .&lt;br /&gt;   Ans. search&lt;br /&gt; &lt;br /&gt;20.Transpose sequential search is a kind of ___________&lt;br /&gt;fff. linear search  &lt;br /&gt;ggg. binary search&lt;br /&gt;hhh. sequential search  &lt;br /&gt;iii. none of the above&lt;br /&gt;Ans:a,c&lt;br /&gt;21._______________ is a part of or used in linear search.&lt;br /&gt;Ans. move-to-front heuristic.&lt;br /&gt;&lt;br /&gt;22.______________ is a part of or used in sequential search.&lt;br /&gt;Ans. move-to-front heuristic.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-1829911129980301319?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/1829911129980301319/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=1829911129980301319' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/1829911129980301319'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/1829911129980301319'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/linear-search-interview-questions-part.html' title='Linear Search Interview Questions Part 1'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-2467987374570821809</id><published>2007-10-27T10:51:00.000-07:00</published><updated>2007-10-27T10:52:12.908-07:00</updated><title type='text'>Hashing Interview Question Part 3</title><content type='html'>24. Which of the following are not hash functions?&lt;br /&gt; a. division&lt;br /&gt; b. coupling&lt;br /&gt; c. folding&lt;br /&gt; d. extraction&lt;br /&gt; e. mid square&lt;br /&gt;  Ans. c&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;&lt;br /&gt; 25. The following paragraph is connected with hashing:&lt;br /&gt;The process of mapping large amounts of data into a smaller table is called …… (i) ……. A good hash function should satisfy two criteria, namely quickness to compute and minimisation of the number of   …… (ii) ……. Minimization of …… (iii) …… can be achieved by choosing a hash function that spreads the incoming data as evenly as possible over the hash table.&lt;br /&gt;&lt;br /&gt;Correct terms for the blanks positions are:&lt;br /&gt;(a)  (i) indexing   (ii) collisions    (iii) couplings&lt;br /&gt;(b)  (i) hashing      (ii) collisions    (iii) couplings&lt;br /&gt;(c)  (i) hashing    (ii) collisions     (iii) collisions&lt;br /&gt;(d)  (i) indexing     (ii) collisions    (iii) collisions   &lt;br /&gt;&lt;br /&gt; Ans. c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;26. What is the best definition of a collision in a hash table? &lt;br /&gt;            a. Two entries are identical except for their keys. &lt;br /&gt;            b. Two entries with different data have the exact same key. &lt;br /&gt;            c. Two entries with different keys have the same exact hash value. &lt;br /&gt;            d. Two entries with the exact same key have different hash values. &lt;br /&gt;Ans. c&lt;br /&gt;    27. The phenomenon wherein two keys that hash into different values compete with each other in successive rehashes is called ____________ .&lt;br /&gt;     Ans. primary clustering&lt;br /&gt;   28. ________ is a collision resolution technique that puts all the elements that hash to the same slot in a linked list.&lt;br /&gt;  a. chaining&lt;br /&gt;  b. open addressing&lt;br /&gt;  c. closed addressing&lt;br /&gt;  d. hashing&lt;br /&gt;Ans. a&lt;br /&gt;   29. Given a hash table T with m slots that stores n elements,the load factor  is&lt;br /&gt;a. α = m*n&lt;br /&gt;b. α = n/m&lt;br /&gt;c. α = m+n&lt;br /&gt;d. α = m/n&lt;br /&gt;Ans. b&lt;br /&gt;30. If a hash table in which collision are resolved by chaining, a successful search takes ______ time on the average, under the assumption of simple uniform hashing.&lt;br /&gt;a. Q(1+a)&lt;br /&gt;b. θ(1+α)&lt;br /&gt;c. Ω(1+α)&lt;br /&gt;d. O(1+α)&lt;br /&gt;Ans. a&lt;br /&gt;31. Inserting an element into an open-address hash table with load factor a requires at most ______ probes on average, assuming uniform hashing.&lt;br /&gt;a. 1/(1+α)&lt;br /&gt;b. 1/(1-α)&lt;br /&gt;c. 1+α&lt;br /&gt;d. 1/α&lt;br /&gt;Ans. b&lt;br /&gt;&lt;br /&gt;32. One of the collision resolution techniques and the methods used is open addressing include __________ .&lt;br /&gt;     Ans. Overflow block&lt;br /&gt;&lt;br /&gt;   33. The collision resolution techniques and methods used in closed addressing include&lt;br /&gt;         i)linked list&lt;br /&gt;         ii) binary tree&lt;br /&gt;        iii) overflow block&lt;br /&gt;        The correct options are&lt;br /&gt;a. i  and ii only&lt;br /&gt;b. i only&lt;br /&gt;c. ii only&lt;br /&gt;d. i,ii and iii only&lt;br /&gt;Ans. a&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-2467987374570821809?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/2467987374570821809/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=2467987374570821809' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2467987374570821809'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2467987374570821809'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/hashing-interview-question-part-3.html' title='Hashing Interview Question Part 3'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-4948125501267416073</id><published>2007-10-27T10:50:00.000-07:00</published><updated>2007-10-27T10:51:03.260-07:00</updated><title type='text'>Hashing Interview Question Part 2</title><content type='html'>11. A hash table that grows to handle more items is called&lt;br /&gt;a.optimal hashing&lt;br /&gt;b.dynamic hashing&lt;br /&gt;c.minimal perfect hashing&lt;br /&gt;d.none&lt;br /&gt;Ans:b&lt;br /&gt;12. The associated hash function must change as the table grows in dynamic hashing.(T/F)&lt;br /&gt;Ans:True&lt;br /&gt;13. A hash table in which the hash function is the last few bits of the key and the table refers to buckets is called&lt;br /&gt;a.optimal hashing&lt;br /&gt;b.dynamic hashing&lt;br /&gt;c.minimal perfect hashing&lt;br /&gt;d.Extendible hashing&lt;br /&gt;Ans:d&lt;br /&gt;14. A dynamic hashing table that grows one slot at a time is called&lt;br /&gt;a.linear hashing&lt;br /&gt;b.dynamic hashing&lt;br /&gt;c.minimal perfect hashing&lt;br /&gt;d.Extendible hashing&lt;br /&gt;Ans:a&lt;br /&gt;15.Linear hashing is also known as &lt;br /&gt;a.Decremental hashing&lt;br /&gt;b.Incremental hashing&lt;br /&gt;c.Extendible hashing&lt;br /&gt;d.none&lt;br /&gt;Ans:b&lt;br /&gt;16. A dictionary implemented with two hash tables of equal size, T1 and T2, and two different hash functions, h1 and h2.&lt;br /&gt;a.optimal hashing&lt;br /&gt;b.dynamic hashing&lt;br /&gt;c.minimal perfect hashing&lt;br /&gt;d.2-left hashing&lt;br /&gt;Ans:d&lt;br /&gt;17. A variant of a hash table in which keys are added by hashing with two hash functions is called&lt;br /&gt;a.optimal hashing&lt;br /&gt;b.2-choice hashing&lt;br /&gt;c.minimal perfect hashing&lt;br /&gt;d.2-left hashing&lt;br /&gt;Ans:b&lt;br /&gt;18. The average-case cost of a successful search is__________ for 2-choice hashing where m is the number of keys and n is the size of the array&lt;br /&gt;a. O(2 + (m-1)/n)&lt;br /&gt;b.O(1+(m-1)/n)&lt;br /&gt;c.O(3+(m-1)/n)&lt;br /&gt;d.none&lt;br /&gt;Ans:a&lt;br /&gt;19. A conceptual method of open addressing for a hash table is called&lt;br /&gt;a.Universal hashing&lt;br /&gt;b.Uniform hashing&lt;br /&gt;c.Optimal hashing&lt;br /&gt;d.none&lt;br /&gt;Ans:b&lt;br /&gt;20. The assumption or goal that items are equally likely to hash to any value is called&lt;br /&gt;a.Simple uniform hashing&lt;br /&gt;b.Uniform hashing&lt;br /&gt;c.Optimal hashing&lt;br /&gt;d.none&lt;br /&gt;Ans:a&lt;br /&gt;21. A method of open addressing for a hash table in which a collision is resolved by searching the table for an empty place at intervals given by a different hash function, thus minimizing clustering is called &lt;br /&gt;a.double hashing&lt;br /&gt;b.Uniform hashing&lt;br /&gt;c.Optimal hashing&lt;br /&gt;d.none&lt;br /&gt;Ans:a&lt;br /&gt;22.Double hashing is also known as rehashing(T/F)&lt;br /&gt;Ans:True&lt;br /&gt;23. A scheme that chooses randomly from a set of hash functions is called&lt;br /&gt;a.double hashing&lt;br /&gt;b.Uniform hashing&lt;br /&gt;c.Optimal hashing&lt;br /&gt;d.universal hashing&lt;br /&gt;Ans:d&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-4948125501267416073?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/4948125501267416073/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=4948125501267416073' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4948125501267416073'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4948125501267416073'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/hashing-interview-question-part-2.html' title='Hashing Interview Question Part 2'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-1391785728997962779</id><published>2007-10-27T10:48:00.002-07:00</published><updated>2007-10-27T10:50:17.615-07:00</updated><title type='text'>Hashing Interview Question Part 1</title><content type='html'>1. A function that maps keys to integers, usually to get an even distribution on a smaller set of values is called ______&lt;br /&gt;Ans: Hash function&lt;br /&gt;2. A dictionary in which keys are mapped to array positions by hash functions is called&lt;br /&gt;a.hash table&lt;br /&gt;b.view table&lt;br /&gt;c.Both&lt;br /&gt;d.none&lt;br /&gt;Ans:a&lt;br /&gt;3.A hash function f defined as f(key) = key mod 7, with linear probing, is used to insert the keys 37,38,72,48,98,11,56,into a table indexed from 0 to 6. 11 will be stored in the location&lt;br /&gt;a.3  b.4  c.5   d.6&lt;br /&gt;Ans:c&lt;br /&gt;f(37)=37  mod 7 =2.&lt;br /&gt;So,37 will be put in location 2.f(38)=3.&lt;br /&gt;So,38 will be in third location.&lt;br /&gt;F(72)=2. This results in a collision. With linear probing as the collision resolving strategy, the alternate location for 72 will be the location 4. Continuing this way, the final configuration will be 98,56,37,38,72,11,48. &lt;br /&gt;Hence the answer.&lt;br /&gt;&lt;br /&gt;4. Having the keys of more than one item map to the same position is called a __________&lt;br /&gt;Ans: collision.&lt;br /&gt;5. A hash function that maps each different key to a distinct integer is called&lt;br /&gt;a.perfect hashing&lt;br /&gt;b.internal hashing&lt;br /&gt;c.external hashing&lt;br /&gt;d.none&lt;br /&gt;Ans:a&lt;br /&gt;6. Usually all possible keys must be known beforehand in perfect hashing.(T/F)&lt;br /&gt;Ans:True&lt;br /&gt;7. A hash table that uses a perfect hash has &lt;br /&gt;a. 1 collision&lt;br /&gt;b.no collisions&lt;br /&gt;c.Multiple collisions&lt;br /&gt;d.none&lt;br /&gt;Ans:b&lt;br /&gt;8.Perfect hashing is also called &lt;br /&gt;a.optimal hashing&lt;br /&gt;b.dynamic hashing&lt;br /&gt;c.cuckoo hashing&lt;br /&gt;d.none&lt;br /&gt;Ans:a&lt;br /&gt;9. A perfect hashing function that maps each different key to a distinct integer and has the same number of possible integers as keys is called&lt;br /&gt;a.optimal hashing&lt;br /&gt;b.dynamic hashing&lt;br /&gt;c.minimal perfect hashing&lt;br /&gt;d.none&lt;br /&gt;Ans:c&lt;br /&gt;10. A minimal perfect hashing function for keys in S such that if k1, k2 ∈ S and k1 &gt; k2, then f(k1) &gt; f(k2) is called ____&lt;br /&gt;Ans:Order preserving minimal perfect hashing&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-1391785728997962779?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/1391785728997962779/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=1391785728997962779' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/1391785728997962779'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/1391785728997962779'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/hashing-interview-question-part-1.html' title='Hashing Interview Question Part 1'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-8496223887624118547</id><published>2007-10-27T10:48:00.001-07:00</published><updated>2007-10-27T10:48:39.439-07:00</updated><title type='text'>Greedy Strategy Interview Question Part 5</title><content type='html'>44. The minimum spanning tree of a graph give the shortest distance between any 2 specified nodes.(True or False)&lt;br /&gt;Ans. False&lt;br /&gt; Minimal spanning tree assures that the total weight of the tree is kept at its minimum. But it doesn’t mean that the distance between any two nodes involved in the minimum-spanning tree is minimum.&lt;br /&gt;&lt;br /&gt;45. Dijkstra’s algorithm solves the _____________ shortest path problem.&lt;br /&gt;Ans. single- source&lt;br /&gt;&lt;br /&gt;46. The time required to run Dijkstra’s algorithm is ___________&lt;br /&gt;a. O( ElogV)&lt;br /&gt;b. O( |E| logV)&lt;br /&gt;c. O( |E| log |V| )&lt;br /&gt;d. O( log V)&lt;br /&gt;Ans. c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;47. Dijkstra algorithm finds the shortest path from a source to all the other nodes in a&lt;br /&gt;weighted graph. Can you use Dijksta algorithm to find the shortest path from a source&lt;br /&gt;node to all the other nodes in non-weighted graph?&lt;br /&gt;a) No, because I wouldn’t know which edge to include in the cloud at each step&lt;br /&gt;b) Yes, I could associate weight 0 to each edge and apply Dijkstra&lt;br /&gt;c) No, because I wouldn’t be able to label the nodes&lt;br /&gt;d) Yes, I could associate weight 1 to each edge and apply Dijkstra ***&lt;br /&gt;e) None of the above&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;48. Suppose I want to find a spanning tree of a ring graph (see an example of ring graph&lt;br /&gt;below) represented by an adjacency list. Can I use a BFS traversal? What would be the&lt;br /&gt;complexity of BFS traversal as a function of n (number of nodes)?&lt;br /&gt;a) yes, for a ring with n nodes the complexity would be always O(n) ***&lt;br /&gt;b) yes, for a ring with n nodes the complexity would be always O(n2)&lt;br /&gt;c) yes, for a ring with n nodes the complexity would be O(n2) in the worst case&lt;br /&gt;d) yes, for a ring with n nodes the complexity would be O(n log n)&lt;br /&gt;e) no, BFS is an algorithm to visit the nodes, not to construct a spanning tree. I could use&lt;br /&gt;Prim to construct a spanning tree&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;49. What would be the complexity of Prim algorithm on a graph with n nodes and m&lt;br /&gt;edges, if the priority queue is implemented with a sorted sequence based on an array.&lt;br /&gt;a) O(n2+ n)&lt;br /&gt;b) O(n2 + m)&lt;br /&gt;c) O( n + mn) &lt;br /&gt;d) O( n + n2)&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;50. You are given the following graph. If you use Dijkstra algorithm from node v you&lt;br /&gt;will obtain a shortest path spanning tree from v. Which of the following algorithms&lt;br /&gt;could also create a shortest path spanning tree starting from node v?&lt;br /&gt;a) DFS and BFS&lt;br /&gt;b) Prim and BFS&lt;br /&gt;c) BFS only&lt;br /&gt;d) DFS only&lt;br /&gt;Ans:b&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-8496223887624118547?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/8496223887624118547/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=8496223887624118547' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/8496223887624118547'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/8496223887624118547'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/greedy-strategy-interview-question-part_5708.html' title='Greedy Strategy Interview Question Part 5'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-6929828317926498834</id><published>2007-10-27T10:47:00.001-07:00</published><updated>2007-10-27T10:47:56.471-07:00</updated><title type='text'>Greedy Strategy Interview Question Part 4</title><content type='html'>32.     Lossless compression refers to&lt;br /&gt;a. data that can be uncompressed exactly as it was before compression&lt;br /&gt;b. Huffman coding&lt;br /&gt;c. The assumption that data need not be stored perfectly&lt;br /&gt;d. a and b&lt;br /&gt;     Ans.     d&lt;br /&gt;                Huffman coding is an example of lossless compression wherein the characters are converted into a binary code such that the original text can be retrieved as it was.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;33. State whether the following statement is true or false&lt;br /&gt;       The basic idea in Huffman coding is to assign short codewords to those input blocks with low probabilities and long codewords to those with high probabilities. &lt;br /&gt;Ans.  False&lt;br /&gt;       The basic idea in Huffman coding is to assign short codewords to those input blocks with high probabilities and long codewords to those with low probabilities.&lt;br /&gt;&lt;br /&gt;        34.       Dijkstra’s Algorithm determines&lt;br /&gt;a.        Shortest Path between every pair of vertices&lt;br /&gt;b.       Paths between every pair of vertices&lt;br /&gt;c.        Paths between every pair of vertices&lt;br /&gt;d.       Shortest path only between a given source and multiple destinations&lt;br /&gt;               Ans.   d&lt;br /&gt;&lt;br /&gt;       35.       Which is an example of a minimum spanning tree algorithm?&lt;br /&gt;a.        Kruskal's&lt;br /&gt;b.       Huffman&lt;br /&gt;c.        Euler's&lt;br /&gt;d.       Fibonacci&lt;br /&gt;              Ans. a&lt;br /&gt;&lt;br /&gt;     36..     Kruskal's Algorithm can be solved on the Bases of __________.&lt;br /&gt;a.        Cost&lt;br /&gt;b.       Nodes&lt;br /&gt;c.        Edges&lt;br /&gt;d.       Tree&lt;br /&gt;              Ans.  a&lt;br /&gt;&lt;br /&gt;        37.  Huffman code is a &lt;br /&gt;a. fixed-to-variable length code&lt;br /&gt;b. variable-to-fixed length code&lt;br /&gt;c. variable-to-variable length code&lt;br /&gt;d. fixed-to-fixed length code&lt;br /&gt;              Ans.  a&lt;br /&gt;       &lt;br /&gt;        38. An edge of a spanning tree is called a ________&lt;br /&gt;        Ans. branch&lt;br /&gt;&lt;br /&gt;        39. An edge in the graph that is not in the spanning tree is called a ________&lt;br /&gt;               a. tree&lt;br /&gt;               b. branch&lt;br /&gt;               c. chord&lt;br /&gt;               d. root&lt;br /&gt;         Ans. c&lt;br /&gt;&lt;br /&gt;       40.  Spanning trees are important because of following reasons.&lt;br /&gt;i)Spanning trees construct a sparse sub graph that tells a lot about the original graph.&lt;br /&gt;ii)Spanning trees a very important in designing efficient routing algorithms. &lt;br /&gt;iii)Some hard problems (e.g., Steiner tree problem and traveling salesman problem) can be solved approximately by using spanning trees. &lt;br /&gt;iv)Spanning trees have wide applications in many areas, such as network design, etc. Which of the following options are correct?&lt;br /&gt;a. i,ii and  iii&lt;br /&gt;b. i and iii&lt;br /&gt;c. all the above&lt;br /&gt;d. ii and iv&lt;br /&gt;Ans.  c&lt;br /&gt;41. A minimum spanning tree is a graph that has the following properties:&lt;br /&gt;    ● it spans the graph&lt;br /&gt;    ● it is a minimum&lt;br /&gt;State whether the above statement is true or false.&lt;br /&gt;Ans. True&lt;br /&gt;42. Which of the following algorithms solves the all-pair shortest path problem?&lt;br /&gt;a. Dijkstra’s algorithm&lt;br /&gt;b. Floyd’s algorithm&lt;br /&gt;c. Prim’s algorithm&lt;br /&gt;d. Warshall’s algorithm&lt;br /&gt; Ans. b&lt;br /&gt;Dijkstra’s algorithm solves single source shortest path problem.Warshall’s algorithm finds transitive closure of a given graph.Prim’s algorithm constructs a minimum cost spanning tree for a given weighted graph&lt;br /&gt;43. In kruskal’s algorithm &lt;br /&gt;i)the selection function chooses edges in increasing order of their length&lt;br /&gt;ii)cycle has to be formed&lt;br /&gt;iii)result is a forest of trees that grows until all the trees merge into one.&lt;br /&gt;The correct options are&lt;br /&gt;a. i  and ii&lt;br /&gt;b. i,ii and iii&lt;br /&gt;c. i and iii&lt;br /&gt;d. ii and iii&lt;br /&gt;Ans. c&lt;br /&gt;In kruskal's algorithm the selection function chooses edges in increasing order of length without worrying too much about their connection to previously chosen edges, except that never to form a cycle. The result is a forest of trees that grows until all the trees in a forest (all the components) merge in a single tree&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-6929828317926498834?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/6929828317926498834/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=6929828317926498834' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/6929828317926498834'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/6929828317926498834'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/greedy-strategy-interview-question-part_9763.html' title='Greedy Strategy Interview Question Part 4'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-3441441753888060889</id><published>2007-10-27T10:46:00.000-07:00</published><updated>2007-10-27T10:47:07.402-07:00</updated><title type='text'>Greedy Strategy Interview Question Part 3</title><content type='html'>23. ___________ is to be sent with Huffman code for its decompression.&lt;br /&gt;a. Original string&lt;br /&gt;b. only tree&lt;br /&gt;c. Only frequent occurring characters&lt;br /&gt;d. Coded string&lt;br /&gt;Ans. d&lt;br /&gt;24. In Huffman coding,the code with highest frequency character contains _________  bit(s).&lt;br /&gt;a. Maximum &lt;br /&gt;b. Minimum&lt;br /&gt;c. One&lt;br /&gt;d. Equal&lt;br /&gt;Ans. b&lt;br /&gt;25. Greedy algorithms are&lt;br /&gt;a. simple and straightforward&lt;br /&gt;b. longsighted in approach&lt;br /&gt;     c. many problems can be solved correctly by greedy approach&lt;br /&gt;  d. all of the above&lt;br /&gt;Ans. a&lt;br /&gt;Greedy algorithms are simple and straightforward. They are shortsighted in their approach in the sense that they take decisions on the basis of information at hand without worrying about the effect these decisions may have in the future. They are easy to invent, easy to implement and most of the time quite efficient. Many problems cannot be solved correctly by greedy approach. Greedy algorithms are used to solve optimization problems&lt;br /&gt;26. To construct the solution in an optimal way,Greedy algorithm maintains two sets. One contains ___________ and the other contains ___________ .&lt;br /&gt;Ans. chosen items and rejected items .&lt;br /&gt;  27. The greedy algorithm consists of following functions.&lt;br /&gt;1. A function that checks whether chosen set of items provide a solution. &lt;br /&gt;2. A function that checks the feasibility of a set. &lt;br /&gt;3. The selection function tells which of the candidates is the most promising. &lt;br /&gt;4. An objective function, which does not appear explicitly, gives the value of a solution. &lt;br /&gt;The correct options are&lt;br /&gt;a. 1 and 2&lt;br /&gt;b. 2 and 4&lt;br /&gt;c. 1,2 and 3&lt;br /&gt;d. All the above&lt;br /&gt;Ans. d&lt;br /&gt;  The greedy algorithm consists of four (4) function.&lt;br /&gt;1. A function that checks whether chosen set of items provide a solution. &lt;br /&gt;2. A function that checks the feasibility of a set. &lt;br /&gt;3. The selection function tells which of the candidates is the most promising. &lt;br /&gt;4. An objective function, which does not appear explicitly, gives the value of a solution. &lt;br /&gt;&lt;br /&gt;28. The ____________ and _________________ are two ingredients in the problem that lend to a greedy strategy .&lt;br /&gt;Ans. Greedy-choice property and optimal substructure.&lt;br /&gt;The "greedy-choice property" and "optimal substructure" are two ingredients in the problem that lend to a greedy strategy.&lt;br /&gt;29. A greedy strategy usually progresses in a _____________, making one greedy choice after another.&lt;br /&gt;a. bottom-up fashion&lt;br /&gt;b. linear fashion&lt;br /&gt;c. top-down fashion&lt;br /&gt;d. none of the above&lt;br /&gt;Ans. c&lt;br /&gt;A greedy strategy usually progresses in a top-down fashion, making one greedy choice after another, reducing each problem to a smaller one.&lt;br /&gt;     30. Greedy-Choice Property says that a globally optimal solution can be arrived                        at by making a ________ optimal choice.&lt;br /&gt;       Ans. locally&lt;br /&gt;    Greedy-Choice Property says that a globally optimal solution can be arrived at by                   making a locally optimal choice .&lt;br /&gt;     31. A spanning tree of a graph is any tree that includes every ________  in the graph.&lt;br /&gt;    Ans. vertex&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-3441441753888060889?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/3441441753888060889/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=3441441753888060889' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/3441441753888060889'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/3441441753888060889'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/greedy-strategy-interview-question-part_6850.html' title='Greedy Strategy Interview Question Part 3'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-7135153648596454997</id><published>2007-10-27T10:45:00.000-07:00</published><updated>2007-10-27T10:46:00.640-07:00</updated><title type='text'>Greedy Strategy Interview Question Part 2</title><content type='html'>11. Lossless encoding techniques include&lt;br /&gt;    i) Run length encoding&lt;br /&gt;   ii) Huffman encoding&lt;br /&gt;  iii) Transform coding&lt;br /&gt;The correct option is&lt;br /&gt;a. i&lt;br /&gt;b. i  and ii&lt;br /&gt;c. all of the above&lt;br /&gt;d. only ii&lt;br /&gt;Ans. b&lt;br /&gt;12. Disjoint sets are __________ sets.&lt;br /&gt;Ans. mutually exclusive/independent&lt;br /&gt;13. The disjoint set is an abstract data type that supports ___________ and _________ operations.&lt;br /&gt;Ans. Union and find&lt;br /&gt;14. Union(x,y) is an operation in disjoint set which means merge the set containing x with the set containing y. (True or False)&lt;br /&gt;Ans. True&lt;br /&gt;15.Find(x) should return some representation of the set containing x. (True or False)&lt;br /&gt;Ans. True&lt;br /&gt;16.Running time of find(i) is proportional to the _________of the tree containing node i.&lt;br /&gt;Ans. height&lt;br /&gt;17. Minimum spanning tree gives shortest distance between&lt;br /&gt;a. any two nodes&lt;br /&gt;b. source and destination&lt;br /&gt;c. source and any node&lt;br /&gt;d. none&lt;br /&gt;Ans. b&lt;br /&gt;In minimum spanning tree,we get the shortest path between the source and the destination.&lt;br /&gt;18. The shortest path algorithm gives minimum distance between&lt;br /&gt;a. any two nodes&lt;br /&gt;b. source and destination&lt;br /&gt;c. all of the above&lt;br /&gt;d. source and any node&lt;br /&gt;Ans. a&lt;br /&gt;19. The cost of a path between two vertices is the sum of the _________ of the edges in that path.&lt;br /&gt;Ans. costs&lt;br /&gt;20. Huffman’s coding technique uses ____________ algorithm.&lt;br /&gt;Ans. Greedy algorithm&lt;br /&gt;21. Huffman coding uses __________&lt;br /&gt;a. tree&lt;br /&gt;b. graph&lt;br /&gt;c. linked list&lt;br /&gt;d. stack&lt;br /&gt;Ans. a&lt;br /&gt;22. The data structure used for the implementation of Kruskal’s algorithm is&lt;br /&gt;a. Graph&lt;br /&gt;b. Linked list&lt;br /&gt;c. stack&lt;br /&gt;d. disjoint set&lt;br /&gt;Ans. d&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-7135153648596454997?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/7135153648596454997/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=7135153648596454997' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7135153648596454997'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7135153648596454997'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/greedy-strategy-interview-question-part_27.html' title='Greedy Strategy Interview Question Part 2'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-2186081890131338415</id><published>2007-10-27T10:43:00.000-07:00</published><updated>2007-10-27T10:45:05.359-07:00</updated><title type='text'>Greedy Strategy Interview Question Part 1</title><content type='html'>1. Huffman’s greedy algorithm&lt;br /&gt;a  is a lossy compression technique&lt;br /&gt;b. computes frequency of occurrence of characters&lt;br /&gt;c. assigns binary codes to a string of characters&lt;br /&gt;d. b and c&lt;br /&gt;Ans.  d&lt;br /&gt;&lt;br /&gt;2. Huffman’s greedy algorithm has a total running time of&lt;br /&gt;a. O(log n)&lt;br /&gt;b.O(n)&lt;br /&gt;c. O(nlogn)&lt;br /&gt;d. O(n*n)&lt;br /&gt;Ans. c&lt;br /&gt;&lt;br /&gt;3. Greedy algorithms are used for&lt;br /&gt;i)optimization problems&lt;br /&gt;ii)always make a locally optimal choice&lt;br /&gt;iii)widely applied:Dijkstra’s algorithm and MST&lt;br /&gt;The correct options are&lt;br /&gt;a)i and ii&lt;br /&gt;b)i and iii&lt;br /&gt;c)all of the above&lt;br /&gt;d)only i&lt;br /&gt;Ans. c&lt;br /&gt;4. A graph may have ________ number of spanning trees.&lt;br /&gt;Ans. many&lt;br /&gt;5. Kruskal’s algorithm is also known as _________ algorithm.&lt;br /&gt;Ans. Greedy algorithm&lt;br /&gt;6. Kruskal’s algorithm works faster on sparse graphs.( True or False).&lt;br /&gt;Ans. True&lt;br /&gt;7. Every spanning tree on n points contains exactly &lt;br /&gt;a. n edges&lt;br /&gt;b. n-1 edges&lt;br /&gt;c. n(n-1) edges&lt;br /&gt;d. n-2 edges&lt;br /&gt;Ans . b&lt;br /&gt;8. the time required by Kruskal’s algorithm is  _______ where E stands for edges and V for vertices&lt;br /&gt;a. O( |E| + log |V| )&lt;br /&gt;b. O( ElogV)&lt;br /&gt;c. O( |E|log|V| )&lt;br /&gt;d. O( log |V| )&lt;br /&gt;Ans.  c&lt;br /&gt;9. A minimum spanning tree is a minimum-weight tree in a ________ graph which contains all of the graph’s vertices.&lt;br /&gt;Ans. weighted&lt;br /&gt;10. Travelling salesman problem can be best solved by using a&lt;br /&gt;a. Minimum spanning tree algorithm&lt;br /&gt;b. Dijkstra algorithm&lt;br /&gt;c. Floyd algorithm&lt;br /&gt;d. None of the above&lt;br /&gt;Ans. a&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-2186081890131338415?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/2186081890131338415/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=2186081890131338415' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2186081890131338415'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2186081890131338415'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/greedy-strategy-interview-question-part.html' title='Greedy Strategy Interview Question Part 1'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-8898179083552534656</id><published>2007-10-27T10:42:00.002-07:00</published><updated>2007-10-27T10:43:30.378-07:00</updated><title type='text'>Selection Sort Interview Question Part 3</title><content type='html'>27. What is the output of selection sort for the following numbers after the 8th pass?&lt;br /&gt;3 6 9 2 7 10 1 5 8 4&lt;br /&gt;a. 1 2 3 4 5 6 10 9 8 7&lt;br /&gt;b. 1 2 3 4 5 6 7 9 8 10&lt;br /&gt;c.1 2 3 4 5 6 7 8 9 10&lt;br /&gt;d. 1 2 3 4 7 10 9 6 8 5&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;28. What is the output of selection sort for the following numbers after the 9th pass?&lt;br /&gt;3 6 9 2 7 10 1 5 8 4&lt;br /&gt;a. 1 2 3 4 5 6 10 9 8 7&lt;br /&gt;b. 1 2 3 4 5 6 7 9 8 10&lt;br /&gt;c.1 2 3 4 5 6 7 8 9 10&lt;br /&gt;d. 1 2 3 4 7 10 9 6 8 5&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;29. What is the output of selection sort after the 1st pass given the following sequence of numbers: 7 3 5 1 9 8 4 6&lt;br /&gt;a. 1 7 5 3 9 8 4 6&lt;br /&gt;b. 1 3 7 5 9 8 4 6&lt;br /&gt;c. 1 3 4 7 9 8 5 6&lt;br /&gt;d. 1 3 4 5 9 8 7 6&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;30. What is the output of selection sort after the 2nd pass given the following sequence of numbers: 7 3 5 1 9 8 4 6&lt;br /&gt;a. 1 7 5 3 9 8 4 6&lt;br /&gt;b. 1 3 7 5 9 8 4 6&lt;br /&gt;c. 1 3 4 7 9 8 5 6&lt;br /&gt;d. 1 3 4 5 9 8 7 6&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;31. What is the output of selection sort after the 3rd pass given the following sequence of numbers: 7 3 5 1 9 8 4 6&lt;br /&gt;a. 1 7 5 3 9 8 4 6&lt;br /&gt;b. 1 3 7 5 9 8 4 6&lt;br /&gt;c. 1 3 4 7 9 8 5 6&lt;br /&gt;d. 1 3 4 5 9 8 7 6&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;32. What is the output of selection sort after the 4th pass given the following sequence of numbers: 7 3 5 1 9 8 4 6&lt;br /&gt;a. 1 7 5 3 9 8 4 6&lt;br /&gt;b. 1 3 7 5 9 8 4 6&lt;br /&gt;c. 1 3 4 7 9 8 5 6&lt;br /&gt;d. 1 3 4 5 9 8 7 6&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;33. What is the output of selection sort after the 5th pass given the following sequence of numbers: 7 3 5 1 9 8 4 6&lt;br /&gt;a. 1 7 5 3 9 8 4 6&lt;br /&gt;b. 1 3 7 5 9 8 4 6&lt;br /&gt;c. 1 3 4 7 9 8 5 6&lt;br /&gt;d. 1 3 4 5 6 8 7 9&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;34. What is the output of selection sort after the 6th pass given the following sequence of numbers: 7 3 5 1 9 8 4 6&lt;br /&gt;a. 1 3 4 5 6 7 8 9&lt;br /&gt;b. 1 3 7 5 9 8 4 6&lt;br /&gt;c. 1 3 4 7 9 8 5 6&lt;br /&gt;d. 1 3 4 5 9 8 7 6&lt;br /&gt;Ans:a&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-8898179083552534656?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/8898179083552534656/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=8898179083552534656' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/8898179083552534656'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/8898179083552534656'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/selection-sort-interview-question-part_174.html' title='Selection Sort Interview Question Part 3'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-2348639176417742281</id><published>2007-10-27T10:42:00.001-07:00</published><updated>2007-10-27T10:42:40.002-07:00</updated><title type='text'>Selection Sort Interview Question Part 2</title><content type='html'>14.The efficiency of selection sort is&lt;br /&gt;a.n*(n/2)&lt;br /&gt;b.n*n&lt;br /&gt;c.n(n-1)/2&lt;br /&gt;d.none&lt;br /&gt;Ans:a&lt;br /&gt; The first loop goes from 0 to n, and the second loop goes from x to n, so it goes from 0 to n, then from 1 to n, then from 2 to n and so on. The multiplication works out so that the efficiency is n*(n/2), though the order is still O(n^2).&lt;br /&gt;15.The frequency count of selection sort is&lt;br /&gt;  a.n*n&lt;br /&gt;  b.n(n-1)/2&lt;br /&gt;  c.n&lt;br /&gt;  d.logn&lt;br /&gt;Ans:b&lt;br /&gt;(n-1)+(n-2)+……+3+2+1=n(n+1)/2 – n =n(n-1)/2&lt;br /&gt;&lt;br /&gt;16.The total number of iterations in selection sort is&lt;br /&gt;a.n-1&lt;br /&gt;b.n&lt;br /&gt;c.n*n&lt;br /&gt;d.2*n&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;17. For a List with L elements numbered from 0 to L-1 , the selection sort algorithm is&lt;br /&gt;&lt;br /&gt;Set marker to L-1 (begin with the last element in the list)&lt;br /&gt;While marker&gt;0&lt;br /&gt;Find the largest element in the range numbered from 0 to marker.&lt;br /&gt;Swap that element with the element at location marker.&lt;br /&gt;Increase marker back by 1&lt;br /&gt;Assume the initial list is 3, 9, 1,7 ,2&lt;br /&gt;&lt;br /&gt;What are the correct intermediate output values during the process of sorting?&lt;br /&gt;a.3, 2, 1, 7, 9&lt;br /&gt;b.3, 9, 1, 2, 7&lt;br /&gt;c.1, 2, 3, 7, 9&lt;br /&gt;d.9, 3, 1, 2, 7&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;18. Consider the following selection sort algorithm and the integer data set given thereafter.&lt;br /&gt;For a list with L elements numbered from 0 to L-1, the selection sort algorithms is :&lt;br /&gt;1. Set marker to L-1 (beginning with the last element in the list)&lt;br /&gt;2. While marker &gt;0 ;&lt;br /&gt;i. Find the largest element in the range numbered from 0 to marker.&lt;br /&gt;ii. Swap the largest element with the element at the location marker.&lt;br /&gt;iii. Increase marker back by 1&lt;br /&gt;Data set: { 4 10 2 8 3 }&lt;br /&gt;If the above algorithm works on the given data set , what would not be the pair of swapping values during the&lt;br /&gt;process of sorting?&lt;br /&gt;(a) (3,10)  (b) (4,2)  (c) (2,3)  (d) (10,2)    &lt;br /&gt;Ans: d&lt;br /&gt;&lt;br /&gt;19. Let there be a list with L elements numbered from 0 to L-1, and consider the following algorithm:&lt;br /&gt;&lt;br /&gt;Step 1: set marker1 to L-1 (begin with the location of the last element in the list)&lt;br /&gt;Step 2: While marker &gt; 0&lt;br /&gt;Step 3: find the largest element in the range numbered from 0 to marker&lt;br /&gt;Step 4: swap that element with the element at location marker.&lt;br /&gt;Step 5: Increase marker by 1&lt;br /&gt;The above algorithm describes&lt;br /&gt;(a) Bubble sort. (b) Selection sort. (c) Insertion sort. (d)Merge sort&lt;br /&gt;Ans:b&lt;br /&gt;20.What is the output of selection sort for the following numbers after the first pass?&lt;br /&gt;3 6 9 2 7 10 1 5 8 4&lt;br /&gt;a. 1 6 9 3 7 10 2 5 4 8&lt;br /&gt;b. 1 6 9 3 7 2 10 5 8 4&lt;br /&gt;c.1 6 9 3 7 10 2 5 8 4&lt;br /&gt;d. 1 6 9 7 3 10 2 5 8 4&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;21. What is the output of selection sort for the following numbers after the 2nd pass?&lt;br /&gt;3 6 9 2 7 10 1 5 8 4&lt;br /&gt;a. 1 6 9 3 7 10 2 5 4 8&lt;br /&gt;b. 1 2 9 6 7 10 3 5 8 4&lt;br /&gt;c.1 6 9 3 7 10 2 5 8 4&lt;br /&gt;d. 1 2 6 9 7 10 3 5 8 4&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;22. What is the output of selection sort for the following numbers after the 3rd pass?&lt;br /&gt;3 6 9 2 7 10 1 5 8 4&lt;br /&gt;a. 1 2 3 6 7 10 9 5 8 4&lt;br /&gt;b. 1 2 9 6 7 10 3 5 8 4&lt;br /&gt;c.1 6 9 3 7 10 2 5 8 4&lt;br /&gt;d. 1 2 6 9 7 10 3 5 8 4&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;23. What is the output of selection sort for the following numbers after the 4th pass?&lt;br /&gt;3 6 9 2 7 10 1 5 8 4&lt;br /&gt;a. 1 2 3 6 7 10 9 5 8 4&lt;br /&gt;b. 1 2 9 6 7 10 3 5 8 4&lt;br /&gt;c.1 6 9 3 7 10 2 5 8 4&lt;br /&gt;d. 1 2 3 4 7 10 9 6 8 5&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;24. What is the output of selection sort for the following numbers after the 5th pass?&lt;br /&gt;3 6 9 2 7 10 1 5 8 4&lt;br /&gt;a. 1 2 3 6 7 10 9 5 8 4&lt;br /&gt;b. 1 2 9 6 7 10 3 5 8 4&lt;br /&gt;c.1 2 3 4 5 10 9 7 8 6&lt;br /&gt;d. 1 2 3 4 7 10 9 6 8 5&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;25. What is the output of selection sort for the following numbers after the 6th pass?&lt;br /&gt;3 6 9 2 7 10 1 5 8 4&lt;br /&gt;a. 1 2 3 4 5 6 10 9 8 7&lt;br /&gt;b. 1 2 9 6 7 10 3 5 8 4&lt;br /&gt;c.1 2 3 4 5 10 9 7 8 6&lt;br /&gt;d. 1 2 3 4 7 10 9 6 8 5&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;26.What is the output of selection sort for the following numbers after the 7th pass?&lt;br /&gt;3 6 9 2 7 10 1 5 8 4&lt;br /&gt;a. 1 2 3 4 5 6 10 9 8 7&lt;br /&gt;b. 1 2 3 4 5 6 7 9 8 10&lt;br /&gt;c.1 2 3 4 5 10 9 7 8 6&lt;br /&gt;d. 1 2 3 4 7 10 9 6 8 5&lt;br /&gt;Ans:b&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-2348639176417742281?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/2348639176417742281/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=2348639176417742281' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2348639176417742281'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2348639176417742281'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/selection-sort-interview-question-part_27.html' title='Selection Sort Interview Question Part 2'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-7279407464328800112</id><published>2007-10-27T10:41:00.000-07:00</published><updated>2007-10-27T10:42:07.875-07:00</updated><title type='text'>Selection Sort Interview Question Part 1</title><content type='html'>1.What is the output of selection sort after the 1st iteration given the following sequence of numbers: 14  9  4  18  45   2  37  63&lt;br /&gt;a. 4   14   9  18  45   2   37  63&lt;br /&gt;b. 2    9   14   18  45   4   37  63&lt;br /&gt;c. 4   9   14    18  45   2   37  63&lt;br /&gt;d.2    14   9  18  45   4   37  63&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. What is the worst case complexity for selection sort algorithm&lt;br /&gt;  a.O(n)     b.O(n*n)    c.O(nlogn)    d.O(logn)&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;3.What is the average case complexity for selection sort algorithm&lt;br /&gt;  a.O(n)     b.O(n*n)    c.O(nlogn)    d.O(logn)&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;4.What is the output of selection sort after the 2nd iteration given the following sequence of numbers: 16  3  46  9  28   14&lt;br /&gt;a.3  9   46   16  28   14&lt;br /&gt;b.3  9   14    16   28   46&lt;br /&gt;c.3  9    16  14   46   28&lt;br /&gt;d.none of the above&lt;br /&gt;Ans:a &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;5.What is the best case complexity for selection sort algorithm&lt;br /&gt;  a.O(n)     b.O(n*n)    c.O(nlogn)    d.O(logn)&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;6.The following loop is used for&lt;br /&gt;    For i&lt;-  1 to N&lt;br /&gt;      For  j&lt;-  i+1  to N&lt;br /&gt;        If(a(i)&gt;a(j))&lt;br /&gt;         {&lt;br /&gt;            Temp=a(i);&lt;br /&gt;             A(i)=a(j);&lt;br /&gt;             A(j)=temp;&lt;br /&gt;         }&lt;br /&gt; a.bubble sort b.selection sort c.insertion sort d.merge sort&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;7.Here is an array of six integers: &lt;br /&gt;      5  3  8  9  1  7  &lt;br /&gt;This array after the FIRST iteration in a selection sort (sorting from smallest to largest) is&lt;br /&gt;a. 5 1 8 4 3 7&lt;br /&gt;b. 1 8 5 4 3 7&lt;br /&gt;c.1 5 8 4 3 7&lt;br /&gt;d. 1 5 8 4 7 3&lt;br /&gt;Ans:c&lt;br /&gt;8.In a selectionsort of n elements, how many times is the swap function called in the complete execution of the algorithm? &lt;br /&gt;A. 1 &lt;br /&gt;B. n - 1 &lt;br /&gt;C. n log n &lt;br /&gt;D. n² &lt;br /&gt;Ans:B&lt;br /&gt;9.A sorting technique in which successive elements are selected in order and placed into their proper sorted positions is called&lt;br /&gt;a.selection sort&lt;br /&gt;b.quick sort &lt;br /&gt;c.bubble sort&lt;br /&gt;d.merge sort&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;10.The selection sort that uses descending priority queue as an unordered array is_____&lt;br /&gt;Ans:straight selection sort&lt;br /&gt;&lt;br /&gt;11.Straight selection sort is also called&lt;br /&gt; a.Push-down sort&lt;br /&gt; b. Push-up sort&lt;br /&gt; c.both&lt;br /&gt;d.none&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;12.The types of selection sort are&lt;br /&gt;a.General selection sort b.Pull-up selection sort c. Push-up selection sort d.none&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;13.In which cases are the time complexities same in selection sort?&lt;br /&gt;a. Worst and Best&lt;br /&gt;b. Best and Average&lt;br /&gt;c. Worst and Average&lt;br /&gt;d. Worst, average and Best&lt;br /&gt;Ans:d&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-7279407464328800112?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/7279407464328800112/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=7279407464328800112' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7279407464328800112'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7279407464328800112'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/selection-sort-interview-question-part.html' title='Selection Sort Interview Question Part 1'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-5389347951907119230</id><published>2007-10-27T10:40:00.000-07:00</published><updated>2007-10-27T10:41:13.908-07:00</updated><title type='text'>Quick Sort Interview Question Part 2</title><content type='html'>17. Which of the following statement(s) best describes the quicksort algorithm&lt;br /&gt;(a)Partitioning the file into two subfiles, selecting some pivot value, sorting the two sub-files sequentially.&lt;br /&gt;(b)Selecting some pivot value, partitioning the file into N sub-files and sorting independently, merging all sub-files into single file.&lt;br /&gt;(c)Selecting some pivot value, partitioning the file into two sub-files, sorting the two sub-files independently in recursive way.&lt;br /&gt;(d)Partitioning the file into two sub-files, sorting these two sub-files independently, then partitioning two sub-files into four sub-files, sorting these four sub-files independently. This process is repeating until entire file becomes sorted.&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;18. If one chooses the middle key as the pivot, what would be the Big-O value for the Best case of the Quick Sort Algorithm? (a) n*n (b) n  (c) a constant  (d) n log n&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;19. Which of the following is/are correct in connection with the time complexity of the quick sort algorithm in the worst case, best case and average case respectively? (a) n*n, n, nlog n  (b) nlog n, nlog n, nlog n  (c) n*n, nlog n, nlog n  (d) n, n, nlog n&lt;br /&gt;Ans:c&lt;br /&gt;20. The basic quicksort algorithm is recursive and consists of four steps, but the following steps are in incorrect order.&lt;br /&gt;(i) Pick any element v in S. This element is called pivot. &lt;br /&gt;(ii) Return the result of Quicksort(L), followed by v, followed  by quicksort(R)&lt;br /&gt;(iii) Partition S – {v} (the remaining elements in S) into two disjoint groups: L={x   S – {v} | x =&lt; v} and R={x  S – {v} | x &gt;v }&lt;br /&gt;(iv) If the number of elements in S is 0 or 1 then return.&lt;br /&gt;&lt;br /&gt;Which of the following is the correct order of steps in the quicksort algorithm?&lt;br /&gt;(a) (iv), (iii),(i),(ii)&lt;br /&gt;      (b) (i),(ii),(iii),(iv)&lt;br /&gt;      (c) (iv), (i),(iii),(ii)&lt;br /&gt;      (d) (i),(iii),(ii),(iv)&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;21. Which of the following activities is/are not relevant to the quick sort algorithm?&lt;br /&gt;(a) Initially divide the entire file into N sub-files.&lt;br /&gt; (b) Choose a pivot value and store it in a correct place.&lt;br /&gt; (c) The sorting technique is sorting by exchange.&lt;br /&gt;(d) The sorting technique is sorting by selection.&lt;br /&gt;Ans:a,d&lt;br /&gt;22. If the last element is chosen as the pivot at each iteration, the Quick-sort tree for&lt;br /&gt;the sequence in question 1 will have height:&lt;br /&gt;a)1&lt;br /&gt;b) 2&lt;br /&gt;c) 3 &lt;br /&gt;d)4&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;23. If Quick-sort were implemented so that the element at position n/2 is chosen as&lt;br /&gt;the pivot, which of the following sequences would be the worst input?&lt;br /&gt;a) 1 2 3 4 5 6 7&lt;br /&gt;b) 2 3 4 1 5 6 7&lt;br /&gt;c) 7 6 5 4 3 2 1&lt;br /&gt;d) 5 6 7 1 2 3 4&lt;br /&gt;e) 6 4 2 7 1 3 5&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;24. Given a large amount of highly random data which fits into the computers RAM,&lt;br /&gt;the best choice for sorting would be:&lt;br /&gt;a) Bubble-sort&lt;br /&gt;b) Insertion-sort&lt;br /&gt;c) Merge-sort&lt;br /&gt;d) Quick-sort &lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;25. In Quick sort , after the completion of every pass the pivot/key element  moves to the  ________ position. a.first b.second c.middle d.exact sorted position&lt;br /&gt;Ans:d&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-5389347951907119230?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/5389347951907119230/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=5389347951907119230' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5389347951907119230'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5389347951907119230'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/quick-sort-interview-question-part-2.html' title='Quick Sort Interview Question Part 2'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-5255119043044686397</id><published>2007-10-27T10:39:00.002-07:00</published><updated>2007-10-27T10:40:41.441-07:00</updated><title type='text'>Quick Sort Interview Question Part 1</title><content type='html'>1.Quick  sort is   1.in-place  2.non in-place  3.stable  4.non-stable   a.1 and 3     b.1 and 4    c.2 and 3    d.2 and 4&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2.What is the average case complexity for quick sort algorithm   a.O(n)      b.O(n*n) c.O(nlogn)     d.O(logn)&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3.What is the worst case complexity for quick sort algorithm  a.O(n)  b.O(n*n) c.O(nlogn) d.O(logn)&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;4.What is the best case complexity for quick sort algorithm  a.O(n)      b.O(n*n)      c.O(nlogn)  d.O(logn)&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;5.Quick sort is also known as  a. Pointer sort  b.External sorting   c.Both   d.none&lt;br /&gt; Ans:c&lt;br /&gt;&lt;br /&gt;6.What is the output of quick sort after the 1st iteration given the following sequence of numbers: 65 70 75 80 85 60 55 50 45 a. 60 45 50 55 65 85 80 70 75  b.60 45 50 55 65 85 80 75 70 c. 45 60 50 55 65 85 80 75 70 d. 60 45 50 65 55 85 80 75 70&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;7.Which sorting technique is also called partition exchange sort? a.selection sort b.quick sort c.bubble sort d.merge sort&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;8. In which cases are the time complexities same in quick sort? a. Worst and Best b. Best and Average c. Worst and Average d. Worst, average and Best&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;9.            Quick sort uses ___________. a.       Divide and Conquer Technique b.      Greedy Approach c.       Back Tracking d.      None of the above&lt;br /&gt;              Ans.  a&lt;br /&gt;&lt;br /&gt;10.      What pattern of splits gives the worst-case performance for quick sort? a.    Ascending order.  b.    Descending order. &lt;br /&gt;c.    Any order.  &lt;br /&gt;d.    None of the above. &lt;br /&gt;                 Ans. b  &lt;br /&gt;&lt;br /&gt;11.In quick sort the pivot value is usually the&lt;br /&gt;a.first element&lt;br /&gt;b.last element&lt;br /&gt;c.middle element&lt;br /&gt;d.any element&lt;br /&gt;Ans: d&lt;br /&gt;&lt;br /&gt;12. What is the output of quick sort after the 2nd iteration given the following sequence of numbers: 65 70 75 80 85 60 55 50 45&lt;br /&gt;a. 60 45 50 55 65 85 80 70 75&lt;br /&gt;b.60 45 50 55 65 85 80 75 70&lt;br /&gt;c.55 45 50 60 65 70 80 75 85&lt;br /&gt;d. 60 45 50 65 55 85 80 75 70&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;13.What is the output of quick sort after the 3rd iteration given the following sequence of numbers: 65 70 75 80 85 60 55 50 45&lt;br /&gt;a. 60 45 50 55 65 85 80 70 75  b.60 45 50 55 65 85 80 75 70  c.55 45 50 60 65 70 80 75 85 d. 50 45 55 60 65 70 80 75 85&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;14.What is the output of quick sort after the 4th iteration given the following sequence of numbers: 65 70 75 80 85 60 55 50 45&lt;br /&gt;a. 45 50 55 60 65 70 75 80 85&lt;br /&gt;b.60 45 50 55 65 85 80 75 70&lt;br /&gt;c.55 45 50 60 65 70 80 75 85&lt;br /&gt;d. 50 45 55 60 65 70 80 75 85&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;15. Which of the following statements about Quick sort is/are incorrect?&lt;br /&gt;   a. Average running time is O(N log N).&lt;br /&gt;   b. The best case always occurs when the pivot partitions the set of numbers to be sorted into two equal-sized subsets.&lt;br /&gt;   c. The worst case always occurs when the pivot partitions the set of numbers to be sorted into two equal-sized subsets.&lt;br /&gt;  d. The worst case always occurs when the smallest item is selected from the items to be sorted as the pivot.&lt;br /&gt;   Ans. c&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;16. Which statement(s) is/are correct for the Quick sort algorithm?&lt;br /&gt;(i) Quick Sort is still best sorting algorithms, known for sequential computers&lt;br /&gt;(ii) It works by partitioning the file into two sub files and sorting two sub files independently.&lt;br /&gt;(iii) The pivot value can be chosen in an arbitrary way.&lt;br /&gt;a.(i) only&lt;br /&gt;b.(i) and (iii) only&lt;br /&gt;c.(i), (ii) and (iii).&lt;br /&gt;d.(ii) and  (iii)&lt;br /&gt;Ans:c&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-5255119043044686397?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/5255119043044686397/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=5255119043044686397' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5255119043044686397'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5255119043044686397'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/quick-sort-interview-question-part-1.html' title='Quick Sort Interview Question Part 1'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-4116689376826087172</id><published>2007-10-27T10:39:00.001-07:00</published><updated>2007-10-27T10:39:25.858-07:00</updated><title type='text'>Merge Sort Interview Question Part 2</title><content type='html'>16. Given the initial sequence : 3,41,52,26,38,57,9,49 ,at the last step in the merge sort .the sequences to be merged are &lt;br /&gt; a.{ 3,26,52,41} and {38,49,57,9}&lt;br /&gt; b.{ 3,26,41,52} and {9,38,49,57}&lt;br /&gt; c. {3,9,41,52} and {26,38,49,57}&lt;br /&gt; d. {3,9,26,38} and {41,49,52,57}&lt;br /&gt; Ans. b&lt;br /&gt;&lt;br /&gt;17. Mergesort makes two recursive calls. Which statement is true after these recursive calls finish, but before the merge step? &lt;br /&gt;a. The array elements form a heap&lt;br /&gt;b. Elements in each half of the array are sorted among themselves&lt;br /&gt;c. Elements in the first half of the array are less than or equal to elements in the second half of the array&lt;br /&gt;d. . Elements in the first half of the array are greater than or equal to elements in the second half of the array&lt;br /&gt;Ans. b&lt;br /&gt;18. Given the initial sequence: {85 24 63 47 17 31 96 50}, at the last step in the&lt;br /&gt;merge sort, the sequences to be merged are:&lt;br /&gt;a). {24 47 63 85} and {17 31 50 96} &lt;br /&gt;b). {17 24 31 47} and {50 63 85 96}&lt;br /&gt;c). {24 85} {47 63} {17 31} and {50 96}&lt;br /&gt;d). {17 24 31 47 63 85 96} and {50}&lt;br /&gt;e). depends on choice of pivot&lt;br /&gt;Ans. a&lt;br /&gt;19.On each iteration,the size of the sorted lists in a merge sort&lt;br /&gt;  a. doubles&lt;br /&gt;  b. halves&lt;br /&gt;  c.remains the same&lt;br /&gt; d. increases 4 times&lt;br /&gt;Ans. a&lt;br /&gt;On each iteration, the size of the sorted lists doubles, form 1 to 2 to 4 to 8 to 16 ...to n.&lt;br /&gt;&lt;br /&gt;20. What is the output of merge sort after the 1st pass given the following sequence of numbers: 12 13 1 5 7 9 11 14&lt;br /&gt;a. 12 13 1 5 7 9 11 14&lt;br /&gt;b. 1 5 12 13 7 9 11 14&lt;br /&gt;c. 1 5 7 9 11 12 13 14&lt;br /&gt;d. 1 5 7 9 12 13 11 14&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;21. What is the output of merge sort after the 2nd pass given the following sequence of numbers: 12 13 1 5 7 9 11 14&lt;br /&gt;a. 12 13 1 5 7 9 11 14&lt;br /&gt;b. 1 5 12 13 7 9 11 14&lt;br /&gt;c. 1 5 7 9 11 12 13 14&lt;br /&gt;d. 1 5 7 9 12 13 11 14&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;22. What is the output of merge sort after the 3rd pass given the following sequence of numbers: 12 13 1 5 7 9 11 14&lt;br /&gt;a. 12 13 1 5 7 9 11 14&lt;br /&gt;b. 1 5 12 13 7 9 11 14&lt;br /&gt;c. 1 5 7 9 11 12 13 14&lt;br /&gt;d. 1 5 7 9 12 13 11 14&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;23. In every pass, maximum number of comparisons in the merge sort  is _________.&lt;br /&gt;a.n-1&lt;br /&gt;b.n&lt;br /&gt;c.log n&lt;br /&gt;d.n*n&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;24.What does the following pseudocode do?&lt;br /&gt;&lt;br /&gt;function sort(m)&lt;br /&gt;    var list left, right&lt;br /&gt;    if length(m) ≤ 1&lt;br /&gt;        return m&lt;br /&gt;    else&lt;br /&gt;        middle = length(m) / 2&lt;br /&gt;        for each x in m up to middle&lt;br /&gt;            add x to left&lt;br /&gt;        for each x in m after middle&lt;br /&gt;            add x to right&lt;br /&gt;        left = sort(left)&lt;br /&gt;        right = sort(right)&lt;br /&gt;        result = app(left, right)&lt;br /&gt;        return result&lt;br /&gt;    end if&lt;br /&gt;a. quick sort&lt;br /&gt;b. selection sort&lt;br /&gt;c. insertion sort&lt;br /&gt;d. merge sort&lt;br /&gt;Ans. d&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-4116689376826087172?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/4116689376826087172/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=4116689376826087172' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4116689376826087172'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4116689376826087172'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/merge-sort-interview-question-part-2.html' title='Merge Sort Interview Question Part 2'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-1524370200800133278</id><published>2007-10-27T10:20:00.002-07:00</published><updated>2007-10-27T10:38:50.230-07:00</updated><title type='text'>Merge Sort Interview Question Part 1</title><content type='html'>1. What is the average case complexity for merge sort algorithm&lt;br /&gt;    a.O(n)     b.O(n*n)    c.O(nlogn)    d.O(logn)&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;2. What is the worst case complexity for merge sort algorithm&lt;br /&gt;    a.O(n)     b.O(n*n)    c.O(nlogn)    d.O(logn)&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3. What is the best case complexity for merge sort algorithm&lt;br /&gt;  a.O(n)     b.O(n*n)    c.O(nlogn)    d.O(logn)&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;4. What is the output of merge sort after the 1st pass given the following sequence of numbers: 25 57 48 37 12 92 86 33&lt;br /&gt;a. 48 25 37 12 57 86 33 92  &lt;br /&gt;b. 12 25 33 37 48 57 86 92  &lt;br /&gt;c.12 25 33 37 48 57 86 92  &lt;br /&gt;d. 25 57 37 48 12 92 33 86&lt;br /&gt;Ans:d  &lt;br /&gt;&lt;br /&gt;5. What is the output of merge sort after the 2nd pass given the following sequence of numbers: 25 57 48 37 12 92 86 33&lt;br /&gt;a. 48 25 37 12 57 86 33 92  &lt;br /&gt;b. 12 25 33 37 48 57 86 92  &lt;br /&gt;c.25 37 48 57 12 33 86 92  &lt;br /&gt;d. 25 57 37 48 12 92 33 86&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;6. What is the output of merge sort after the 3rd pass given the following sequence of numbers: 25 57 48 37 12 92 86 33&lt;br /&gt;a. 12 25 33 37 48 57 86 92&lt;br /&gt;b. 12 25 33 37 48 57 86 92  &lt;br /&gt;c.12 25 33 37 48 57 86 92  &lt;br /&gt;d. 25 57 37 48 12 92 33 86&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;7. In which cases are the time complexities same in merge sort?&lt;br /&gt;a. Worst and Best&lt;br /&gt;b. Best and Average&lt;br /&gt;c. Worst and Average&lt;br /&gt;d. Worst, average and Best&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;8.Total numbers of passes in merge sort of 'n' numbers is _______.&lt;br /&gt;a.n&lt;br /&gt;b.n-1&lt;br /&gt;c.log(n)&lt;br /&gt;d.nlogn&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;9.Merge sort is based on the divide and conquer strategy.it consists of the following  steps&lt;br /&gt;a. Divide,Recursive and Conquer&lt;br /&gt;b. Divide and Conquer&lt;br /&gt;c. Divide and Recursive&lt;br /&gt;d. None of the above&lt;br /&gt;                Ans.  a   &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;10.Given two sorted lists of size m,n ,the number of comparisons needed in the worst case by the merge sort algorithm is&lt;br /&gt;a.mn b.max(m,n) c.min(m,n) d.m+n-1&lt;br /&gt;Ans:d&lt;br /&gt;Each comparison puts 1 element in the final sorted array. So,in the worst case m+n-1 comparisons are needed.&lt;br /&gt;&lt;br /&gt;11. Suppose the array A contains 14 elements as follows:&lt;br /&gt; A = [66, 33, 40, 22, 55, 88, 60, 11, 80, 20, 50, 44, 77, 30] &lt;br /&gt;      How many Passes are required to sort the above array A using the Merge sort algorithm?&lt;br /&gt;a. 3         &lt;br /&gt;b. 4 &lt;br /&gt;c. 5&lt;br /&gt;d. 7&lt;br /&gt;e. 14&lt;br /&gt;  Ans.  c&lt;br /&gt; &lt;br /&gt;12. If you are provided with two files whose contents are sorted and the requirement is to copy the contents of both the files into a third file which should be sorted. In this case which of the sorting techniques can be an appropriate one?&lt;br /&gt;a.Selection sort&lt;br /&gt;b.Bubble sort&lt;br /&gt;c.Merge sort&lt;br /&gt;d.insertion sort&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;13. The merge sort algorithm involves the following steps.&lt;br /&gt;(i) Recursively sort the 1st and 2nd halves separately&lt;br /&gt;(ii) Merge the two-sorted halves into a sorted group.&lt;br /&gt;(iii) If the number of items to sort is 0 or 1, return.&lt;br /&gt;&lt;br /&gt;Which is the correct order of instructions in merge sort algorithm?&lt;br /&gt;(a) (i),(ii),(iii)&lt;br /&gt;(b) (ii),(iii),(i)&lt;br /&gt;(c) (iii),(ii),(i)&lt;br /&gt;(d) (iii),(i),(ii)&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;14. What is the output of merge sort after the 1st pass given the following sequence of numbers : 3,41,52,26,38,57,9,49&lt;br /&gt;   a. 3,41,26,52,38,57,9,49&lt;br /&gt;   b. 3,41,52,26,38,57,9,49&lt;br /&gt;   c. 3,41,52,26,38,57,9,49&lt;br /&gt;   d. 3,41,38,26,52,9,49,57&lt;br /&gt;  Ans. a&lt;br /&gt;&lt;br /&gt;15. What is the output of merge sort after the 2nd pass given the following sequence of numbers : 3,41,52,26,38,57,9,49&lt;br /&gt;  a.  3,26,41,52,38,9,49,57&lt;br /&gt;  b. 3,26,41,52,9,38,49,57&lt;br /&gt; c. 3,26,38,9,49,57,41,52&lt;br /&gt; d. 3,26,41,52,38,49,57,9&lt;br /&gt; Ans. b&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-1524370200800133278?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/1524370200800133278/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=1524370200800133278' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/1524370200800133278'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/1524370200800133278'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/merge-sort-interview-question-part-1.html' title='Merge Sort Interview Question Part 1'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-5528478114345416809</id><published>2007-10-27T10:20:00.001-07:00</published><updated>2007-10-27T10:20:40.608-07:00</updated><title type='text'>Insertion Sort Interview Question Part 4</title><content type='html'>37. The output of 7th iteration for the sequence 5 7 0 3 4 2 6 1 using insertion sort is&lt;br /&gt;a. 0 2 3 4 5 7 6 1&lt;br /&gt;b.0 2 3 4 5 6 7 1&lt;br /&gt;&lt;br /&gt;c. 0 3 5 7 4 2 6 1&lt;br /&gt;&lt;br /&gt;d. 0 3 4 5 7 2 6 1&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;38. The output of 8th iteration for the sequence 5 7 0 3 4 2 6 1 using insertion sort is&lt;br /&gt;a. 0 2 3 4 5 7 6 1&lt;br /&gt;b.0 2 3 4 5 6 7 1&lt;br /&gt;&lt;br /&gt;c. 0 1 2 3 4 5 6 7&lt;br /&gt;&lt;br /&gt;d. 0 3 4 5 7 2 6 1&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;39. The number of positions the inserted element has moved after the 1st iteration is&lt;br /&gt;a.0  b.2   c.4   d.6&lt;br /&gt;Ans:a&lt;br /&gt; &lt;br /&gt;40. The number of positions the inserted element has moved after the 2nd iteration is&lt;br /&gt;a.0  b.2   c.4   d.6&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;41. The number of positions the inserted element has moved after the 3rd iteration is&lt;br /&gt;a.0  b.2   c.4   d.6&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;42. The number of positions the inserted element has moved after the 4th iteration is&lt;br /&gt;a.0  b.2   c.4   d.6&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;43. The number of positions the inserted element has moved after the 5th iteration is&lt;br /&gt;a.0  b.2   c.4   d.6&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;44. The number of positions the inserted element has moved after the 6th iteration is&lt;br /&gt;a.0  b.2   c.4   d.6&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;45. The number of positions the inserted element has moved after the 7th iteration is&lt;br /&gt;a.0  b.1  c.4   d.6&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;46. The number of positions the inserted element has moved after the 8th iteration is&lt;br /&gt;a.0  b.2   c.4   d.6&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;5 7 0 3 4 2 6 1   (0)&lt;br /&gt;5 7 0 3 4 2 6 1   (0)&lt;br /&gt;0 5 7 3 4 2 6 1   (2)&lt;br /&gt;0 3 5 7 4 2 6 1   (2)&lt;br /&gt;0 3 4 5 7 2 6 1   (2)&lt;br /&gt;0 2 3 4 5 7 6 1   (4)&lt;br /&gt;0 2 3 4 5 6 7 1   (1)&lt;br /&gt;0 1 2 3 4 5 6 7   (6)&lt;br /&gt; &lt;br /&gt;        On the left side the sorted part of the sequence is shown in red. For each iteration, the number of positions the inserted element has moved is shown in brackets. Altogether this amounts to 17 steps. &lt;br /&gt;&lt;br /&gt;47. What is the output of insertion sort after the 7th iteration given the following sequence of numbers: 7 3 5 1 9 8 4 6&lt;br /&gt;a. 3 7 5 1 9 8 4 6&lt;br /&gt;b. 1 3 4 5 6 7 8 9 &lt;br /&gt;c. 3 4 1 5 6 8 7 9 &lt;br /&gt;d. 1 3 4 5 6 7 9 8 &lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;48. What is the output of insertion sort after the 9th iteration given the following sequence of numbers: 3 10 4 6 8 9 7 2 1 5&lt;br /&gt;A.1 2 3 4 6 7 8 9 10 5&lt;br /&gt;b. 2 3 4 6 7 8 9 10 1 5&lt;br /&gt;c. 1 2 3 4 5 6 7 8 9 10&lt;br /&gt;d. 3 4 6 8 9 10 7 2 1 5&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;49. ________ is a sorting technique that sorts a set of records by inserting records into an existing sorted file.&lt;br /&gt;  a. quick sort&lt;br /&gt;  b. insertion sort&lt;br /&gt;  c. selection sort&lt;br /&gt;  d. merge sort&lt;br /&gt;Ans. b&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-5528478114345416809?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/5528478114345416809/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=5528478114345416809' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5528478114345416809'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5528478114345416809'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/insertion-sort-interview-question-part_5708.html' title='Insertion Sort Interview Question Part 4'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-8789901015178571440</id><published>2007-10-27T10:19:00.002-07:00</published><updated>2007-10-27T10:20:13.357-07:00</updated><title type='text'>Insertion Sort Interview Question Part 3</title><content type='html'>25. What is the output of insertion sort after the 4th iteration given the following sequence of numbers: 3 10 4 6 8 9 7 2 1 5&lt;br /&gt;a. 3 4 6 8 10 9 7 2 1 5&lt;br /&gt;b. 3 4 6 10 8 9 7 2 1 5&lt;br /&gt;c. 3 4 10 6 8 9 7 2 1 5&lt;br /&gt;d. 3 4 6 8 9 10 7 2 1 5&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;26. What is the output of insertion sort after the 5th iteration given the following sequence of numbers: 3 10 4 6 8 9 7 2 1 5&lt;br /&gt;a. 3 4 6 8 10 9 7 2 1 5&lt;br /&gt;b. 3 4 6 10 8 9 7 2 1 5&lt;br /&gt;c. 3 4 6 7 8 9 10 2 1 5&lt;br /&gt;d. 3 4 6 8 9 10 7 2 1 5&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;27. What is the output of insertion sort after the 6th iteration given the following sequence of numbers: 3 10 4 6 8 9 7 2 1 5&lt;br /&gt;a. 3 4 6 8 10 9 7 2 1 5&lt;br /&gt;b. 3 4 6 7 8 9 10 2 1 5&lt;br /&gt;c. 3 4 10 6 8 9 7 2 1 5&lt;br /&gt;d. 3 4 6 8 9 10 7 2 1 5&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;28. What is the output of insertion sort after the 7th iteration given the following sequence of numbers: 3 10 4 6 8 9 7 2 1 5&lt;br /&gt;A.1 2 3 4 6 7 8 9 10 5&lt;br /&gt;b. 2 3 4 6 7 8 9 10 1 5&lt;br /&gt;c. 3 4 10 6 8 9 7 2 1 5&lt;br /&gt;d. 3 4 6 8 9 10 7 2 1 5&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;29. What is the output of insertion sort after the 8th iteration given the following sequence of numbers: 3 10 4 6 8 9 7 2 1 5&lt;br /&gt;A.1 2 3 4 6 7 8 9 10 5&lt;br /&gt;b. 2 3 4 6 7 8 9 10 1 5&lt;br /&gt;c. 1 2 3 4 5 6 7 8 9 10&lt;br /&gt;d. 3 4 6 8 9 10 7 2 1 5&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;30. Consider the following insertion sort algorithm and the Data set of integers given thereafter:&lt;br /&gt;&lt;br /&gt;Setp 1 : initialise marker1 to 1 ( the location of the second element in the list)&lt;br /&gt;Step 2 : while marker1 &lt; L&lt;br /&gt;Setp 3 : if Element[marker1] &lt; Element[marker1- 1 ] , store Element [marker1] in a temporary location temp. Initialise marker2 to marker1 – 1 ( the location just before the marker1)&lt;br /&gt;  Step 4 : while Element[marker2] &gt; temp and marker2 &gt;= 0. Shift Element[marker2] to location marker2+1.( this slides the element over to make room to its left). Decrease marker2 by 1&lt;br /&gt;                       Step 5 : insert temp into the location last vacated by a shift&lt;br /&gt;        Setp 6 : increase marker1 by 1.&lt;br /&gt;&lt;br /&gt;Data set: 3 9 1 7 2&lt;br /&gt;Note: There are L elements numbered from 0 to L-1 stored in the array.&lt;br /&gt;&lt;br /&gt; Which of the following values are not the temp values during the process of sorting?&lt;br /&gt;(a) 1   (b)3   (c)7       (d)2&lt;br /&gt;Ans: b&lt;br /&gt;&lt;br /&gt;     31. The output of 1st iteration for the sequence 5 7 0 3 4 2 6 1 using insertion sort is&lt;br /&gt;a. 5 7 0 3 4 2 6 1&lt;br /&gt;b. 0 5 7 3 4 2 6 1&lt;br /&gt;&lt;br /&gt;c. 0 3 5 7 4 2 6 1&lt;br /&gt;&lt;br /&gt;d. 0 3 4 5 7 2 6 1&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;32. The output of 2nd iteration for the sequence 5 7 0 3 4 2 6 1 using insertion sort is&lt;br /&gt;a.5 7 0 3 4 2 6 1&lt;br /&gt;b. 0 5 7 3 4 2 6 1&lt;br /&gt;&lt;br /&gt;c. 0 3 5 7 4 2 6 1&lt;br /&gt;&lt;br /&gt;d. 0 3 4 5 7 2 6 1&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;33. The output of 3rd iteration for the sequence 5 7 0 3 4 2 6 1 using insertion sort is&lt;br /&gt;a.5 7 0 3 4 2 6 1&lt;br /&gt;b. 0 5 7 3 4 2 6 1&lt;br /&gt;&lt;br /&gt;c. 0 3 5 7 4 2 6 1&lt;br /&gt;&lt;br /&gt;d. 0 3 4 5 7 2 6 1&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;34. The output of 4th iteration for the sequence 5 7 0 3 4 2 6 1 using insertion sort is&lt;br /&gt;a.5 7 0 3 4 2 6 1&lt;br /&gt;b. 0 5 7 3 4 2 6 1&lt;br /&gt;&lt;br /&gt;c. 0 3 5 7 4 2 6 1&lt;br /&gt;&lt;br /&gt;d. 0 3 4 5 7 2 6 1&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;35. The output of 5th iteration for the sequence 5 7 0 3 4 2 6 1 using insertion sort is&lt;br /&gt;a.5 7 0 3 4 2 6 1&lt;br /&gt;b. 0 5 7 3 4 2 6 1&lt;br /&gt;&lt;br /&gt;c. 0 3 5 7 4 2 6 1&lt;br /&gt;&lt;br /&gt;d. 0 3 4 5 7 2 6 1&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;36. The output of 6th iteration for the sequence 5 7 0 3 4 2 6 1 using insertion sort is&lt;br /&gt;a.0 2 3 4 5 7 6 1&lt;br /&gt;b. 0 5 7 3 4 2 6 1&lt;br /&gt;&lt;br /&gt;c. 0 3 5 7 4 2 6 1&lt;br /&gt;&lt;br /&gt;d. 0 3 4 5 7 2 6 1&lt;br /&gt;Ans:a&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-8789901015178571440?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/8789901015178571440/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=8789901015178571440' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/8789901015178571440'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/8789901015178571440'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/insertion-sort-interview-question-part_4179.html' title='Insertion Sort Interview Question Part 3'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-2998420806899753144</id><published>2007-10-27T10:19:00.001-07:00</published><updated>2007-10-27T10:19:32.206-07:00</updated><title type='text'>Insertion Sort Interview Question Part 2</title><content type='html'>13. What is the output of insertion sort after the 4th iteration given the following sequence of numbers: 7 3 5 1 9 8 4 6&lt;br /&gt;a. 3 7 5 1 9 8 4 6&lt;br /&gt;b. 1 3 5 7 9 8 4 6&lt;br /&gt;c. 3 4 1 5 6 8 7 9 &lt;br /&gt;d. 1 3 4 5 6 7 8 9 &lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;14. What is the output of insertion sort after the 5th iteration given the following sequence of numbers: 7 3 5 1 9 8 4 6&lt;br /&gt;a. 3 7 5 1 9 8 4 6&lt;br /&gt;b. 1 3 4 5 7 9 8 6&lt;br /&gt;c. 3 4 1 5 6 8 7 9 &lt;br /&gt;d. 1 3 5 7 8 9 4 6 &lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;15. What is the output of insertion sort after the 6th iteration given the following sequence of numbers: 7 3 5 1 9 8 4 6&lt;br /&gt;a. 3 7 5 1 9 8 4 6&lt;br /&gt;b. 1 3 4 5 7 8 9 6&lt;br /&gt;c. 3 4 1 5 6 8 7 9 &lt;br /&gt;d. 1 3 4 5 6 7 9 8 &lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;16.The frequency count of insertion sort in the worst case is&lt;br /&gt;  a.n*n&lt;br /&gt;  b.n(n-1)/2&lt;br /&gt;  c.n&lt;br /&gt;  d.logn&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;17.The frequency count of insertion sort in the average case is&lt;br /&gt;  a.n*n&lt;br /&gt;  b.n(n-1)/2&lt;br /&gt;  c.n(n-1)/4&lt;br /&gt;  d.logn&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;18.Insertion sort is an example of&lt;br /&gt;a.incremental algorithm&lt;br /&gt;b.decremental algorithm&lt;br /&gt;c.both&lt;br /&gt;d.none&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;19.The best case running time T(n) for insertion sort is&lt;br /&gt;a.a quadratic function of n&lt;br /&gt;b.a linear function of n&lt;br /&gt;c.a logarithmic function of n&lt;br /&gt;d.none&lt;br /&gt;Ans:b&lt;br /&gt;Complexity is O(n)&lt;br /&gt;&lt;br /&gt;20. The worst case running time T(n) for insertion sort is&lt;br /&gt;a.a quadratic function of n&lt;br /&gt;b.a linear function of n&lt;br /&gt;c.a logarithmic function of n&lt;br /&gt;d.none&lt;br /&gt;Ans:a&lt;br /&gt;Complexity is O(n*n)&lt;br /&gt;&lt;br /&gt;21. The sort that keeps making the left side of the array sorted until the whole array is sorted and which sorts the values seen so far and repeatedly inserts unseen values in the array into the left sorted array is called&lt;br /&gt;a.selection sort&lt;br /&gt;b.bubble sort&lt;br /&gt;c.insertion sort&lt;br /&gt;d.heap sort&lt;br /&gt;Ans:c&lt;br /&gt;22. What is the output of insertion sort after the 1st iteration given the following sequence of numbers: 3 10 4 6 8 9 7 2 1 5&lt;br /&gt;a. 3 4 10 6 8 7 9 2 1 5&lt;br /&gt;b. 3 4 6 10 8 9 7 2 1 5&lt;br /&gt;c. 3 10 4 6 8 9 7 2 1 5&lt;br /&gt;d. 3 4 10 6 8 9 2 7 1 5&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;23. What is the output of insertion sort after the 2nd iteration given the following sequence of numbers: 3 10 4 6 8 9 7 2 1 5&lt;br /&gt;a. 3 4 10 6 8 7 9 2 1 5&lt;br /&gt;b. 3 4 10 6 8 9 7 2 1 5&lt;br /&gt;c. 3 4 10 6 8 9 7 2 1 5&lt;br /&gt;d. 3 4 10 6 8 9 2 7 1 5&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;24. What is the output of insertion sort after the 3rd iteration given the following sequence of numbers: 3 10 4 6 8 9 7 2 1 5&lt;br /&gt;a. 3 4 6 8 10 9 7 2 1 5&lt;br /&gt;b. 3 4 6 10 8 9 7 2 1 5&lt;br /&gt;c. 3 4 10 6 8 9 7 2 1 5&lt;br /&gt;d. 3 4 10 6 8 9 2 7 1 5&lt;br /&gt;Ans:b&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-2998420806899753144?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/2998420806899753144/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=2998420806899753144' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2998420806899753144'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2998420806899753144'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/insertion-sort-interview-question-part_27.html' title='Insertion Sort Interview Question Part 2'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-706395736383837328</id><published>2007-10-27T10:17:00.002-07:00</published><updated>2007-10-27T10:19:07.971-07:00</updated><title type='text'>Insertion Sort Interview Question Part 1</title><content type='html'>1.Insertion sort is   1.in-place  2.out-place  3.stable  4.non-stable&lt;br /&gt;  a.1 and 3    b.1 and 4   c.2 and 3   d.2 and 4&lt;br /&gt;Ans:a&lt;br /&gt;The array is sorted in-place because no extra memory is required. Stable sort retains the original ordering of keys when identical keys are present in the input data.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2.Sorting of  playing cards is an example of&lt;br /&gt; a.Bubble sort  b. Insertion sort   c.Selection sort  d.Quick sort&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;3. For insertion sort, the number of  entries we must index through when there are n elements in the array is&lt;br /&gt;a. n entries b.n*n entries  c.n-1 entries  d.none of the above&lt;br /&gt;Ans:c&lt;br /&gt;Assuming there are n elements in the array we must index through n - 1 entries. For each entry we may need to examine and shift up to n - 1 other entries resulting in a O(n2) algorithm.&lt;br /&gt;&lt;br /&gt;4.What is the average case complexity for insertion sort algorithm&lt;br /&gt;  a.O(n)     b.O(n*n)    c.O(nlogn)    d.O(logn)&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;5.What is the worst case complexity for insertion sort algorithm&lt;br /&gt;  a.O(n)     b.O(n*n)    c.O(nlogn)    d.O(logn)&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;6. What is the best case complexity for insertion sort algorithm&lt;br /&gt;  a.O(n)     b.O(n*n)    c.O(nlogn)    d.O(logn)&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;7.What is the output of insertion sort after the 1st iteration given the following sequence of numbers: 7 3 5 1 9 8 4 6&lt;br /&gt;a. 3 7 5 1 9 8 4 6&lt;br /&gt;b. 1 3 7 5 9 8 4 6&lt;br /&gt;c. 3 4 1 5 6 8 7 9 &lt;br /&gt;d. 1 3 4 5 6 7 8 9 &lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;8. The following loop is used for&lt;br /&gt;    For i&lt;-  1 to N-1 &lt;br /&gt;     {&lt;br /&gt;      For  j&lt;-  i+1  to N&lt;br /&gt;       {&lt;br /&gt;            If(a(j)&lt;a(i))&lt;br /&gt;            {&lt;br /&gt;              Temp=a(j);&lt;br /&gt;              For k&lt;- j to i+1&lt;br /&gt;              A[k]=a[k-1];&lt;br /&gt;           }&lt;br /&gt;       }&lt;br /&gt;              A(i)=temp;&lt;br /&gt;      }&lt;br /&gt; a.bubble sort b.selection sort c.insertion sort d.merge sort&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;9. Total number of comparisons for insertion sort is&lt;br /&gt;a.n(n-1)/2&lt;br /&gt;b. n(n+1)/2&lt;br /&gt;c.n&lt;br /&gt;d.n*n&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;10. In which cases are the time complexities same in insertion sort?&lt;br /&gt;a. Worst and Best&lt;br /&gt;b. Best and Average&lt;br /&gt;c. Worst and Average&lt;br /&gt;d. Worst, average and Best&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;11. What is the output of insertion sort after the 2nd iteration given the following sequence of numbers: 7 3 5 1 9 8 4 6&lt;br /&gt;a. 3 5 7  1 9 8 4 6&lt;br /&gt;b. 1 3 7 5 9 8 4 6&lt;br /&gt;c. 3 4 1 5 6 8 7 9 &lt;br /&gt;d. 1 3 4 5 6 7 8 9 &lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;12.What is the output of insertion sort after the 3rd iteration given the following sequence of numbers: 7 3 5 1 9 8 4 6&lt;br /&gt;a. 3 7 5 1 9 8 4 6&lt;br /&gt;b. 1 3 7 5 9 8 4 6&lt;br /&gt;c. 3 4 1 5 6 8 7 9 &lt;br /&gt;d. 1 3 5 7 9 8 4 6 &lt;br /&gt;Ans:d&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-706395736383837328?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/706395736383837328/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=706395736383837328' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/706395736383837328'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/706395736383837328'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/insertion-sort-interview-question-part.html' title='Insertion Sort Interview Question Part 1'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-8457407469482898683</id><published>2007-10-27T10:17:00.001-07:00</published><updated>2007-10-27T10:17:31.285-07:00</updated><title type='text'>Heap Sort Interview Question Part 2</title><content type='html'>17. The __________ data structure is a n array object that can be viewed as a nearly complete binary tree.&lt;br /&gt;  a. stack&lt;br /&gt;  b. queue&lt;br /&gt;  c. binary heap&lt;br /&gt;  d.linked list&lt;br /&gt;Ans. c&lt;br /&gt;&lt;br /&gt;18. The MAX-HEAPIFY procedure has running time &lt;br /&gt;   a. O(n) &lt;br /&gt;   b. O(n log n)&lt;br /&gt;   c. O(log n)&lt;br /&gt;   d. O(n²)&lt;br /&gt; Ans. c&lt;br /&gt;&lt;br /&gt; 19. The worst case running time of MAX-HEAPIFY on a heap of size n is ______&lt;br /&gt;    a. O(lg n)&lt;br /&gt;    b. θ (lg n)&lt;br /&gt;    c. Ω (lg n)&lt;br /&gt;    d. O(n)&lt;br /&gt;   Ans. c&lt;br /&gt;&lt;br /&gt;20. The worst case running time of heapsort is&lt;br /&gt;a. O(n log n)&lt;br /&gt;b. O(log n)&lt;br /&gt;c. Θ(log n)&lt;br /&gt;d. Ω(n log n)&lt;br /&gt;     Ans. d&lt;br /&gt;&lt;br /&gt;21. Which of the following arrays represent descending (max) heaps?&lt;br /&gt;a. [10,7,7,2,4,6]&lt;br /&gt;b. [10,7,6,2,4,7]&lt;br /&gt;c. [10]&lt;br /&gt;d. [10,6,7,2,4,6]&lt;br /&gt;Ans. c&lt;br /&gt;&lt;br /&gt;22. Which of the following is/are incorrect?&lt;br /&gt;a. The worst case complexity of Heap Sort is O(n2).&lt;br /&gt;b. A heap can be easily constructed in an array so that the left and right children of a node at index k have indexes 2k and 2k+1 respectively.&lt;br /&gt;c. The worst case complexity of Heap Sort is O(n log n).&lt;br /&gt;d. A binary tree can be transformed into a heap by systematically moving items up in the binary tree, starting from the leaf nodes.&lt;br /&gt;Ans.  a&lt;br /&gt;&lt;br /&gt;23. Consider the following statements:&lt;br /&gt;(i) In a max heap, the value of each non-leaf node is strictly less than the values of its children.&lt;br /&gt;(ii) A binary heap is a complete binary tree.&lt;br /&gt;(iii) All complete binary trees are heaps.&lt;br /&gt;&lt;br /&gt;Which of the above statement(s) is/are correct?&lt;br /&gt;a. (i) only&lt;br /&gt;b. (ii) only&lt;br /&gt;c. (iii) only&lt;br /&gt;d. (i) and (ii) only&lt;br /&gt;Ans. b&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;       24. Which of the following statement(s) describe properties of a Heap&lt;br /&gt;&lt;br /&gt;(i) A heap is a special kind of binary tree, that does not leave any  gap in the array implementation.&lt;br /&gt;(ii) The value stored at any node is larger than the value stored in it’s children.&lt;br /&gt;(iii) A heap may be easily constructed from an array. The left child of a node k has index 2k and right child has index 2k+1.&lt;br /&gt;(iv) Level of all leaf nodes must be last level or last level-1.&lt;br /&gt;a.(i), (ii), (iii) and (iv) only.&lt;br /&gt;b.(i) and (ii) only.&lt;br /&gt;c.(i) and (iii) only.&lt;br /&gt;d.(i), (ii) and (iii) only.&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;25. {2,8,6,1,10,15,3,12,11} is a set of  integers. If you create a maximum heap and store it in an array, what would be the final values in the array?&lt;br /&gt;&lt;br /&gt;(a)1,2,3,6,8,10,11,12,15&lt;br /&gt;(b)15,12,11,10,8,6,3,2,1&lt;br /&gt;(c) 15,12,6,11,10,2,3,8,1&lt;br /&gt;(d)15,12,10,11,2,6,3,1,8&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;26. Consider the following statements:&lt;br /&gt;(i) In a max heap, root value is always higher than its children (if any).&lt;br /&gt;(ii) A heap is fully filled from level 1 to level last –1. &lt;br /&gt;&lt;br /&gt;Which of the above statements is/are correct?&lt;br /&gt;a.only 1  b.only 2  c.both 1 and 2  d.none&lt;br /&gt;Ans:c&lt;br /&gt;27. The following sequence represents a max heap stored in an array: 60 40 50 35 32&lt;br /&gt;30 20 34 10 25. What would be the content of the array after 3 removeMax (&amp; reheap)&lt;br /&gt;operations of a heap-sort algorithm implemented in place?&lt;br /&gt;a). 35 34 30 10 32 25 20 40 50 60 &lt;br /&gt;b). 35 34 30 10 32 25 20 60 50 40&lt;br /&gt;c). 60 50 40 35 32 30 20 34 10 25&lt;br /&gt;d). 40 10 50 34 60 32 35 25 30 20&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;28. Inserting an item into a heap takes O(n2) time.(T/F)&lt;br /&gt;false -- O(lg n)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-8457407469482898683?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/8457407469482898683/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=8457407469482898683' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/8457407469482898683'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/8457407469482898683'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/heap-sort-interview-question-part-2.html' title='Heap Sort Interview Question Part 2'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-2623944663851109312</id><published>2007-10-27T10:15:00.002-07:00</published><updated>2007-10-27T10:16:56.186-07:00</updated><title type='text'>Heap Sort Interview Question Part 1</title><content type='html'>1. What is the average case complexity for heap sort algorithm&lt;br /&gt;  a.O(n)     b.O(n*n)    c.O(nlogn)    d.O(logn)&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2.What is the best case complexity for heap sort algorithm&lt;br /&gt;  a.O(n)     b.O(n*n)    c.O(nlogn)    d.O(logn)&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3.The condition applicable for max-heap is&lt;br /&gt;  a.A[Parent(i)]&gt;=A[i]&lt;br /&gt;  b. A[Parent(i)]&lt;=A[i]&lt;br /&gt;  c. A[Parent(i+1)]&gt;A[i]&lt;br /&gt;  d. A[Parent(i+1)]&lt;A[i]&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;4.The condition applicable for min-heap is&lt;br /&gt;  a.A[Parent(i)]&gt;=A[i]&lt;br /&gt;  b. A[Parent(i)]&lt;=A[i]&lt;br /&gt;  c. A[Parent(i+1)]&gt;A[i]&lt;br /&gt;  d. A[Parent(i+1)]&lt;A[i]&lt;br /&gt; Ans:b&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;5.The number of operations required for heap sort regardless of the order of input&lt;br /&gt;a.O(1)&lt;br /&gt;b.O(logn)&lt;br /&gt;c.O(nlogn)&lt;br /&gt;d.O(n*n)&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;6.In which cases are the time complexities same in heap sort?&lt;br /&gt;a. Worst and Best&lt;br /&gt;b. Best and Average&lt;br /&gt;c. Worst and Average&lt;br /&gt;d. Worst, average and Best&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;7.The heap sort property is __________. &lt;br /&gt;a.  A[Parent(I)] &gt;=A[I] &lt;br /&gt;b.  A[Parent(I)] &lt;=A[I] &lt;br /&gt;c.  A[Parent(I)]!=A[I] &lt;br /&gt;d.  None of the above &lt;br /&gt;      Ans.  a&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;8.If a max heap is implemented using a partially filled array called data, and the array contains n elements (n &gt; 0), where is the entry with the greatest value? (most appropriate answer) &lt;br /&gt;a.  data[0] &lt;br /&gt;b.  data[n-1] &lt;br /&gt;c.  data[n] &lt;br /&gt;d.  data[2*n + 1] &lt;br /&gt;e.  data[2*n + 2] &lt;br /&gt;     Ans.  a&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;9.What is the worst-case time for heapsort to sort an array of n elements? &lt;br /&gt;a.  O(log n) &lt;br /&gt;b.  O(n) &lt;br /&gt;c.  O(n log n) &lt;br /&gt;d.  O(n²) &lt;br /&gt;     Ans.   c&lt;br /&gt;&lt;br /&gt;10.The frequency count for heapify process is(all logarithms are to the base 2)&lt;br /&gt; a.log n&lt;br /&gt; b.n log n&lt;br /&gt; c.n*n &lt;br /&gt; d.none&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;11. The frequency count for heap sort process is(all logarithms are to the base 2)&lt;br /&gt; a.log n&lt;br /&gt; b.n log n&lt;br /&gt; c.n*n &lt;br /&gt; d.none&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;12.The process of converting an array into a heap by executing heapify progressively closer to the root is called _________&lt;br /&gt;Ans:build-heap&lt;br /&gt;13.For an array of n nodes, build heap takes _______ time&lt;br /&gt;A.O(logn)&lt;br /&gt;b.O(n)&lt;br /&gt;c.O(nlogn)&lt;br /&gt;d.none&lt;br /&gt;Ans:b&lt;br /&gt;14. The Time Complexity of the Huffman code generation algorithm, when the forest is represented as a minHeap is: &lt;br /&gt;(i) O(n² ) &lt;br /&gt;(ii) O(log n) &lt;br /&gt;(iii) O(n log n) &lt;br /&gt;(iv) O(n) &lt;br /&gt;Answer: O(n log n) where the forest is stored as a minHeap. Each time the minimum element is deleted from the heap it costs log n. Since there are 2 deletions and one insertion during each iteration until the forest is empty,it costs n log n to build the tree. &lt;br /&gt;&lt;br /&gt;15. The Time Complexity to list all the elements in a Heap is &lt;br /&gt;(i) O(log n) &lt;br /&gt;(ii) O(n log n) &lt;br /&gt;(iii) O(1) &lt;br /&gt;(iv) O(n) &lt;br /&gt;Answer: Perform any order traversal of the tree - cost is O(n) &lt;br /&gt;&lt;br /&gt;16. Draw the min-max heap after insertion of the following sequence of numbers 6, 3, 2, 5, 1, 1, 3. &lt;br /&gt;Answer: &lt;br /&gt;Order of nodes is: &lt;br /&gt;level 1: 1 &lt;br /&gt;Level 2: 6 3 &lt;br /&gt;Level 3: 5 2 1 3&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-2623944663851109312?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/2623944663851109312/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=2623944663851109312' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2623944663851109312'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2623944663851109312'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/heap-sort-interview-question-part-1.html' title='Heap Sort Interview Question Part 1'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-4810617556664874628</id><published>2007-10-27T10:15:00.001-07:00</published><updated>2007-10-27T10:15:21.231-07:00</updated><title type='text'>Graphs Interview Questions Part 7</title><content type='html'>62. Given the graph ,the resulting breadth-first traversal will be&lt;br /&gt;         &lt;br /&gt; &lt;br /&gt; &lt;br /&gt;           a. ABCDEFGH&lt;br /&gt;           b. ACDGBFEH &lt;br /&gt;           c. ACDBEFGH&lt;br /&gt;           d. ACDGBEFH&lt;br /&gt;Ans. b&lt;br /&gt; Refer pg-565 fig.b of Data Structures Using C and C++ by Tanenbaum       &lt;br /&gt;&lt;br /&gt;63. Using adjacency matrix representation,the efficiency of breadth-first search is&lt;br /&gt;a. O(n+n²) or O(n²)&lt;br /&gt;b. O(e)&lt;br /&gt;c. O(n)&lt;br /&gt;d. O(n+e)&lt;br /&gt;Where n is the number of graph nodes and e is the number of edges in the graph   &lt;br /&gt; Ans. a&lt;br /&gt;&lt;br /&gt;64. Using adjacency list representation,the efficiency of breadth-first traversal is&lt;br /&gt;a. O(n+n²)&lt;br /&gt;b. O(e)&lt;br /&gt;c. O(n)&lt;br /&gt;d. O(n+e)&lt;br /&gt;Ans. d&lt;br /&gt;Traversing all successors of all nodes is O(e) and assuming that the graph nodes are organized as an array or a linked list ,visiting all n nodes is O(n).hence,efficiency is O(n+e).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;65. The adjacency matrix representation size is equal to the number of nodes available in the graph.(T/F)&lt;br /&gt;Ans:True&lt;br /&gt;&lt;br /&gt;66.A weighted graph has a weight/cost of construction for&lt;br /&gt;a.no edge&lt;br /&gt;b.1 edge&lt;br /&gt;c.2 edges&lt;br /&gt;d.each edge&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;67.The adjacency matrix representation mat[i][j] has a value ____ when there is an edge from ith to jth node&lt;br /&gt;a.0&lt;br /&gt;b.1&lt;br /&gt;c.2&lt;br /&gt;d.can be any value&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;68. The adjacency matrix representation mat[i][j] has a value ____ when there is no edge from ith to jth node&lt;br /&gt;a.0&lt;br /&gt;b.1&lt;br /&gt;c.2&lt;br /&gt;d.can be any value&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;69. If there is a solution breadth-first search will find it regardless of the kind of graph. However, if the graph is infinite and there is no solution breadth-first search will diverge.What does this property mean?&lt;br /&gt; a. BFS is complete&lt;br /&gt; b. BFS is incomplete&lt;br /&gt; c. BFS is optimal&lt;br /&gt; d. BFS implements queue&lt;br /&gt;Ans. a&lt;br /&gt; Breadth-first search is complete. This means that if there is a solution breadth-first search will find it regardless of the kind of graph. However, if the graph is infinite and there is no solution breadth-first search will diverge.&lt;br /&gt;70. Breadth-first search is _______ since it always returns the result with the fewest edges between the start node and the goal node.&lt;br /&gt;a. optimal&lt;br /&gt;b. not optimal  &lt;br /&gt;c. complete&lt;br /&gt;d. incomplete&lt;br /&gt;Ans. b&lt;br /&gt;In general breadth-first search is not optimal since it always returns the result with the fewest edges between the start node and the goal node. If the graph is a weighted graph and therefore has costs associated with each step a goal next to the start does not have to be the cheapest goal available.&lt;br /&gt;71. _________ is a good technique for graph when there are many possible solutions, and you only want one.&lt;br /&gt; a. Breadth first search&lt;br /&gt; b. Depth first search&lt;br /&gt; c. Postorder&lt;br /&gt; d. Inorder&lt;br /&gt;Ans. b&lt;br /&gt;Depth first search is good when there are many possible solutions, and you only want one (and you don't care which one). It may be less appropriate when there is only one solution, or if you want the shortest one.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-4810617556664874628?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/4810617556664874628/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=4810617556664874628' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4810617556664874628'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4810617556664874628'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/graphs-interview-questions-part-7.html' title='Graphs Interview Questions Part 7'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-1852756521380996022</id><published>2007-10-27T10:14:00.003-07:00</published><updated>2007-10-27T10:14:50.348-07:00</updated><title type='text'>Graphs Interview Questions Part 6</title><content type='html'>49. Determining the shortest path from every vertex to every other vertex in a weighted graph (with non-negative weights) using Dijkstra's algorithm takes O(V3) time. (T/F)&lt;br /&gt;Ans. True -- determining the shortest path from a single vertex s to every other vertex takes O(V2) time.  So determining the shortest path for every vertex will take O(V3) time.&lt;br /&gt;51. Which one of the following is a faster technique to test if (x,y) is in a graph?&lt;br /&gt;a. adjacency list&lt;br /&gt;b. adjacency matrix&lt;br /&gt;c. Kruskal’s algorithm&lt;br /&gt;d. Dijkstra’s algorithm&lt;br /&gt;Ans. b&lt;br /&gt;&lt;br /&gt;52. Adjacency lists are faster to find the degree of a vertex as compared to adjacency matrix. True or False&lt;br /&gt;   Ans. True&lt;br /&gt;&lt;br /&gt;53. _________ is a graph representation that occupies less memory on small graphs.&lt;br /&gt;a. forest&lt;br /&gt;b. adjacency list&lt;br /&gt;c. adjacency matrix&lt;br /&gt;d. tree&lt;br /&gt;Ans. b because for adjacency list its (m+n) whereas for matrix its n^2.&lt;br /&gt;&lt;br /&gt;54. _________ is a graph representation that occupies less memory on big graphs.&lt;br /&gt;a. adjacency matrix&lt;br /&gt;b. adjacency list&lt;br /&gt;c. forest&lt;br /&gt;d. queue&lt;br /&gt;Ans. a&lt;br /&gt;&lt;br /&gt;55. Faster traversal in a graph is possible in which representation?&lt;br /&gt;a.  forest&lt;br /&gt;b. adjacency list&lt;br /&gt;c. adjacency matrix&lt;br /&gt;d. tree&lt;br /&gt;Ans. b&lt;br /&gt;                  adjacency lists  vs. adjacency matrix &lt;br /&gt;56. Edge insertion or deletion is better in adjacency matrices as compared to adjacency list. (True or False)&lt;br /&gt;Ans. True&lt;br /&gt;adjacency matrices O(1) vs. O(d)&lt;br /&gt;&lt;br /&gt;57. Given the graph, the depth-first traversal will be &lt;br /&gt;&lt;br /&gt;a. ACGBEFHD&lt;br /&gt;b. ABCDEFGH&lt;br /&gt;c. ACDBEFHG&lt;br /&gt;d. ACGDEFBH&lt;br /&gt;Ans. a&lt;br /&gt;&lt;br /&gt;58. Given the following graph,the resulting depth-first traversal will be&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;                                                          a. BEFGHCAD b. BFEGHCAD c. BEGHFCAD d. BEFHGCAD&lt;br /&gt;         Ans. a&lt;br /&gt;&lt;br /&gt;       Refer Pg-565 for the resulting tree (Data Structures Using C and C++ by Tanenbaum)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;59. Depth-first traversal method in a graph&lt;br /&gt;i. creates a spanning forest&lt;br /&gt;ii. can be used to determine if an undirected graph is connected&lt;br /&gt;iii. to identify the connected components of an undirected graph&lt;br /&gt;The correct options are&lt;br /&gt;a. i only&lt;br /&gt;b. i and ii only&lt;br /&gt;c. ii only&lt;br /&gt;d. i,ii and iii&lt;br /&gt;Ans. d&lt;br /&gt;&lt;br /&gt;60. Using adjacency matrix representation,the efficiency of depth-first search is&lt;br /&gt;a. O(n+n²) or O(n²)&lt;br /&gt;b. O(e)&lt;br /&gt;c. O(n)&lt;br /&gt;d. O(n+e)&lt;br /&gt;Where n is the number of graph nodes and e is the number of edges in the graph.&lt;br /&gt;Ans. a&lt;br /&gt;Refer Pg-573 of Data Structures in c and C++ by tanenbaum&lt;br /&gt;61. Using adjacency list representation,the efficiency of depth-first traversal is&lt;br /&gt;a. O(n+n²)&lt;br /&gt;b. O(e)&lt;br /&gt;c. O(n)&lt;br /&gt;d. O(n+e)&lt;br /&gt;Ans. d&lt;br /&gt;Traversing all successors of all nodes is O(e) and assuming that the graph nodes are organized as an array or a linked list ,visiting all n nodes is O(n).hence,efficiency is O(n+e).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-1852756521380996022?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/1852756521380996022/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=1852756521380996022' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/1852756521380996022'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/1852756521380996022'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/graphs-interview-questions-part-6.html' title='Graphs Interview Questions Part 6'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-6770705941393134114</id><published>2007-10-27T10:14:00.001-07:00</published><updated>2007-10-27T10:14:15.995-07:00</updated><title type='text'>Graphs Interview Questions Part 5</title><content type='html'>36. A structure for representing a graph in which the presence of arcs between nodes is is indicated by an entry in a matrix is ________&lt;br /&gt;           a. Breadth-first search&lt;br /&gt;           b. Depth-first search&lt;br /&gt;           c. Adjacency matrix&lt;br /&gt;           d. Adjacency list&lt;br /&gt;          Ans. c&lt;br /&gt;&lt;br /&gt;         37. A structure for representing a graph in which the arcs are stored as lists of connections between nodes is ________&lt;br /&gt;           a. Breadth-first search&lt;br /&gt;           b. Depth-first search&lt;br /&gt;           c. Adjacency matrix&lt;br /&gt;           d. Adjacency list&lt;br /&gt;         Ans. d&lt;br /&gt;&lt;br /&gt;          38. The amount of  space required to store an adjacency-matrix is ____ where V is a vertex set whose elements are vertices.&lt;br /&gt;           a. O(V)&lt;br /&gt;           b. O(V+E)&lt;br /&gt;           c. O(V²)&lt;br /&gt;           d. O(V*E)&lt;br /&gt;         Ans. c&lt;br /&gt;&lt;br /&gt;39. Any edge in an adjacency matrix representation can be accessed,added or removed in ______ time.&lt;br /&gt;           a. O(V)&lt;br /&gt;           b. O(1)&lt;br /&gt;           c. O(E)&lt;br /&gt;           d. O(V²)&lt;br /&gt;          Ans. b&lt;br /&gt;&lt;br /&gt;40. For sparse graphs,the amount of memory required to store an adjacency list is ______&lt;br /&gt;              a. O(V)&lt;br /&gt;              b. O(V²)&lt;br /&gt;              c. O(V+E)&lt;br /&gt;              d. O(V*E)&lt;br /&gt;            Ans. c&lt;br /&gt;&lt;br /&gt;           41. A technique that picks the next adjacent unvisited vertex until reaching a vertex that has no unvisited adjacent vertices is ________&lt;br /&gt;           a. Breadth-first search&lt;br /&gt;           b. Depth-first search&lt;br /&gt;           c. Adjacency matrix&lt;br /&gt;           d. Adjacency list&lt;br /&gt;Ans. b&lt;br /&gt;&lt;br /&gt;42. Consider the graph represented by the following adjacency list:&lt;br /&gt;1: 2—3—6&lt;br /&gt;2: 5—1—3&lt;br /&gt;3: 2—1—7—5—6&lt;br /&gt;4: 5—7&lt;br /&gt;5: 2—4—3—6&lt;br /&gt;6: 3—5—1&lt;br /&gt;7: 3—4&lt;br /&gt;Perform a Breadth First Search in the graph starting from node 1 and processing the&lt;br /&gt;edges adjacent to a node in the order they appear in the adjacency list.&lt;br /&gt;What is the order in which the nodes are visited?&lt;br /&gt;a) 1,2,3,6,4,7,5&lt;br /&gt;b) 1,2,3,6,7,5,4&lt;br /&gt;c) 1,2,3,6,5,4,7&lt;br /&gt;d) 1,2,3,6,5,7,4 &lt;br /&gt;e) 1,2,3,6,7,4,5&lt;br /&gt;Ans. d&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;44. If you perform a Depth First Search in a binary tree, what traversal will you obtain?&lt;br /&gt;a) pre-order &lt;br /&gt;b) in-order&lt;br /&gt;c) post-order&lt;br /&gt;d) Eulerian&lt;br /&gt;Ans. a&lt;br /&gt;&lt;br /&gt;45. Given a graph G with n nodes, you want to find the node that has maximum degree.&lt;br /&gt;What would be the complexity using an adjacency matrix?&lt;br /&gt;a) O(1)    b) O(log n)    c) O(n)       d) O(n log n)         e) O(n2) &lt;br /&gt;Ans. e&lt;br /&gt;&lt;br /&gt;46. Given a graph G with n nodes and m edges, you want to find all the nodes with&lt;br /&gt;degree 5. What would be the complexity using an adjacency list (where the degree of&lt;br /&gt;each node is not stored)?&lt;br /&gt;a) O(n)          b) O(log m)          c) O(log n)        d) O(m)          e) O(n logn )&lt;br /&gt;Ans. d&lt;br /&gt;&lt;br /&gt;47. Which of the following statements is incorrect?&lt;br /&gt;a) A tree with n nodes has n-1 edges&lt;br /&gt;b) Dijkstra does not work if some weights are negative &lt;br /&gt;c) BSF finds whether a graph is connected&lt;br /&gt;d) All nodes in a graph must have degree at least 1&lt;br /&gt;Ans. d&lt;br /&gt;&lt;br /&gt;48.Depth first search of a graph is&lt;br /&gt;i.recursive&lt;br /&gt;ii.can be parallelized&lt;br /&gt;a.only I  b.only ii   c.i and ii  d.neither I nor ii&lt;br /&gt;Ans:a&lt;br /&gt;Some problems have no parallel algorithms, and are called inherently serial problems. Those problems cannot be solved faster by employing more processors. One such example is depth-first search of a graph, which happens to be recursive, but can not be parallelized&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-6770705941393134114?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/6770705941393134114/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=6770705941393134114' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/6770705941393134114'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/6770705941393134114'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/graphs-interview-questions-part-5.html' title='Graphs Interview Questions Part 5'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-5593437220169417717</id><published>2007-10-27T10:13:00.001-07:00</published><updated>2007-10-27T10:13:38.850-07:00</updated><title type='text'>Graphs Interview Questions Part 4</title><content type='html'>23. For the following graph, using breadth first search, which of the following elements are present at level 3&lt;br /&gt; &lt;br /&gt;a.8,6    b.4,5   c.8,7,6   d.2,3&lt;br /&gt;Ans:a&lt;br /&gt;24. For the following graph, using breadth first search, which of the following elements are present at level 4&lt;br /&gt; &lt;br /&gt;a.8,7,6    b.4,5   c.8,6   d.7&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;25. Depth first search is another way of traversing graphs, which is closely related to preorder traversal of a tree.(T/F)&lt;br /&gt;Ans:True&lt;br /&gt;26.Choose the right statement from the following&lt;br /&gt;a.Depth first search is closely related to traveling salesman problem&lt;br /&gt;b. Breadth first search is closely related to traveling salesman problem&lt;br /&gt;c. Breadth first search can be thought of as being like Dijkstra's algorithm for shortest paths&lt;br /&gt;d. Depth first search can be thought of as being like Dijkstra's algorithm for shortest paths&lt;br /&gt;Ans:a,c&lt;br /&gt;27. Depth First Search is a generalization of the ________. &lt;br /&gt;a.Inorder traversal &lt;br /&gt;bPreorder traversal &lt;br /&gt;c.Postorder traversal &lt;br /&gt;d.none&lt;br /&gt;Ans:b&lt;br /&gt;28. For a graph with n nodes to be Cyclic, the minimum number of edges required are________.     &lt;br /&gt;a.n/2&lt;br /&gt;b.n+1&lt;br /&gt;c.n-1&lt;br /&gt;d.n&lt;br /&gt;Ans:d&lt;br /&gt;29. For a Graph with v nodes and e edges, the running time of DFS is given by ________.&lt;br /&gt;a.O(|V| + |E|)&lt;br /&gt;b. O(|E|)&lt;br /&gt;c. O(|V| )&lt;br /&gt;d. O(|V| log |E|)&lt;br /&gt;Ans:a&lt;br /&gt;30. Breadth First Search algorithm can be used in Prim's MST algorithm. (T/F)&lt;br /&gt;Ans:True&lt;br /&gt;31. Breadth First Search algorithm cannot be used in Dijkstra’s single source shortest path algorithm. (T/F)&lt;br /&gt;Ans:False&lt;br /&gt;&lt;br /&gt;32. A graph with V vertices and E edges can be represented with an adjacency matrix using O(V2) space. (T/F)&lt;br /&gt;true. &lt;br /&gt;&lt;br /&gt;33. Consider the following pseudo code.&lt;br /&gt; void PQR(Vertex v)&lt;br /&gt; { v.visited = true ;&lt;br /&gt;   For each w adjacent to v&lt;br /&gt;       if (!w.visited)&lt;br /&gt;     PQR(w); }&lt;br /&gt;Which of the following is/are it intended to do?&lt;br /&gt;a. Finding the adjacency matrix&lt;br /&gt;b. Depth first search&lt;br /&gt;c. Finding the path matrix&lt;br /&gt;d. Breadth first search&lt;br /&gt;e. Calculating the shortest path&lt;br /&gt;Ans. Depth first search&lt;br /&gt;34. Depth first search is a generalization of&lt;br /&gt;  a. Inorder traversal&lt;br /&gt;  b. Preorder traversal&lt;br /&gt;  c. Postorder traversal&lt;br /&gt;  d. none of the above&lt;br /&gt; Ans. b&lt;br /&gt;&lt;br /&gt;35. Traversing a graph by visiting all the nodes attached directly to a starting node first  is called ___________&lt;br /&gt;   a. Depth-first search&lt;br /&gt;   b. Breadth-first search&lt;br /&gt;   c. Adjacency list&lt;br /&gt;   d. Adjacency matrix&lt;br /&gt;Ans. b&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-5593437220169417717?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/5593437220169417717/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=5593437220169417717' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5593437220169417717'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5593437220169417717'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/graphs-interview-questions-part-4.html' title='Graphs Interview Questions Part 4'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-1996204365004590144</id><published>2007-10-27T10:12:00.001-07:00</published><updated>2007-10-27T10:12:57.013-07:00</updated><title type='text'>Graphs Interview Questions Part 3</title><content type='html'>18. Time complexity of breadth-first search where v is the no. of nodes and e is the no. of edges is &lt;br /&gt;a.O(|V| + |E|)&lt;br /&gt;b. O(|E|)&lt;br /&gt;c. O(|V| )&lt;br /&gt;d. O(|V| log |E|)&lt;br /&gt;Ans:a&lt;br /&gt;Since in the worst case breadth-first search has to consider all paths to all possible nodes the time complexity of breadth-first search is O(|V| + |E|) where |V| is the number of nodes and |E| the number of edges in the graph.&lt;br /&gt;19. Applications of BFS are&lt;br /&gt;a.Finding all connected components in a graph. &lt;br /&gt;b.Finding all nodes within one connected component &lt;br /&gt;c.Finding the shortest path between two nodes u and v (unweighted nodes) &lt;br /&gt;      d.All the above&lt;br /&gt;Ans:d&lt;br /&gt;20.For the following graph, using breadth first search, which of the following elements are present at level 0&lt;br /&gt; &lt;br /&gt;a.1,2,3    b.1   c.1,2   d.2,3&lt;br /&gt;Ans:b&lt;br /&gt;21. For the following graph, using breadth first search, which of the following elements are present at level 1&lt;br /&gt; &lt;br /&gt;a.1,2,3    b.1   c.1,2   d.2,3&lt;br /&gt;Ans:d&lt;br /&gt;22. For the following graph, using breadth first search, which of the following elements are present at level 2&lt;br /&gt; &lt;br /&gt;a.1,2,3    b.4,5   c.3,4,5   d.2,3&lt;br /&gt;Ans:b&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-1996204365004590144?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/1996204365004590144/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=1996204365004590144' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/1996204365004590144'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/1996204365004590144'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/graphs-interview-questions-part-3.html' title='Graphs Interview Questions Part 3'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-4088925736778972476</id><published>2007-10-27T10:11:00.000-07:00</published><updated>2007-10-27T10:12:33.833-07:00</updated><title type='text'>Graphs Interview Questions Part 2</title><content type='html'>10. For the following graph:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;a depth-first search starting at A, assuming that the left edges in the shown graph are chosen before right edges, and assuming the search remembers previously-visited nodes and will not repeat them, will visit the nodes in the following order:&lt;br /&gt;a. A, B, D, F, E, C, G b. A, B, C, F, E, D, G c. A, B, D, E, F, C, G d. A, B, D, F, E, G, C&lt;br /&gt;Ans:a&lt;br /&gt;11. For the following graph:&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Performing the depth first search without remembering previously visited nodes results in visiting nodes in the order &lt;br /&gt;a. B , A, D, F, E, B , A , D, F, E, etc. forever&lt;br /&gt;b. A, D,B, F, E, A, D , B , F, E, etc. forever&lt;br /&gt;c. A, B, D, E, F, A, B, D, E , F etc. forever&lt;br /&gt;d. A, B, D, F, E, A, B, D, F, E, etc. forever&lt;br /&gt;Ans:d&lt;br /&gt;Performing the same search without remembering previously visited nodes results in visiting nodes in the order A, B, D, F, E, A, B, D, F, E, etc. forever, caught in the A, B, D, F, E cycle and never reaching C or G.&lt;br /&gt;12. code(graph G)&lt;br /&gt;{&lt;br /&gt;  list L = empty&lt;br /&gt;  tree T = empty&lt;br /&gt;  choose a starting vertex x&lt;br /&gt;  search(x)&lt;br /&gt;  while(L is not full)&lt;br /&gt;    remove edge (v, w) from end of L&lt;br /&gt;    if w not yet visited&lt;br /&gt;    {&lt;br /&gt;      add (v, w) to T&lt;br /&gt;      search(w)&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;   &lt;br /&gt;search(vertex v)&lt;br /&gt;{&lt;br /&gt;  visit v&lt;br /&gt;  for each edge (v, w)&lt;br /&gt;    add edge (v, w) to end of L&lt;br /&gt;}&lt;br /&gt;The code here can represent&lt;br /&gt;a.Depth first search&lt;br /&gt;b.Breadth first seach&lt;br /&gt;c.Prim’s algorithm&lt;br /&gt;d.Kruskal’s algorithm&lt;br /&gt;Ans:a                                 Level:3&lt;br /&gt;&lt;br /&gt;13. function (Start, Goal) { &lt;br /&gt;    Push(Stack,Start)&lt;br /&gt;    while notEmpty(Stack) {&lt;br /&gt;        Node := Pop(Stack)&lt;br /&gt;        if Node = Goal {&lt;br /&gt;            return Node /*the code below does not get executed*/&lt;br /&gt;        }&lt;br /&gt;        for each Child in Expand(Node) {&lt;br /&gt;            if notVisited(Child) {&lt;br /&gt;                setVisited(Child)&lt;br /&gt;                Push(Stack, Child)&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;The function here can represent&lt;br /&gt;a.Depth first search&lt;br /&gt;b.Breadth first seach&lt;br /&gt;c.Prim’s algorithm&lt;br /&gt;d.Kruskal’s algorithm&lt;br /&gt;Ans:a                                      Level:3&lt;br /&gt;&lt;br /&gt;14.The following algorithm represents&lt;br /&gt;1. Put the starting node (the root node) in the queue. &lt;br /&gt;2. Pull a node from the beginning of the queue and examine it. &lt;br /&gt;o If the searched element is found in this node, quit the search and return a result. &lt;br /&gt;o Otherwise push all the (so-far-unexamined) successors of this node into the end of the queue, if there are any. &lt;br /&gt;3. If the queue is empty, every node on the graph has been examined -- quit the search and return "not found". &lt;br /&gt;4. repeat from step 2. &lt;br /&gt;a.Depth first search&lt;br /&gt;b.Breadth first seach&lt;br /&gt;c.Prim’s algorithm&lt;br /&gt;d.Kruskal’s algorithm&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;15. function (Start, Goal) { &lt;br /&gt;    enqueue(Queue,Start)&lt;br /&gt;    while notEmpty(Queue) {&lt;br /&gt;        Node := dequeue(Queue)&lt;br /&gt;        if Node = Goal {&lt;br /&gt;            return Node /*the code below does not get executed*/&lt;br /&gt;        }&lt;br /&gt;        for each Child in Expand(Node) {&lt;br /&gt;            if notVisited(Child) {&lt;br /&gt;                setVisited(Child)&lt;br /&gt;                enqueue(Queue, Child)&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The function here can represent&lt;br /&gt;a.Depth first search&lt;br /&gt;b.Breadth first seach&lt;br /&gt;c.Prim’s algorithm&lt;br /&gt;d.Kruskal’s algorithm&lt;br /&gt;Ans:b&lt;br /&gt;16. The immense demand for space is the reason why breadth-first search is impractical for larger problems(T/F)&lt;br /&gt;Ans:True&lt;br /&gt;17. Space complexity of breadth-first search where v is the no. of nodes and e is the no. of edges is &lt;br /&gt;a.O(|V| + |E|)&lt;br /&gt;b. O(|E|)&lt;br /&gt;c. O(|V| )&lt;br /&gt;d. O(|V| log |E|)&lt;br /&gt;Ans:a&lt;br /&gt;Since all nodes discovered so far have to be saved, the space complexity of breadth-first search is O(|V| + |E|) where |V| is the number of nodes and |E| the number of edges in the graph&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-4088925736778972476?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/4088925736778972476/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=4088925736778972476' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4088925736778972476'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4088925736778972476'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/graphs-interview-questions-part-2.html' title='Graphs Interview Questions Part 2'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-4804631394276191070</id><published>2007-10-27T10:10:00.000-07:00</published><updated>2007-10-27T10:11:06.640-07:00</updated><title type='text'>Graphs Interview Questions Part 1</title><content type='html'>1.Any search algorithm that considers outgoing edges of a vertex before any neighbors of the vertex, that is, outgoing edges of the vertex's predecessor in the search, where extremes are searched first is called&lt;br /&gt;a.Depth first search&lt;br /&gt;b.Breadth first seach&lt;br /&gt;c.Prim’s algorithm&lt;br /&gt;d.Kruskal’s algorithm&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;2. Depth first search can be implemented with recursion.(T/F)&lt;br /&gt;Ans:True&lt;br /&gt;&lt;br /&gt;3. A search algorithm that considers neighbors of a vertex, that is, outgoing edges of the vertex's predecessor in the search, before any outgoing edges of the vertex, where extremes are searched last is called&lt;br /&gt;a.Depth first search&lt;br /&gt;b.Breadth first seach&lt;br /&gt;c.Prim’s algorithm&lt;br /&gt;d.Kruskal’s algorithm&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;4. Depth first search can be implemented with&lt;br /&gt;a.stack&lt;br /&gt;b.queue&lt;br /&gt;c.tree&lt;br /&gt;d.priority queue&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;5. Breadth first search can be implemented with&lt;br /&gt;a.stack&lt;br /&gt;b.queue&lt;br /&gt;c.tree&lt;br /&gt;d.forest&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;6. For tree search, depth first search tends to require_____ memory, as compared to breadth first search.&lt;br /&gt;a.less&lt;br /&gt;b.more&lt;br /&gt;c.same&lt;br /&gt;d.cannot say&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;For tree search at least, depth first search tends to require less memory, as you only need to record nodes on the `current' path. If there are lots of solutions, but all at a comparable `depth' in the tree, then you may hit on a solution having only explored a very small part of the tree.&lt;br /&gt;&lt;br /&gt;7. __________ may use more memory, but will not get stuck in blind alleys, and will always find the shortest path first (or at least, the path that involves the least number of steps).&lt;br /&gt;a.Depth first search&lt;br /&gt;b.Breadth first seach&lt;br /&gt;c.Prim’s algorithm&lt;br /&gt;d.Kruskal’s algorithm&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;Breadth first search may use more memory, but will not get stuck in blind alleys, and will always find the shortest path first (or at least, the path that involves the least number of steps). It may be more appropriate when exploring very large search spaces where there is an expected solution which takes a relatively small number of steps, or when you are interested in all the solutions (perhaps up to some depth limit).&lt;br /&gt;&lt;br /&gt;8.What is the output of pre-order traversal using DFS for the given graph&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;a. 1 2 3 4 8 7 5 6  b. 1 2 3 4 7 8 6 5 c.1 2 3 4 8 7 6 5 d. 1 2 3 4 8 6 7 5&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;http://www.cs.duke.edu/csed/jawaa/DFSanim.html&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;9. What is the output of post-order traversal using DFS for the given graph&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;a. 2 7 8 5 6 4 1 3 b.2 7 8 5 6 4 3 1 c. 2 7 8 5 4 6 3 1 d. 2 7 5 8 6 4 3 1&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;http://www.cs.duke.edu/csed/jawaa/DFSanim.html&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-4804631394276191070?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/4804631394276191070/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=4804631394276191070' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4804631394276191070'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4804631394276191070'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/graphs-interview-questions-part-1.html' title='Graphs Interview Questions Part 1'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-624190442139746602</id><published>2007-10-27T10:09:00.001-07:00</published><updated>2007-10-27T10:09:38.087-07:00</updated><title type='text'>Bubble Sort Interview Question Part 4</title><content type='html'>32. What is the output of bubble sort after the 5th pass given the following sequence of numbers: 25 57 48 37 12 92 86 33 23 15&lt;br /&gt;a. 48 25 37 12 57 86 33 92  23 15&lt;br /&gt;b. 25  48 37 12 57 86 33 23 15 92&lt;br /&gt;c. 12 25 33  23 15 37 48 57  86 92 &lt;br /&gt;d. 25 12 37 33 23 15 48 57 86 92&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;33. What is the output of bubble sort after the 6th pass given the following sequence of numbers: 25 57 48 37 12 92 86 33 23 15&lt;br /&gt;a. 48 25 37 12 57 86 33 92  23 15&lt;br /&gt;b. 12 25  23 15 33 37 48 57 86 92 &lt;br /&gt;c. 12 25 33  23 15 37 48 57 86 92 &lt;br /&gt;d. 25 12 37 33 23 15 48 57 86 92&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;34. What is the output of bubble sort after the 7th pass given the following sequence of numbers: 25 57 48 37 12 92 86 33 23 15&lt;br /&gt;a. 12  23 15  25  33 37 48  57  86  92 &lt;br /&gt;b. 12 25  23 15  33 37 48  57  86  92 &lt;br /&gt;c. 12 25  33  23  15 37 48  57  86 92 &lt;br /&gt;d. 25  12  37  33 23 15 48 57 86  92&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;35. What is the output of bubble sort after the 8th pass given the following sequence of numbers: 25 57 48 37 12 92 86 33 23 15&lt;br /&gt;a. 12  15  23    25  33 37 48  57  86  92 &lt;br /&gt;b. 12 25  23   15  33 37 48  57  86  92 &lt;br /&gt;c. 12 25   33  23  15 37 48  57  86  92 &lt;br /&gt;d. 25  12  37   33 23 15 48 57 86  92&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;36. What is the output of bubble sort after the 1st pass given the following sequence of numbers: 7 3 5 1 9 8 4 6&lt;br /&gt;a. 3 5 1 7 8 4 6 9&lt;br /&gt;b. 3 1 5 7 4 6 8 9&lt;br /&gt;c. 1 3 5 4 6 7 8 9&lt;br /&gt;d. 1 3 4 5 6 7 8 9&lt;br /&gt;&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;37. What is the output of bubble sort after the 2nd pass given the following sequence of numbers: 7 3 5 1 9 8 4 6&lt;br /&gt;a. 3 5 1 7 8 4 6 9&lt;br /&gt;b. 3 1 5 7 4 6 8 9&lt;br /&gt;c. 1 3 5 4 6 7 8 9&lt;br /&gt;d. 1 3 4 5 6 7 8 9&lt;br /&gt;&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;38. What is the output of bubble sort after the 3rd pass given the following sequence of numbers: 7 3 5 1 9 8 4 6&lt;br /&gt;a. 3 5 1 7 8 4 6 9&lt;br /&gt;b. 3 1 5 7 4 6 8 9&lt;br /&gt;c. 1 3 5 4 6 7 8 9&lt;br /&gt;d. 1 3 4 5 6 7 8 9&lt;br /&gt;&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;39. What is the output of bubble sort after the 4th pass given the following sequence of numbers: 7 3 5 1 9 8 4 6&lt;br /&gt;a. 3 5 1 7 8 4 6 9&lt;br /&gt;b. 3 1 5 7 4 6 8 9&lt;br /&gt;c. 1 3 5 4 6 7 8 9&lt;br /&gt;d. 1 3 4 5 6 7 8 9&lt;br /&gt;&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;40. What is the output of bubble sort after the 5th pass given the following sequence of numbers: 7 3 5 1 9 8 4 6&lt;br /&gt;a. 3 5 1 7 8 4 6 9&lt;br /&gt;b. 3 1 5 7 4 6 8 9&lt;br /&gt;c. 1 3 5 4 6 7 8 9&lt;br /&gt;d. 1 3 4 5 6 7 8 9&lt;br /&gt;&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;41.What will the output after 1st pass when Bubble sorting technique is used on the following set of numbers? 76,36,17,58,45,13, 66, 54&lt;br /&gt;a. 76,17,36,45,66,13,54,58 &lt;br /&gt;b. 17,36,45,66,13,54,76,58&lt;br /&gt;c. 36,17,45,66,13,54,76,58&lt;br /&gt;d. 36,17,58,45,13,66,54,76&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;42. What will the output after 2nd pass when Bubble sorting technique is used on the following set of numbers? 76,36,17,58,45,13, 66, 54&lt;br /&gt;a. 76,17,36,45,66,13,54,58 &lt;br /&gt;b. 17,36,45,13,58,54,66,76&lt;br /&gt;c. 36,17,45,66,13,54,76,58&lt;br /&gt;d. 36,17,58,45,13,66,54,76&lt;br /&gt;Ans: b&lt;br /&gt;&lt;br /&gt;43. What will the output after 3rd pass when Bubble sorting technique is used on the following set of numbers? 76,36,17,58,45,13, 66, 54&lt;br /&gt;a. 76,17,36,45,66,13,54,58 &lt;br /&gt;b. 17,36,13,45,54,58,66,76&lt;br /&gt;c. 36,17,45,66,13,54,76,58&lt;br /&gt;d. 36,17,58,45,13,66,54,76&lt;br /&gt;Ans: b&lt;br /&gt;&lt;br /&gt;44. What will the output after 4th pass when Bubble sorting technique is used on the following set of numbers? 76,36,17,58,45,13, 66, 54&lt;br /&gt;a. 76,17,36,45,66,13,54,58 &lt;br /&gt;b. 17,36,13,45,54,58,66,76&lt;br /&gt;c. 17,13,36,45,54,58,66,76&lt;br /&gt;d. 36,17,58,45,13,66,54,76&lt;br /&gt;Ans: c&lt;br /&gt;&lt;br /&gt;45. What will the output after 5th pass when Bubble sorting technique is used on the following set of numbers? 76,36,17,58,45,13, 66, 54&lt;br /&gt;a. 76,17,36,45,66,13,54,58 &lt;br /&gt;b. 13,17,36,45,54,58,66,76&lt;br /&gt;c. 17,13,36,45,54,58,66,76&lt;br /&gt;d. 36,17,58,45,13,66,54,76&lt;br /&gt;Ans: b&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-624190442139746602?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/624190442139746602/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=624190442139746602' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/624190442139746602'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/624190442139746602'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/bubble-sort-interview-question-part-4.html' title='Bubble Sort Interview Question Part 4'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-8225199377343884680</id><published>2007-10-27T10:08:00.000-07:00</published><updated>2007-10-27T10:09:01.874-07:00</updated><title type='text'>Bubble Sort Interview Question Part 3</title><content type='html'>24.Bubble sort is also called&lt;br /&gt;a.Exchange sort  b.Sinking sort  c.Both D.none&lt;br /&gt;Ans:c&lt;br /&gt;    25. Which of the following correctly describe(s) the bubble sort algorithm?&lt;br /&gt;      a.   public void bubblesort(int[ ] data) &lt;br /&gt;{ int temp;&lt;br /&gt;                int  i, j ;&lt;br /&gt;                for (i = 1; i &lt; data.length; i++) &lt;br /&gt;                { temp = data[i] ;&lt;br /&gt;                   for (j = i; j&gt;0  temp &lt; data[j – 1]; j--)&lt;br /&gt;data[j] = data[j – 1] ;&lt;br /&gt;                    data[j] = temp ;  }  }&lt;br /&gt;      b.     public void bubblesort(object[ ] data) &lt;br /&gt; { int i, j, least&lt;br /&gt;for ( i = 0; i&lt; data.length;  j++)&lt;br /&gt;if (((comparable[j]).compareTo(data[least])&lt;0)&lt;br /&gt;least = j ;&lt;br /&gt;               swap (data, least,  i); }&lt;br /&gt;      c.      public void bubblesort(object[ ] data)&lt;br /&gt;{ int  i, j &lt;br /&gt;                 for (i = 0; i &lt; data.length-1; i++)&lt;br /&gt;                 for ( j  = data.length-1; j&gt;i; --j )&lt;br /&gt;                 if (((comparable) data[j]).compareTo(data[j-1] &lt;0)&lt;br /&gt;                swap (data, j, j-1) }&lt;br /&gt;      d.      void bubblesort(object[ ] data) &lt;br /&gt; { for (int i = data.length/2 –1;i)&gt; = 0; --i)&lt;br /&gt;    movedown(data. i, data.length – 1) ;&lt;br /&gt;    for (int i = data.length –1; i &gt; = 1 ;--i)&lt;br /&gt;    { swap(data, 0, i)&lt;br /&gt;                movedown(data, 0, i-1) ; }  }&lt;br /&gt;     &lt;br /&gt;&lt;br /&gt;  Ans.  e&lt;br /&gt;&lt;br /&gt;26.The number of nested loops in a bubble sort algorithm&lt;br /&gt;a.1   b.2    c.3    d.4&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;27. Let A be a list of n numbers. Sorting A refers to the operation of re-arranging the elements of A so that they are in increasing order.&lt;br /&gt;&lt;br /&gt;If  A= { 32,  51,  27,  85,  66,  23,  13,  5} and method of sorting is bubble sort, Which is/are the correct intermediate output  values during the process of sorting.&lt;br /&gt;a.23,  13,  5,  27,  32,  51,  66,  85&lt;br /&gt;b.27,  32,  23,  13   ,5,  51  66,  85&lt;br /&gt;c.32,  27,  51,  66,  23,  13,  5,  85&lt;br /&gt;d.32,  51,  85,  27,  66,  23,  13,  5&lt;br /&gt;Ans:a,c,d,&lt;br /&gt;&lt;br /&gt;28. What is the output of bubble sort after the 1st pass given the following sequence of numbers: 25 57 48 37 12 92 86 33 23 15&lt;br /&gt;a. 48 25 37 12 57 86 33 92  23 15&lt;br /&gt;b. 25  48 37 12 57 86 33 23 15 92&lt;br /&gt;c.12 25 33 37 48 57 86 92  23 15&lt;br /&gt;d. 25 57 37 48 12 92 33 86 23 15&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;29. What is the output of bubble sort after the 2nd pass given the following sequence of numbers: 25 57 48 37 12 92 86 33 23 15&lt;br /&gt;a. 48 25 37 12 57 86 33 92  23 15&lt;br /&gt;b. 25  48 37 12 57 86 33 23 15 92&lt;br /&gt;c. 25  37 12 48 57 33 23 15 86  92&lt;br /&gt;d. 25 57 37 48 12 92 33 86 23 15&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;30. What is the output of bubble sort after the 3rd pass given the following sequence of numbers: 25 57 48 37 12 92 86 33 23 15&lt;br /&gt;a. 48 25 37 12 57 86 33 92  23 15&lt;br /&gt;b. 25  48 37 12 57 86 33 23 15 92&lt;br /&gt;c. 25   37 12 48 57 33 23 15 86  92&lt;br /&gt;d. 25   37 12 48  33 23 15 57 86  92&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;31. What is the output of bubble sort after the 4th pass given the following sequence of numbers: 25 57 48 37 12 92 86 33 23 15&lt;br /&gt;a. 48 25 37 12 57 86 33 92  23 15&lt;br /&gt;b. 25  48 37 12 57 86 33 23 15 92&lt;br /&gt;c. 25   37 12 48 57 33 23 15 86  92&lt;br /&gt;d. 25  12  37   33 23 15 48 57 86  92&lt;br /&gt;Ans:d&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-8225199377343884680?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/8225199377343884680/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=8225199377343884680' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/8225199377343884680'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/8225199377343884680'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/bubble-sort-interview-question-part-3.html' title='Bubble Sort Interview Question Part 3'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-2051082658817395880</id><published>2007-10-27T10:07:00.001-07:00</published><updated>2007-10-27T10:07:35.195-07:00</updated><title type='text'>Bubble Sort Interview Question Part 2</title><content type='html'>14.When does the best case for Bubble sort occur?&lt;br /&gt;a. When the numbers are placed in random&lt;br /&gt;b. When the numbers are placed in descending order&lt;br /&gt;c. When the numbers are placed in ascending order &lt;br /&gt;d. When all the numbers are same&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;15.In which cases are the time complexities same in Bubble sort?&lt;br /&gt;a. Worst and Best&lt;br /&gt;b. Best and Average&lt;br /&gt;c. Worst and Average&lt;br /&gt;d. none of the above&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;16.The sort which works by iterating down an array to be sorted from the first element to the last, comparing each pair of elements and switching their positions if necessary is&lt;br /&gt;&lt;br /&gt;a.Merge sort&lt;br /&gt;b.Bubble sort&lt;br /&gt;c.Selection sort&lt;br /&gt;d.none of these&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;17.The most exchanges that will be necessary for bubble sort for an array of length n is&lt;br /&gt;a.n&lt;br /&gt;b.n+1&lt;br /&gt;c.n-1&lt;br /&gt;d.n*n&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;18. The best case order for modified bubble sort  algorithm is &lt;br /&gt;a.O(n)&lt;br /&gt;b.O(n*n)&lt;br /&gt;c.O(nlogn)&lt;br /&gt;d.O(logn)&lt;br /&gt;Ans:a&lt;br /&gt;A better version of bubble sort, known as modified bubble sort, includes a flag that is set if an exchange is made after an entire pass over the array. If no exchange is made, then it should be clear that the array is already in order because no two elements need to be switched. In that case, the sort should end. The new best case order for this algorithm is O(n), as if the array is already sorted, then no exchanges are made. &lt;br /&gt;19. The frequency count of bubble sort is&lt;br /&gt;  a.n*n&lt;br /&gt;  b.n(n-1)/2&lt;br /&gt;  c.n&lt;br /&gt;  d.logn&lt;br /&gt;Ans:b&lt;br /&gt;(n-1)+(n-2)+……+3+2+1=n(n+1)/2 – n =n(n-1)/2&lt;br /&gt;&lt;br /&gt;20.In bubble sort,after the 1st iteration, the element which is at the bottom is&lt;br /&gt;a.the smallest&lt;br /&gt;b.the largest&lt;br /&gt;c.the 2nd largest&lt;br /&gt;d.none&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;21. In bubble sort,after the 2nd iteration, the element which is at the bottom is&lt;br /&gt;a.the smallest&lt;br /&gt;b.the largest&lt;br /&gt;c.the 2nd largest&lt;br /&gt;d.none&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;22.The number of swappings required to sort the numbers 8,22,7,9,31,19,5,13 in ascending order using bubble sort&lt;br /&gt;a.11 b.12 c.13 d.14&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;23.Which of the following sort is known as sinking sort?&lt;br /&gt;a.Bubble sort&lt;br /&gt;b.Selection sort&lt;br /&gt;c.Quick sort&lt;br /&gt;d.none&lt;br /&gt;Ans:a&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-2051082658817395880?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/2051082658817395880/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=2051082658817395880' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2051082658817395880'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2051082658817395880'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/bubble-sort-interview-question-part-2.html' title='Bubble Sort Interview Question Part 2'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-1254254997744272134</id><published>2007-10-27T10:06:00.001-07:00</published><updated>2007-10-27T10:06:54.669-07:00</updated><title type='text'>Bubble Sort Interview Question Part 1</title><content type='html'>1.What is the output of bubble sort after the 1st iteration given the following sequence of numbers: 13  2  9  4  18  45  37  63&lt;br /&gt;a.2   4   9   13  18  37    45  63&lt;br /&gt;b.2   9   4   13  18  37   45   63&lt;br /&gt;c.13  2   4   9    18   45   37  63  &lt;br /&gt;d.2    4   9  13  18   45   37  63&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2.What is the worst case complexity for bubble sort algorithm&lt;br /&gt;  a.O(n)     b.O(n*n)    c.O(nlogn)    d.O(logn)&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;3.What is the average case complexity for bubble sort algorithm&lt;br /&gt;    a.O(n)     b.O(n*n)    c.O(nlogn)    d.O(logn)&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;4.What is the best case complexity for bubble sort algorithm&lt;br /&gt;  a.O(n)     b.O(n*n)    c.O(nlogn)    d.O(logn)&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;5.The following loop is used for&lt;br /&gt;    For i&lt;-  N-1 to 1&lt;br /&gt;      For  j&lt;-  1  to i&lt;br /&gt;        If(a(j)&gt;a(j+1))&lt;br /&gt;         {&lt;br /&gt;            Temp=a(j);&lt;br /&gt;             A(j)=a(j+1);&lt;br /&gt;             A(j+1)=temp;&lt;br /&gt;         }&lt;br /&gt; a.bubble sort b.selection sort c.insertion sort d.merge sort&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;6. What is the output of bubble sort after the 1st iteration given the following sequence of numbers: 25 57 48 37 12 92 86 33&lt;br /&gt;a. 48 25 37 12 57 86 33 92  &lt;br /&gt;b. 25 48 12 37 57 86 33 92  &lt;br /&gt;c.25 48 37 12 57 86 33 92  &lt;br /&gt;d. 25 48 37 12 57 33 86 92  &lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;7.What is the output of bubble sort after the 2nd iteration given the following sequence of numbers: 25 57 48 37 12 92 86 33&lt;br /&gt;a. 48 25 37 12 57 86 33 92  &lt;br /&gt;b. 25 48 12 37 57 86 33 92  &lt;br /&gt;c.25 48 37 12 57 86 33 92  &lt;br /&gt;d. 25 37 12 48 57 33 86 92  &lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;8.What is the output of bubble sort after the 3rd iteration given the following sequence of numbers: 25 57 48 37 12 92 86 33&lt;br /&gt;a. 48 25 37 12 57 86 33 92  &lt;br /&gt;b. 25 12 37 48 33 57 86 92  &lt;br /&gt;c.25 48 37 12 57 86 33 92  &lt;br /&gt;d. 25 37 12 48 57 33 86 92  &lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;9.What is the output of bubble sort after the 4th iteration given the following sequence of numbers: 25 57 48 37 12 92 86 33&lt;br /&gt;a. 48 25 37 12 57 86 33 92  &lt;br /&gt;b. 25 48 12 37 57 86 33 92  &lt;br /&gt;c.25 48 37 12 57 86 33 92  &lt;br /&gt;d. 12 25 37 33 48 57 86 92  &lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;10.What is the output of bubble sort after the 5th iteration given the following sequence of numbers: 25 57 48 37 12 92 86 33&lt;br /&gt;a. 12 25 33 37 48 57 86 92  &lt;br /&gt;b. 25 48 12 37 57 86 33 92  &lt;br /&gt;c.25 48 37 12 57 86 33 92  &lt;br /&gt;d. 25 37 12 48 57 33 86 92  &lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;11.What is the output of bubble sort after the 6th iteration given the following sequence of numbers: 25 57 48 37 12 92 86 33&lt;br /&gt;a. 48 25 37 12 57 86 33 92  &lt;br /&gt;b. 25 48 12 37 57 86 33 92  &lt;br /&gt;c.12 25 33 37 48 57 86 92  &lt;br /&gt;d. 25 37 12 48 57 33 86 92  &lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;12.What is the output of bubble sort after the 7th iteration given the following sequence of numbers: 25 57 48 37 12 92 86 33&lt;br /&gt;a. 48 25 37 12 57 86 33 92  &lt;br /&gt;b. 12 25 33 37 48 57 86 92  &lt;br /&gt;c.12 25 37 33 48 57 86 92  &lt;br /&gt;d. 25 37 12 48 57 33 86 92  &lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;13.When does the worst case for Bubble sort occur?&lt;br /&gt;a. When the numbers are placed in random&lt;br /&gt;b. When the numbers are placed in descending order&lt;br /&gt;c. When the numbers are placed in ascending order &lt;br /&gt;d. When all the numbers are same&lt;br /&gt;Ans:b&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-1254254997744272134?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/1254254997744272134/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=1254254997744272134' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/1254254997744272134'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/1254254997744272134'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/bubble-sort-interview-question-part-1.html' title='Bubble Sort Interview Question Part 1'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-7987017453526846206</id><published>2007-10-27T10:04:00.000-07:00</published><updated>2007-10-27T10:05:56.597-07:00</updated><title type='text'>Binary Search Interview Question Part 2</title><content type='html'>17.Which of the following searching method runs most efficiently utilising the memory       for already sorted file?&lt;br /&gt;a. Binary search&lt;br /&gt;b. Index sequential search&lt;br /&gt;c. Sequential search with array implementation&lt;br /&gt;d. Sequential search with linked list implementation&lt;br /&gt;Ans. a&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;18.To search a single item from a group of 8 sorted items how many checks are required in Binary Search&lt;br /&gt;a.8  b.4   c.3   d.2&lt;br /&gt;Ans:c&lt;br /&gt;Since 2*2*2=8&lt;br /&gt;&lt;br /&gt;19.To search a page number 364 in a book containing 500 pages which of the following Searching technique should be used to reach the page in minimum time?&lt;br /&gt;a.Linear search&lt;br /&gt;b.Fibonacci search&lt;br /&gt;c.Binary search&lt;br /&gt;d.Random search&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;20. Consider the set of integers given below. &lt;br /&gt;&lt;br /&gt; 2,3,5, 7,11, 13, 17 ,19, 23, 29&lt;br /&gt;How many comparisons are required to search when key value is equal to 23 using a binary search algorithm.&lt;br /&gt;a.1  b.2   c.3  d.4&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;First comparison identifies middle element 0+9/2=4.5&lt;br /&gt;4th element is 11.&lt;br /&gt;2nd comparison gives 19 and 3rd 23.&lt;br /&gt;&lt;br /&gt;21.What kind of search is used in a telephone directory?&lt;br /&gt;a.Linear search&lt;br /&gt;b.Binary search&lt;br /&gt;c.Hashing&lt;br /&gt;d.none&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;22. Which of the following statements is/are incorrect in connection with the binary search algorithm?&lt;br /&gt;(a) The most efficient method of searching a sequential table without the use of auxiliary indices or tables is the binary search algorithm.&lt;br /&gt;(b) Basically, the argument is compared with the key of the middle element of the table. If they are equal, the search is successful; otherwise, either the upper half or the lower half of the table must be searched in a similar manner.&lt;br /&gt;(c) Any kind of data set can be used.&lt;br /&gt; (d) Time complexity is O (n log n).&lt;br /&gt;Ans: c&lt;br /&gt;23. Binary search algorithm works best with&lt;br /&gt;a) Arrays&lt;br /&gt;b) trees&lt;br /&gt;c) Binary Search trees&lt;br /&gt;d) None&lt;br /&gt;Ans:c&lt;br /&gt;       &lt;br /&gt;24. What additional requirement is placed on an array, so that binary search may be used to locate an entry? &lt;br /&gt;A. The array elements must form a heap. &lt;br /&gt;B. The array must have at least 2 entries. &lt;br /&gt;C. The array must be sorted. &lt;br /&gt;D. The array's size must be a power of two. &lt;br /&gt;Ans:c&lt;br /&gt;25. What is the worst-case time for serial search finding a single item in an array? &lt;br /&gt;A. Constant time &lt;br /&gt;B. Logarithmic time &lt;br /&gt;C. Linear time &lt;br /&gt;D. Quadratic time &lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;26. If there are 17 elements in an array, how many maximum comparisons are required to search an element using binary search?&lt;br /&gt;a.3  b.4   c.5   d.6&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;27.If there are 34 elements in an array, how many maximum comparisons are required to search an element using binary search?&lt;br /&gt;a.3  b.4   c.5   d.6&lt;br /&gt;Ans:d&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-7987017453526846206?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/7987017453526846206/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=7987017453526846206' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7987017453526846206'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7987017453526846206'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/binary-search-interview-question-part-2.html' title='Binary Search Interview Question Part 2'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-5070235621503765177</id><published>2007-10-27T10:03:00.002-07:00</published><updated>2007-10-27T10:04:24.161-07:00</updated><title type='text'>Binary Search Interview Question Part 1</title><content type='html'>1. Binary search is a more specialized algorithm than sequential search as it takes advantage of data that has been &lt;br /&gt;a. Sorted &lt;br /&gt;b. Not Sorted&lt;br /&gt;c. random&lt;br /&gt;d. none of the above&lt;br /&gt;Ans:a&lt;br /&gt;2. The underlying idea of binary search is to divide the sorted data into two halves and to examine the data at the point of the split. True.&lt;br /&gt;&lt;br /&gt;3. Binary search when compared to linear search is &lt;br /&gt;a. More efficient &lt;br /&gt;b. Less efficient&lt;br /&gt;c. slower&lt;br /&gt;d. none&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;4. A search algorithm is an algorithm that accepts an argument a and tries to find a record in the file with the primary key as a. True.&lt;br /&gt;&lt;br /&gt;5. Binary search is a part of or used in which of the following&lt;br /&gt;a. binary insertion sort&lt;br /&gt;b. ideal search&lt;br /&gt;c. suffix array&lt;br /&gt;d. all the above  &lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;6. Binary search is a kind of ________________ .&lt;br /&gt;Ans. dichotomic search&lt;br /&gt;&lt;br /&gt;7. _________________ strategy is a part of or used in binary search.&lt;br /&gt;Ans. Divide and conquer&lt;br /&gt;&lt;br /&gt;8. The run time of binary search is _______&lt;br /&gt;a. O(ln n)&lt;br /&gt;b. O(n ln n)&lt;br /&gt;c. O(log n)&lt;br /&gt;d. O(n)&lt;br /&gt;            Ans. a&lt;br /&gt;         The run time of binary search is O(ln n) which is log n to the base e.&lt;br /&gt;&lt;br /&gt;9. For finding the middle element in a binary search to avoid overflows the formula used is __________ where high and low are non-negative.&lt;br /&gt;Ans. mid = low + (high-low)/2&lt;br /&gt;&lt;br /&gt;10. The mid element of a binary search can be found by using the relation               ________________ .&lt;br /&gt;Ans. mid = (high + low)/2&lt;br /&gt;&lt;br /&gt;11. The average successful search time taken by binary search on a sorted array of 10 items is _____&lt;br /&gt;a. 2.6&lt;br /&gt;b. 2.7&lt;br /&gt;c. 2.8&lt;br /&gt;d. 2.9&lt;br /&gt;            Ans. d&lt;br /&gt;         The items  I1,I2,….I10 may be arranged in a binary search tree as shown below.So,to match I5,the number of comparisons needed is 1;for I2,it is 2, for I8 it is 2,for I1 it is 3 and so on.So,the average is (1+(2+2)+(3+3+3+3)+(4+4+4))/10 = 2.9&lt;br /&gt;                                   &lt;br /&gt;                                   &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;12. A fast way to search a sorted array is to use a __________.&lt;br /&gt;  Ans. Binary search&lt;br /&gt; &lt;br /&gt;13. For an array of million items,________ search operation is better than _____________ search.&lt;br /&gt;a. linear,binary&lt;br /&gt;b. binary,linear&lt;br /&gt;c. linear,fibonacci&lt;br /&gt;d. none of the above&lt;br /&gt;        Ans. b&lt;br /&gt;    For an array of a million elements, binary search, O(log N), will find the target element with a worst case of only 20 comparisons. Linear search, O(N), on average will take 500,000 comparisons to find the element. &lt;br /&gt;&lt;br /&gt;14. In case of a binary search,the array must be __________ before it is searched.&lt;br /&gt;  Ans. sorted&lt;br /&gt;&lt;br /&gt;15. Which of the following statement(s) is/are not correct?&lt;br /&gt;             a. In sequential search, the time complexity of an unsuccessful search is O(N).&lt;br /&gt;                b.The average case time complexity of sequential search algorithm is O(N).                                                    .               c.  In binary search,an unsuccessful search requires examining every  in the array                                              &lt;br /&gt;              d. In Binary search, the time complexity of a successful search in the worst case is O(log N).    &lt;br /&gt;Ans. c&lt;br /&gt;&lt;br /&gt;     16. Consider the following algorithm.&lt;br /&gt;(i) Compare the given Name with the Name in the middle of the list&lt;br /&gt;(ii) This tells which half of the list contains Name&lt;br /&gt;(iii) Then compare Name with the Name in the middle of the correct half to Determine which quarter of the list contains Name&lt;br /&gt;(iv) Continue the process until finding Name in the list&lt;br /&gt;            What does the above algorithm describe?&lt;br /&gt;a. Sequential search&lt;br /&gt;b. Index sequential search&lt;br /&gt;c. Merge sort&lt;br /&gt;d. Binary search&lt;br /&gt;        Ans. d&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-5070235621503765177?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/5070235621503765177/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=5070235621503765177' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5070235621503765177'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5070235621503765177'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/binary-search-interview-question-part-1.html' title='Binary Search Interview Question Part 1'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-8152156661989042209</id><published>2007-10-27T10:03:00.001-07:00</published><updated>2007-10-27T10:03:40.610-07:00</updated><title type='text'>a</title><content type='html'>1. Binary search is a more specialized algorithm than sequential search as it takes advantage of data that has been &lt;br /&gt;a. Sorted &lt;br /&gt;b. Not Sorted&lt;br /&gt;c. random&lt;br /&gt;d. none of the above&lt;br /&gt;Ans:a&lt;br /&gt;2. The underlying idea of binary search is to divide the sorted data into two halves and to examine the data at the point of the split. True.&lt;br /&gt;&lt;br /&gt;3. Binary search when compared to linear search is &lt;br /&gt;a. More efficient &lt;br /&gt;b. Less efficient&lt;br /&gt;c. slower&lt;br /&gt;d. none&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;4. A search algorithm is an algorithm that accepts an argument a and tries to find a record in the file with the primary key as a. True.&lt;br /&gt;&lt;br /&gt;5. Binary search is a part of or used in which of the following&lt;br /&gt;a. binary insertion sort&lt;br /&gt;b. ideal search&lt;br /&gt;c. suffix array&lt;br /&gt;d. all the above  &lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;6. Binary search is a kind of ________________ .&lt;br /&gt;Ans. dichotomic search&lt;br /&gt;&lt;br /&gt;7. _________________ strategy is a part of or used in binary search.&lt;br /&gt;Ans. Divide and conquer&lt;br /&gt;&lt;br /&gt;8. The run time of binary search is _______&lt;br /&gt;a. O(ln n)&lt;br /&gt;b. O(n ln n)&lt;br /&gt;c. O(log n)&lt;br /&gt;d. O(n)&lt;br /&gt;            Ans. a&lt;br /&gt;         The run time of binary search is O(ln n) which is log n to the base e.&lt;br /&gt;&lt;br /&gt;9. For finding the middle element in a binary search to avoid overflows the formula used is __________ where high and low are non-negative.&lt;br /&gt;Ans. mid = low + (high-low)/2&lt;br /&gt;&lt;br /&gt;10. The mid element of a binary search can be found by using the relation               ________________ .&lt;br /&gt;Ans. mid = (high + low)/2&lt;br /&gt;&lt;br /&gt;11. The average successful search time taken by binary search on a sorted array of 10 items is _____&lt;br /&gt;a. 2.6&lt;br /&gt;b. 2.7&lt;br /&gt;c. 2.8&lt;br /&gt;d. 2.9&lt;br /&gt;            Ans. d&lt;br /&gt;         The items  I1,I2,….I10 may be arranged in a binary search tree as shown below.So,to match I5,the number of comparisons needed is 1;for I2,it is 2, for I8 it is 2,for I1 it is 3 and so on.So,the average is (1+(2+2)+(3+3+3+3)+(4+4+4))/10 = 2.9&lt;br /&gt;                                   &lt;br /&gt;                                   &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;12. A fast way to search a sorted array is to use a __________.&lt;br /&gt;  Ans. Binary search&lt;br /&gt; &lt;br /&gt;13. For an array of million items,________ search operation is better than _____________ search.&lt;br /&gt;a. linear,binary&lt;br /&gt;b. binary,linear&lt;br /&gt;c. linear,fibonacci&lt;br /&gt;d. none of the above&lt;br /&gt;        Ans. b&lt;br /&gt;    For an array of a million elements, binary search, O(log N), will find the target element with a worst case of only 20 comparisons. Linear search, O(N), on average will take 500,000 comparisons to find the element. &lt;br /&gt;&lt;br /&gt;14. In case of a binary search,the array must be __________ before it is searched.&lt;br /&gt;  Ans. sorted&lt;br /&gt;&lt;br /&gt;15. Which of the following statement(s) is/are not correct?&lt;br /&gt;             a. In sequential search, the time complexity of an unsuccessful search is O(N).&lt;br /&gt;                b.The average case time complexity of sequential search algorithm is O(N).                                                    .               c.  In binary search,an unsuccessful search requires examining every  in the array                                              &lt;br /&gt;              d. In Binary search, the time complexity of a successful search in the worst case is O(log N).    &lt;br /&gt;Ans. c&lt;br /&gt;&lt;br /&gt;     16. Consider the following algorithm.&lt;br /&gt;(i) Compare the given Name with the Name in the middle of the list&lt;br /&gt;(ii) This tells which half of the list contains Name&lt;br /&gt;(iii) Then compare Name with the Name in the middle of the correct half to Determine which quarter of the list contains Name&lt;br /&gt;(iv) Continue the process until finding Name in the list&lt;br /&gt;            What does the above algorithm describe?&lt;br /&gt;a. Sequential search&lt;br /&gt;b. Index sequential search&lt;br /&gt;c. Merge sort&lt;br /&gt;d. Binary search&lt;br /&gt;        Ans. d&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-8152156661989042209?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/8152156661989042209/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=8152156661989042209' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/8152156661989042209'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/8152156661989042209'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/blog-post.html' title='a'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-7290279442542900224</id><published>2007-10-27T10:01:00.000-07:00</published><updated>2007-10-27T10:02:03.066-07:00</updated><title type='text'>Algorithms Interview Question Part 8</title><content type='html'>83. An algorithm designed for a computer which executes one instruction at a time is called&lt;br /&gt;a.Serial algorithm&lt;br /&gt;b.Parallel algorithm&lt;br /&gt;c.Random algorithm&lt;br /&gt;d.Deterministic algorithm&lt;br /&gt;84. Algorithms, which take advantage of computer architectures where several processors can work on a problem at the same time are called&lt;br /&gt;a.Serial algorithm&lt;br /&gt;b.Parallel algorithm&lt;br /&gt;c.Random algorithm&lt;br /&gt;d.Deterministic algorithm&lt;br /&gt;Ans:b&lt;br /&gt;85. Serial algorithms divide the problem into more symmetrical or asymmetrical sub problems and pass them to many processors and put the results back together at one end.(T/F)&lt;br /&gt;Ans:False&lt;br /&gt;86.The resource consumption in parallel algorithms is &lt;br /&gt;i.processor cycles on each processors  ii.the communication overhead between the processors.&lt;br /&gt;a.only I  b.only ii   c.i and ii  d.neither I nor ii&lt;br /&gt;Ans:c&lt;br /&gt;87.Sorting algorithms can be parallelized efficiently, but their communication overhead is expensive.(T/F)&lt;br /&gt;Ans:True&lt;br /&gt;88.Recursive algorithms are not parallelizable. (T/F)&lt;br /&gt;Ans:False&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;89. The Order of the expression   : 5*2n-n*log(n)-3*n3-1 is________.&lt;br /&gt;a. O(n3)&lt;br /&gt;b. O(n*log(n))&lt;br /&gt;c. O(2n)&lt;br /&gt;d. O(n*log(n))&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;90. Which  of the following Orders of algorithm is considered efficient ?&lt;br /&gt;a. O (n * log (n))&lt;br /&gt;b. O(2n)&lt;br /&gt;c. O(n2)&lt;br /&gt;d.O (log (n))&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;91. Which one depicts the correct order of efficiency from best to worst among the following ?&lt;br /&gt;a. O(n*n) , O(2n), O(log(n)), O(n)&lt;br /&gt;b. O(n*n)O(n),O(2n),O(log(n)&lt;br /&gt;c. O(log(n)), O(n), O(n*n), O(2n )&lt;br /&gt;d. O(n*n), O(2n), O(log(n)), O(n)&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;92. (A) In O(n*log(n)), multiplying the file size by 100 will multiply the sorting time by less than 200. (B) In O(n*n), multiplying the file size by 100 will multiply the sorting time by a factor of 10000. What is correct about above statements?&lt;br /&gt;a.A is TRUE, B is FALSE&lt;br /&gt;b. B is TRUE, A is FALSE&lt;br /&gt;c. Both are TRUE&lt;br /&gt;d. Both are FALSE&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;Nlog n=100log100 &lt; 200&lt;br /&gt;100*100=10000&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-7290279442542900224?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/7290279442542900224/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=7290279442542900224' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7290279442542900224'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7290279442542900224'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/algorithms-interview-question-part-8.html' title='Algorithms Interview Question Part 8'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-7669023733276318423</id><published>2007-10-27T10:00:00.000-07:00</published><updated>2007-10-27T10:01:20.998-07:00</updated><title type='text'>Algorithms Interview Question Part 7</title><content type='html'>63. In a proper binary tree with n nodes, the number of internal nodes is:&lt;br /&gt;a). n/2&lt;br /&gt;b). (n+1)/2&lt;br /&gt;c). (n-1)/2 &lt;br /&gt;d). (n+1)/2 –1&lt;br /&gt;Ans:c&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;True false quest&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;64. n2 = O(n3) &lt;br /&gt;True ( Transitive property )&lt;br /&gt;65. n3 = O(n2) &lt;br /&gt;False&lt;br /&gt;66.3n = o(n) &lt;br /&gt;False [Remember, little-o means "less than" not "less than or equal."]&lt;br /&gt;67.n/3 = O(n) &lt;br /&gt;True&lt;br /&gt;68`.n! = O (n log n) &lt;br /&gt;False [But if it were big-Omega, it would be true!]&lt;br /&gt;69.3n =  (2n) &lt;br /&gt;False [Because exponentials differ by more than just a constant factor]&lt;br /&gt;70.n2 + 3n + sin n =  (n2) &lt;br /&gt;True&lt;br /&gt;71.2n =  (2n+4) &lt;br /&gt;True&lt;br /&gt;72.loga n =  (logb n), for a and b constant, a!=b &lt;br /&gt;True&lt;br /&gt;73.na =  (nb), for a and b constant, a!=b &lt;br /&gt;False&lt;br /&gt;74.It is possible to do a general purpose comparison sort on n items using O(n) comparisons. &lt;br /&gt;False&lt;br /&gt;75.In the worst case, access to the maximum element of a heap takes  (ln n) time. &lt;br /&gt;False [it's just constant time]&lt;br /&gt;76.Merge sort is asymptotically faster than bubble sort in the best case. &lt;br /&gt;False [bubble sort is linear in the best case!]&lt;br /&gt;77.Radix sort is a stable sort. &lt;br /&gt;True&lt;br /&gt;&lt;br /&gt;78.Invoking the sort on an already sorted array is an example of a situation&lt;br /&gt;     Where bubble sort is faster than Quick sort.&lt;br /&gt;&lt;br /&gt;     True   [ bubble sort is O(n) while Quick sort is O(n2).]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;                &lt;br /&gt;         &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Fill in the blanks&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;79.   ---------------- is the least number of nodes possible in an almost complete binary tree &lt;br /&gt;      of height h          &lt;br /&gt;&lt;br /&gt;Ans: 2^h         [ This is the case where there is one lone leaf  hanging off the left side of the tree.This is  just one more than the number of nodes in a complete binary tree of height h-1. ]&lt;br /&gt;&lt;br /&gt;80. Which of the following should an algorithm consist of&lt;br /&gt;i. Zero or more Inputs &lt;br /&gt;ii. One or more Outputs &lt;br /&gt;iii. Infiniteness&lt;br /&gt;iv. Definitiveness or Preciseness &lt;br /&gt;a.i,ii,iii    b.i,ii,iv    c.ii,iii,iv    d.i,iii,iv&lt;br /&gt;Ans:b&lt;br /&gt;An algorithm should have the following:&lt;br /&gt;• Zero or more Inputs &lt;br /&gt;• One or more Outputs &lt;br /&gt;• Finiteness or computability &lt;br /&gt;• Definitiveness or Preciseness &lt;br /&gt;&lt;br /&gt;81. An  algorithm that invokes (makes reference to) itself repeatedly until a certain condition matches, which is a method common to functional programming is called&lt;br /&gt;a. recursive algorithm&lt;br /&gt;b. iterative algorithm&lt;br /&gt;c. random&lt;br /&gt;d. deterministic&lt;br /&gt;Ans:a&lt;br /&gt;82. Algorithms which use repetitive constructs like loops and possibly with data structures like stack to solve the problems are called&lt;br /&gt;a. recursive algorithm&lt;br /&gt;b. iterative algorithm&lt;br /&gt;c. random&lt;br /&gt;d. deterministic&lt;br /&gt;Ans:b&lt;br /&gt;Recursion vs. Iteration: A recursive algorithm is one that invokes (makes reference to) itself repeatedly until a certain condition matches, which is a method common to functional programming. Iterative algorithms use repetitive constructs like loops and possibly with data structures like stack to solve the problems. Some problems are naturally suited for one implementation to other. For example, towers of hanoi is well understood in recursive implementation. Every recursive version has an equivalent (but possibly more complex) iterative version&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-7669023733276318423?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/7669023733276318423/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=7669023733276318423' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7669023733276318423'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7669023733276318423'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/algorithms-interview-question-part-7.html' title='Algorithms Interview Question Part 7'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-6187720150938181168</id><published>2007-10-27T09:59:00.000-07:00</published><updated>2007-10-27T10:00:13.060-07:00</updated><title type='text'>Algorithms Interview Question Part 6</title><content type='html'>46. Consider the following four terms given in Part A and some definitions given in Part B.&lt;br /&gt;       Part A                                                              Part B&lt;br /&gt; (i) Big O                               (p) The notation used to capture the most dominant term in a function&lt;br /&gt;(ii) Big Omega                      (q) A guarantee over all inputs of some size&lt;br /&gt;(iii) Average case bound       (r) The bound in which running time is measured as an average&lt;br /&gt;                                                 over all the possible inputs of size N&lt;br /&gt;(iv) Worst case bound           (s) An algorithm that causes the running time to grow as O(N)&lt;br /&gt;(v) Linear time algorithm      (t) The notation similar to greater than or equal to when&lt;br /&gt;                                                  considering growth rates&lt;br /&gt;Choose the best definition from Part B for the above five hash operations respectively in Part A.&lt;br /&gt;(a) (i)􀃆(p) (ii)􀃆(r) (iii)􀃆(t) (iv)􀃆(q) (v)􀃆(s)    (b) (i)􀃆(s) (ii)􀃆(t) (iii)􀃆(r) (iv)􀃆(q) (v)􀃆(p)&lt;br /&gt;(c) (i)􀃆(p) (ii)􀃆(t) (iii)􀃆(r) (iv)􀃆(q) (v)􀃆(s)    (d) (i)􀃆(p) (ii)􀃆(s) (iii)􀃆(r) (iv)􀃆(q) (v)􀃆(t)&lt;br /&gt;(e) (i)􀃆(p) (ii)􀃆(t) (iii)􀃆(r) (iv)􀃆(s) (v)􀃆(q)&lt;br /&gt;&lt;br /&gt;  Ans. c&lt;br /&gt;&lt;br /&gt;47. There are the three main measures of efficiency that can be applied to most algorithms: best, worst and           average cases.&lt;br /&gt;&lt;br /&gt;Part A    Part B&lt;br /&gt;(i) Best case  P This case is when the target is either a &lt;br /&gt;     last item in the list or is not in the list at all &lt;br /&gt;(ii) Worst case  Q This case occurs when the target for which &lt;br /&gt;     you are searching is the first item in the list&lt;br /&gt;(iii) Average case  R This case is found by considering all possible&lt;br /&gt;     outcomes of a search and averaging the number&lt;br /&gt;     of companions over all these cases.   &lt;br /&gt;       Choose the best definition from part B for the above three cases.&lt;br /&gt;a. (i)   R  (ii)   P  (iii)   Q&lt;br /&gt;b. (i)   R  (ii)    Q  (iii)   P&lt;br /&gt;c. (i)   Q  (ii)   P  (iii)   R&lt;br /&gt;d. (i)   Q  (ii)    R  (iii)   P&lt;br /&gt; Ans.  d&lt;br /&gt;&lt;br /&gt;48. Consider the following characteristics connected with a program.&lt;br /&gt;(i) The input to the program&lt;br /&gt;(ii) The time complexity of the algorithm underlying the program&lt;br /&gt;(iii) The quality of the Compiler&lt;br /&gt;(iv) The nature and speed of the machine&lt;br /&gt;     On which of the above does the running time of a program depend?&lt;br /&gt;a. (i) and (ii) only&lt;br /&gt;b. (i),(ii) and (iii) only&lt;br /&gt;c. (i),(iii) and (iv) only&lt;br /&gt;d. (i),(ii) and (iv) only&lt;br /&gt;Ans.  d&lt;br /&gt;   &lt;br /&gt;49. We may find several algorithms for solving a problem; for each algorithm, the measure to calculate the proportionate time taken to solve that particular problem is called ____________. &lt;br /&gt;&lt;br /&gt;        a. Time Complexity&lt;br /&gt;        b. Space Complexity&lt;br /&gt;  c. Algorithm complexity&lt;br /&gt;  d. Design Complexity&lt;br /&gt;Ans: a&lt;br /&gt;50. If an algorithm takes the largest possible execution time for a certain set of input values, then it is called ________ of the algorithm.&lt;br /&gt;a. Best case&lt;br /&gt;b. Worst Case &lt;br /&gt;c. Average case&lt;br /&gt;d. none&lt;br /&gt;Ans:b&lt;br /&gt;51. Which of the following is not a feature of algorithm&lt;br /&gt;a. Step wise implementation of large problems&lt;br /&gt;b. Calculation of time and space complexity&lt;br /&gt;c. Analyzing the efficiency of the code&lt;br /&gt;d. Complex representation of problems&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;52. The correct order of sequential search algorithm is&lt;br /&gt;(i) marker ++.&lt;br /&gt;(ii) else, throw an exception.&lt;br /&gt;(iii) if target  ==  key at location marker, then return.&lt;br /&gt;(iv) While target = = key at location marker and not at the end of the list.&lt;br /&gt;(v) Read in target, initialize marker to first array index(0). &lt;br /&gt;a.(v), (iv), (i), (ii), and (iii).&lt;br /&gt;b.(iv), (i), (iii), (iv) and (ii).&lt;br /&gt;d.(v), (iv), (iii), (i) and (ii). c.(v), (iv), (i), (iii) and (ii)&lt;br /&gt;&lt;br /&gt;Ans:c&lt;br /&gt;&lt;br /&gt;53. Running time of an algorithm does not depend on which of the following statement(s)&lt;br /&gt;(i) Time taken by each instruction in the algorithm.&lt;br /&gt;(ii) Number of times each instruction is executed.&lt;br /&gt;(iii) Processor speed and its machine language instruction set.&lt;br /&gt;(iv) Size of the input&lt;br /&gt;a.(iii)  only  b.(iii) and (iv)  c. (i) and (iii) only   d. (iv) only  e.none of these&lt;br /&gt;Ans:e&lt;br /&gt;54. Consider the following program code.&lt;br /&gt;&lt;br /&gt;Public static int sum (int n)&lt;br /&gt;&lt;br /&gt;{ int Partialsum&lt;br /&gt;    Partialsum=0;&lt;br /&gt;   for (int i=1; i&lt;=n ;i++)&lt;br /&gt;   Partialsum += i *i *i ;&lt;br /&gt;&lt;br /&gt;return Partialsum;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The time complexity of the above algorithm is?&lt;br /&gt;a.log n  b.nlogn  c.n  d.constant&lt;br /&gt;Ans:c&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;55.The minimal spanning tree of a graph gives the shortest distance between any two nodes. (True or False)&lt;br /&gt;Ans. False&lt;br /&gt;Minimal spanning tree assures that the total weight of the tree is kept at its minimum.But it doesn’t mean that the distance between any two nodes involved in the minimum-spanning tree is minimum.&lt;br /&gt;56.What is the simplest file structure?&lt;br /&gt;a. Sequential&lt;br /&gt;b. Indexed&lt;br /&gt;c. Random&lt;br /&gt;Ans. Sequential&lt;br /&gt;57. Computational procedure is an algorithm that&lt;br /&gt;d. does not terminate&lt;br /&gt;e. terminates&lt;br /&gt;f. computes&lt;br /&gt;g. analyzes&lt;br /&gt;Ans. a&lt;br /&gt;58.An algorithm consists of the following areas&lt;br /&gt;i) to devise the algorithm&lt;br /&gt;ii) to validate the algorithm&lt;br /&gt;iii) to express the algorithm&lt;br /&gt;iv) to analyze the algorithm&lt;br /&gt;v) to test the programs for the algorithm&lt;br /&gt;The correct options are&lt;br /&gt;a. (i),(ii),(iii) only&lt;br /&gt;b. (ii),(iii),(iv) and (v) only&lt;br /&gt;c. (i),(ii),(iii),(iv) only&lt;br /&gt;d. All of the above&lt;br /&gt;Ans. d&lt;br /&gt;59.An algorithm is said to be recursive if the same algorithm is invoked in the body of the algorithm. (True or False)&lt;br /&gt;         Ans. True&lt;br /&gt;.&lt;br /&gt;60.______________ is an algorithm design method that can be used when the solution to a problem can be viewed as the result of a sequence of decisions.&lt;br /&gt;             Ans. Dynamic programming&lt;br /&gt;61.The two parameters that can be taken as cost of an algorithm include&lt;br /&gt;running time and amount of memory used .&lt;br /&gt;&lt;br /&gt;62. Given a list implemented with a linked list, the operation remove(p) runs in:&lt;br /&gt;a) O(1)&lt;br /&gt;b) O(log n)&lt;br /&gt;c) O(n) &lt;br /&gt;d). O(nlog n)&lt;br /&gt;Ans:c&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-6187720150938181168?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/6187720150938181168/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=6187720150938181168' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/6187720150938181168'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/6187720150938181168'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/algorithms-interview-question-part-6.html' title='Algorithms Interview Question Part 6'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-3331832639165125309</id><published>2007-10-27T09:56:00.002-07:00</published><updated>2007-10-27T09:59:23.396-07:00</updated><title type='text'>Algorithms Interview Question Part 5</title><content type='html'>27. An algorithm which is given the entire sequence of inputs in advance.  (practice test question)&lt;br /&gt;a.On-line algorithm&lt;br /&gt;b.Off line algorithm&lt;br /&gt;c.Adversary algorithm&lt;br /&gt;d.Deterministic algorithm&lt;br /&gt;Ans:b&lt;br /&gt;An algorithm that must process each input in turn, without detailed knowledge of future inputs is called on-line algorithm.&lt;br /&gt;28. To combine multiple sorted data streams into a single sorted stream using external storage. &lt;br /&gt;a.External merge&lt;br /&gt;b.Internal merge&lt;br /&gt;c.both&lt;br /&gt;d.none&lt;br /&gt;Ans:a&lt;br /&gt;29 .Let m,n be positive integers.Define Q(m,n) as Q(m,n)=0, if m&lt;n&lt;br /&gt;Q(m,3) is (a div b, gives the quotient when a is divided by b)&lt;br /&gt;a.a constant b.p*(m mod 3)  c.p*(m div 3)  d. 3*p&lt;br /&gt;Ans:c&lt;br /&gt;Let m&gt;n .Let m/n yield a quotient x and remainder y. So, m=n*x+y and y&lt;m div 3 is the quotient when m is divided by 3. So,that many times p is added ,before we terminate recursion by satisfying the end condition Q(m,n)=0,if m&lt;n.&lt;br /&gt;30. _________ is the number of times a key operation will execute.&lt;br /&gt;a. Frequency count&lt;br /&gt;b. Running time&lt;br /&gt;c. Space complexity&lt;br /&gt;d. Time complexity&lt;br /&gt;Ans. a&lt;br /&gt;31. When an algorithm contains a recursive call to itself,its running time can often be described by a ___________&lt;br /&gt; Ans. recurrence equation or recurrence&lt;br /&gt;32. A function f(n) is strictly increasing if _________ implies ________ where m and n are the two parameters.&lt;br /&gt; Ans. m &lt;n , f(m)&lt;f(n)&lt;br /&gt;33. A function f(n) is strictly decreasing if _________ implies ________ where m and n are the two parameters.&lt;br /&gt;Ans. m&gt;n , f(m)&gt;f(n)&lt;br /&gt;34. The substitution method for solving recurrences entails the following steps:&lt;br /&gt;a. Guess the form of the solution&lt;br /&gt;b. Use mathematical induction to find the constants and show that the solution works.  True or False&lt;br /&gt;Ans. True&lt;br /&gt;35. The various methods for solving recurrences are&lt;br /&gt;a. substitution method&lt;br /&gt;b. recursion-tree method&lt;br /&gt;c. master method &lt;br /&gt;d. all of the above&lt;br /&gt;Ans. d&lt;br /&gt;36. The recursion-tree method converts the recurrence into a tree whose nodes represent the costs incurred at various levels of the recursion. True or False&lt;br /&gt;Ans. True&lt;br /&gt;37. The master theorem does not apply to the recurrence of the form&lt;br /&gt;a. T(n) = 2T(n/2) + n lg n&lt;br /&gt;b. T(n) = aT(n/b) + f(n)&lt;br /&gt;c. T(n) = aT(n) + f(n)&lt;br /&gt;d. None of the above&lt;br /&gt;Ans. a&lt;br /&gt;Here a=2,b=2,f(n)=nlgn and n^log a = n but f(n)=n lg n is not polynomially larger than n^log a = n.the ratio f(n)/n^log a = (n lg n)/n =lg n is asymptotically less than n^є for any positive constant є.&lt;br /&gt;38.Which of the following is a way of classifying algorithms based on implementation.&lt;br /&gt;a.Recursion vs iteration&lt;br /&gt;b.Serial vs parallel&lt;br /&gt;c.Random vs deterministic &lt;br /&gt;d.All the above&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;39.Searching can be used with&lt;br /&gt;i.lists   ii.graphs   iii.trees   &lt;br /&gt;a.i ,ii   b.i,iii    c.i,ii,iii   d.ii,iii&lt;br /&gt;Ans:c&lt;br /&gt;40. _______ consists of the input (satisfying whatever constraints are imposed in the problem statement) needed to compute a solution to the problem.&lt;br /&gt;Ans: instance of a problem&lt;br /&gt;41. Which of the following factors decides which algorithm is best for a given application?&lt;br /&gt;a.Number of items to be sorted&lt;br /&gt;b.extent to which items are already sorted&lt;br /&gt;c.possible restrictions on the item values&lt;br /&gt;d.All the above&lt;br /&gt;Ans:d &lt;br /&gt;42. Probabilistic analysis is the use of ___________ in the analysis of problems.&lt;br /&gt;Ans. probability&lt;br /&gt;43. Probabilistic analysis &lt;br /&gt; a. is used to analyze the running time of an algorithm&lt;br /&gt; b. requires the knowledge of the distribution of inputs&lt;br /&gt;c. all the above&lt;br /&gt;d. none of the above&lt;br /&gt;Ans. c&lt;br /&gt;44. In randomized algorithm,the behavior of the algorithm is determined only by its input but not by values produced by a randon-number generator. True or False&lt;br /&gt;Ans. False&lt;br /&gt;In randomized algorithm,the behavior of the algorithm is determined not only by its input but also by values produced by a randon-number generator. &lt;br /&gt;45. The running time of an algorithm on a particular input is the number of primitive operations or steps executed. True or False&lt;br /&gt;  Ans. True&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-3331832639165125309?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/3331832639165125309/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=3331832639165125309' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/3331832639165125309'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/3331832639165125309'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/algorithms-interview-question-part-5.html' title='Algorithms Interview Question Part 5'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-4225223713930499998</id><published>2007-10-27T09:56:00.001-07:00</published><updated>2007-10-27T09:56:42.394-07:00</updated><title type='text'>Algorithms Interview Question Part 4</title><content type='html'>22. An algorithm whose behavior can be completely predicted from the input. (practice test question)&lt;br /&gt;a.Probabilistic algorithm&lt;br /&gt;b.Randomized algorithm&lt;br /&gt;c.Deterministic algorithm&lt;br /&gt;d.Non deterministic algorithm&lt;br /&gt;Ans:c&lt;br /&gt;Any algorithm that makes some random (or pseudorandom) choices is called randomized algorithm.&lt;br /&gt;Any algorithm that works for all practical purposes but has a theoretical chance of being wrong is called probabilistic algorithm.&lt;br /&gt;A conceptual algorithm with more than one allowed step at certain times and which always takes the right or best step. It has the super computational characteristic of choosing the optimal behavior is called non-deterministic algorithm.&lt;br /&gt;&lt;br /&gt;23. A conceptual algorithm with more than one allowed step at certain times and which always takes the right or best step. It has the super computational characteristic of choosing the optimal behavior.   (practice test question)&lt;br /&gt;a.Probabilistic algorithm&lt;br /&gt;b.Randomized algorithm&lt;br /&gt;c.Deterministic algorithm&lt;br /&gt;d.Non deterministic algorithm&lt;br /&gt;Ans:d&lt;br /&gt;Any algorithm that makes some random (or pseudorandom) choices is called randomized algorithm.&lt;br /&gt;Any algorithm that works for all practical purposes but has a theoretical chance of being wrong is called probabilistic algorithm.&lt;br /&gt;An algorithm whose behavior can be completely predicted from the input is called deterministic algorithm.&lt;br /&gt;24. An algorithm that usually, but not always, works or that gives nearly the right answer. (practice test question)&lt;br /&gt;a.Probabilistic algorithm&lt;br /&gt;b.Heuristic algorithm&lt;br /&gt;c.Deterministic algorithm&lt;br /&gt;d.Non deterministic&lt;br /&gt;Ans:b&lt;br /&gt;Any algorithm that works for all practical purposes but has a theoretical chance of being wrong is called probabilistic algorithm.&lt;br /&gt;An algorithm whose behavior can be completely predicted from the input is called deterministic algorithm.&lt;br /&gt;A conceptual algorithm with more than one allowed step at certain times and which always takes the right or best step. It has the super computational characteristic of choosing the optimal behavior is called non-deterministic algorithm.&lt;br /&gt;&lt;br /&gt;25. A high-level algorithmic framework or approach that can be specialized to solve optimization problems and a high-level strategy that guides other heuristics in a search for feasible solutions.   (practice test question)&lt;br /&gt;a.Probabilistic algorithm&lt;br /&gt;b.Heuristic algorithm&lt;br /&gt;c.Meta hueristic algorithm&lt;br /&gt;d.Non deterministic&lt;br /&gt;Ans:c&lt;br /&gt;An algorithm that usually, but not always, works or that gives nearly the right answer is called heuristic algorithm.&lt;br /&gt;Any algorithm that works for all practical purposes but has a theoretical chance of being wrong is called probabilistic algorithm.&lt;br /&gt;A conceptual algorithm with more than one allowed step at certain times and which always takes the right or best step. It has the super computational characteristic of choosing the optimal behavior is called non-deterministic algorithm.&lt;br /&gt;&lt;br /&gt;26. An algorithm that must process each input in turn, without detailed knowledge of future inputs. (practice test question)&lt;br /&gt;a.On-line algorithm&lt;br /&gt;b.Off line algorithm&lt;br /&gt;c.Adversary algorithm&lt;br /&gt;d.Deterministic algorithm&lt;br /&gt;Ans:a&lt;br /&gt;An algorithm which is given the entire sequence of inputs in advance is called an off-line algorithm.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-4225223713930499998?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/4225223713930499998/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=4225223713930499998' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4225223713930499998'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4225223713930499998'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/algorithms-interview-question-part-4.html' title='Algorithms Interview Question Part 4'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-111682316032316961</id><published>2007-10-27T09:54:00.002-07:00</published><updated>2007-10-27T09:55:54.372-07:00</updated><title type='text'>Algorithms Interview Question Part 3</title><content type='html'>18. The algorithms that test for a solution, if one is found the algorithm is solved, if not it recurs once and tests again, continuing until a solution is found is     (practice test question)&lt;br /&gt;a. Dynamic Programming Algorithms&lt;br /&gt;b. Branch and Bound Algorithms&lt;br /&gt;c. Simple Recursive Algorithms&lt;br /&gt;d. Backtracking Algorithms&lt;br /&gt;Ans:d&lt;br /&gt;The class of algorithms that remembers older results and attempts to use this to speed the process of finding new results is called dynamic programming algorithm.&lt;br /&gt;The algorithms that form a tree of subproblems to the primary problem, following each branch until it is either solved or lumped in with another branch is called branch and bound algorithm.&lt;br /&gt;This type of algorithm goes for a direct solution first, then backtracks to find a simpler solution is called simple recursive algorithm.&lt;br /&gt;The algorithms that test for a solution, if one is found the algorithm is solved, if not it recurs once and tests again, continuing until a solution is found is called backtracking algorithm.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;19. An algorithm that is similar to a branch and bound algorithm, except that it uses the backtracking method of recurring in tandem with dividing a problem into subproblems. &lt;br /&gt;(practice test question)&lt;br /&gt;a. Dynamic Programming Algorithms&lt;br /&gt;b. Divide and Conquer Algorithms&lt;br /&gt;c. Simple Recursive Algorithms&lt;br /&gt;d. Backtracking Algorithms&lt;br /&gt;Ans:b&lt;br /&gt;The class of algorithms that remembers older results and attempts to use this to speed the process of finding new results is called dynamic programming algorithm.&lt;br /&gt;This type of algorithm goes for a direct solution first, then backtracks to find a simpler solution is called simple recursive algorithm.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;20. Any algorithm that works for all practical purposes but has a theoretical chance of being wrong.   (practice test question)&lt;br /&gt;a.Probabilistic algorithm&lt;br /&gt;b.Randomized algorithm&lt;br /&gt;c.Deterministic algorithm&lt;br /&gt;d.Non deterministic algorithm&lt;br /&gt;Ans:a&lt;br /&gt;Any algorithm that makes some random (or pseudorandom) choices is called randomized algorithm.&lt;br /&gt;An algorithm whose behavior can be completely predicted from the input is called deterministic algorithm.&lt;br /&gt;A conceptual algorithm with more than one allowed step at certain times and which always takes the right or best step. It has the super computational characteristic of choosing the optimal behavior is called non-deterministic algorithm.&lt;br /&gt;21. Any algorithm that makes some random (or pseudorandom) choices&lt;br /&gt;(practice test question)&lt;br /&gt;a.Probabilistic algorithm&lt;br /&gt;b.Randomized algorithm&lt;br /&gt;c.Deterministic algorithm&lt;br /&gt;d.Non deterministic algorithm&lt;br /&gt;Ans:b&lt;br /&gt;Any algorithm that works for all practical purposes but has a theoretical chance of being wrong is called probabilistic algorithm.&lt;br /&gt;An algorithm whose behavior can be completely predicted from the input is called deterministic algorithm.&lt;br /&gt;A conceptual algorithm with more than one allowed step at certain times and which always takes the right or best step. It has the super computational characteristic of choosing the optimal behavior is called non-deterministic algorithm&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-111682316032316961?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/111682316032316961/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=111682316032316961' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/111682316032316961'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/111682316032316961'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/algorithms-interview-question-part-3.html' title='Algorithms Interview Question Part 3'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-4810273235882023131</id><published>2007-10-27T09:54:00.001-07:00</published><updated>2007-10-27T09:54:26.842-07:00</updated><title type='text'>Algorithms Interview Question Part2</title><content type='html'>13. Searches in which the entire table is constantly not in main memory is called as&lt;br /&gt;a. External search&lt;br /&gt;b. Internal search&lt;br /&gt;c. None of these&lt;br /&gt;d. All of these&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;14. The class of algorithms that remembers older results and attempts to use this to speed the process of finding new results is called      (practice test question)&lt;br /&gt;a. Dynamic Programming Algorithms&lt;br /&gt;b. Greedy Algorithms&lt;br /&gt;c. Backtracking Algorithms&lt;br /&gt;d. Divide and Conquer Algorithms&lt;br /&gt;Ans:a&lt;br /&gt;The algorithms that test for a solution, if one is found the algorithm is solved, if not it recurs once and tests again, continuing until a solution is found is called backtracking algorithm.&lt;br /&gt;&lt;br /&gt;15.  The class of algorithms that includes any algorithm that uses a random number at any point during its process.    (practice test question)&lt;br /&gt;a. Dynamic Programming Algorithms&lt;br /&gt;b.Randomized Algorithms &lt;br /&gt;c.Backtracking Algorithms&lt;br /&gt;d.Divide and Conquer Algorithms&lt;br /&gt;Ans:b&lt;br /&gt;The class of algorithms that remembers older results and attempts to use this to speed the process of finding new results is called dynamic programming algorithm.&lt;br /&gt;The algorithms that test for a solution, if one is found the algorithm is solved, if not it recurs once and tests again, continuing until a solution is found is called backtracking algorithm.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;16. The algorithms that form a tree of subproblems to the primary problem, following each branch until it is either solved or lumped in with another branch.   (practice test question)&lt;br /&gt;a. Dynamic Programming Algorithms&lt;br /&gt;b. Branch and Bound Algorithms&lt;br /&gt;c.Backtracking Algorithms&lt;br /&gt;d.Divide and Conquer Algorithms&lt;br /&gt;Ans:b&lt;br /&gt;The class of algorithms that remembers older results and attempts to use this to speed the process of finding new results is called dynamic programming algorithm.&lt;br /&gt;The algorithms that test for a solution, if one is found the algorithm is solved, if not it recurs once and tests again, continuing until a solution is found is called backtracking algorithm.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;17. This type of algorithm goes for a direct solution first, then backtracks to find a simpler solution.     (practice test question)&lt;br /&gt;a. Dynamic Programming Algorithms&lt;br /&gt;b. Branch and Bound Algorithms&lt;br /&gt;c. Simple Recursive Algorithms&lt;br /&gt;d.Divide and Conquer Algorithms&lt;br /&gt;Ans:c&lt;br /&gt;The class of algorithms that remembers older results and attempts to use this to speed the process of finding new results is called dynamic programming algorithm.&lt;br /&gt;The algorithms that form a tree of subproblems to the primary problem, following each branch until it is either solved or lumped in with another branch is called branch and bound algorithm.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-4810273235882023131?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/4810273235882023131/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=4810273235882023131' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4810273235882023131'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4810273235882023131'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/algorithms-interview-question-part2.html' title='Algorithms Interview Question Part2'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-5309909837712877754</id><published>2007-10-27T09:48:00.000-07:00</published><updated>2007-10-27T09:49:52.952-07:00</updated><title type='text'>Algorithms Interview Question Part1</title><content type='html'>1. An algorithm is a sequence of computational steps that transform the input into the output. True &lt;br /&gt;2. An algorithm is a tool for solving a well specified computational problem. True.&lt;br /&gt;3. An algorithm describes a specific computational procedure for achieving the input/output relationship. True.&lt;br /&gt;4. An algorithm is said to be correct if, for every input instance, it halts with the correct output. True.&lt;br /&gt;5. The study of algorithm is called as algorithmics.&lt;br /&gt;6. What is the purpose of algorithm validation?&lt;br /&gt;a. To assure that the algorithm produces the correct output for all legal inputs. &lt;br /&gt;b. To assure that the algorithm is accepting the legal inputs.&lt;br /&gt;c. To assure that the algorithm is not working.&lt;br /&gt;d. None of these.&lt;br /&gt;Ans:a&lt;br /&gt;7. Which of the following is not true…?&lt;br /&gt;a. An algorithm is a set of rules for carrying out calculation either by hand or on a machine. &lt;br /&gt;b. An algorithm is a finite step-by-step procedure to achieve a required result. &lt;br /&gt;c. An algorithm is a sequence of computational steps that transform the input into the output. &lt;br /&gt;d. None&lt;br /&gt;Ans:d&lt;br /&gt;&lt;br /&gt;8. Which of the following is true about Euclid’s Algorithm …&lt;br /&gt;a. Calculating the lowest common multiple of two integers.&lt;br /&gt;b. Calculating the greatest common divisor of two integers. &lt;br /&gt;c. Calculating the number of common factors between the two integers.&lt;br /&gt;d. None of these.&lt;br /&gt;Ans:b&lt;br /&gt;&lt;br /&gt;9. Two important ways to characterize the effectiveness of an algorithm…&lt;br /&gt;a. Time, space Complexity. &lt;br /&gt;b. Space,power Complexity&lt;br /&gt;c. Power, time Complexity.&lt;br /&gt;d. None of these.&lt;br /&gt;Ans:a&lt;br /&gt;&lt;br /&gt;10. A table of records in which a key is used for retrieval is often called as a&lt;br /&gt;a. Search table&lt;br /&gt;b. Dictionary&lt;br /&gt;c. None of these&lt;br /&gt;d. All of these&lt;br /&gt;Ans:a,b&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;11. A table or file can be organized in the form of&lt;br /&gt;a. Array&lt;br /&gt;b. Linked list&lt;br /&gt;c. Tree&lt;br /&gt;d. Graph&lt;br /&gt;Ans:a,b,c,d&lt;br /&gt;&lt;br /&gt;12. Searches in which the entire table is constantly in main memory is called as&lt;br /&gt;a. External search&lt;br /&gt;b. Internal search&lt;br /&gt;c. None of these&lt;br /&gt;d. All of these&lt;br /&gt;Ans:b&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-5309909837712877754?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/5309909837712877754/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=5309909837712877754' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5309909837712877754'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5309909837712877754'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/algorithms-interview-question-part1.html' title='Algorithms Interview Question Part1'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-562518040317172180</id><published>2007-10-26T12:53:00.001-07:00</published><updated>2007-10-26T12:53:53.770-07:00</updated><title type='text'>Java interview questions Part31</title><content type='html'>10. State the transactional behavior in a given scenario for an enterprise bean method with a specified transactional deployment descriptor.&lt;br /&gt;11.Given a requirement specification detailing security and flexibility needs, identify architectures that would fulfill those requirements.&lt;br /&gt;12. Identify costs and benefits of using an intermediate data-access object between an entity bean and the data resource.&lt;br /&gt;13. State the benefits of bean pooling in an EJB container.&lt;br /&gt;14. State the benefits of Passivation in an EJB container.&lt;br /&gt;15. State the benefit of monitoring of resources in an EJB container.&lt;br /&gt;16. Explain how the EJB container does lifecycle management and has the capability to increase scalability.&lt;br /&gt;17. Given a scenario description, distinguish appropriate from inappropriate protocols to implement that scenario.&lt;br /&gt;18. Identify a protocol, given a list of some of its features, where the protocol is one of the following: HTTP, HTTPS, IIOP, JRMP.&lt;br /&gt;19. Select from a list, common firewall features that might interfere with the normal operation of a given protocol.&lt;br /&gt;20. State the benefits of using design patterns.&lt;br /&gt;&lt;br /&gt;Given that 1119280000000L is roughly the number of milliseconds from Jan. 1, 1970, to June 20, 2005, and that you want to print that date in German, using the LONG style such that "June" will be displayed as "juni", complete the code using the fragments below. Note: you can use each fragment either zero or one times, and you might not need to fill all of the slots. &lt;br /&gt;&lt;br /&gt;Code: &lt;br /&gt;&lt;br /&gt;import Java.___________&lt;br /&gt;&lt;br /&gt;import Java.___________&lt;br /&gt;&lt;br /&gt;class DateTwo {&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    Date d = new Date(1119280000000L);&lt;br /&gt;&lt;br /&gt;    DateFormat df =__________________________&lt;br /&gt;&lt;br /&gt;                   _____________ , ______________ ) ;&lt;br /&gt;&lt;br /&gt;    System.out.println(_____________&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Fragments: &lt;br /&gt;&lt;br /&gt;io.*;     new DateFormat(                Locale.LONG&lt;br /&gt;nio.*;    DateFormat.getlnstance(        Locale.GERMANY&lt;br /&gt;util.*;   DateFormat.getDatelnstance(    DateFormat.LONG&lt;br /&gt;text.*;   util.regex;                    DateFormat.GERMANY&lt;br /&gt;date.*;   df.format(d));                 d.format(df));&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;12.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;import java.io.*;&lt;br /&gt;class Directories {&lt;br /&gt;  static String [] dirs = {"dirl", "dir2"};&lt;br /&gt;  public static void main(String [] args){&lt;br /&gt;    for (String d : dirs) {&lt;br /&gt;&lt;br /&gt;      // insert code 1 here&lt;br /&gt;&lt;br /&gt;      File file = new File(path, args[0]) ;&lt;br /&gt;&lt;br /&gt;      // insert code 2 here&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;and that the invocation&lt;br /&gt;&lt;br /&gt;java Directories file2.txt&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;is issued from a directory that has two subdirectories "dir1" and "dir1", and that "dir1" has a file "file1.txt" and "dir2" has a file "file2.txt", and the output is "false true"; which set(s) of code fragments must be inserted? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;String path = d; &lt;br /&gt;&lt;br /&gt;System.out.print (file.exists() + " "); &lt;br /&gt;&lt;br /&gt;String path = d; &lt;br /&gt;&lt;br /&gt;System.out .print (file . isFile() + " "); &lt;br /&gt;&lt;br /&gt;String path = File.separator + d; &lt;br /&gt;&lt;br /&gt;System.out .print (file . exists() + " "); &lt;br /&gt;&lt;br /&gt;String path = File.separator + d; &lt;br /&gt;&lt;br /&gt;System.out.print(file.isFile() + &lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;13.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class Polish {&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    int x = 4 ;&lt;br /&gt;    StringBuffer sb = new StringBuffer("..fedcba");&lt;br /&gt;    sb.delete(3,6);&lt;br /&gt;    sb.insert(3, "az");&lt;br /&gt;    if(sb.length() &gt; 6) x = sb.indexOf("b");&lt;br /&gt;    sb.delete((x-3), (x-2));&lt;br /&gt;    System.out.println(sb);&lt;br /&gt;} }&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;.faza &lt;br /&gt;&lt;br /&gt;.fzba &lt;br /&gt;&lt;br /&gt;..azba &lt;br /&gt;&lt;br /&gt;.fazba &lt;br /&gt;&lt;br /&gt;..fezba &lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;&lt;br /&gt;An exception is thrown at runtime.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;14.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;1. import java.util.*;&lt;br /&gt;2. class Brain {&lt;br /&gt;3.   public static void main(String[] args) {&lt;br /&gt;&lt;br /&gt;4.     // insert code block here&lt;br /&gt;&lt;br /&gt;5.   }&lt;br /&gt;6. }&lt;br /&gt;&lt;br /&gt;Which, inserted independently at line 4, compile and produce the output "123 82"? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;Scanner sc = new Scanner("123 A 3b c,45, x5x,76 82 L"); &lt;br /&gt;&lt;br /&gt;while(sc.hasNextInt()) System.out.print(sc.nextlnt() + " "); &lt;br /&gt;&lt;br /&gt;Scanner sc = new Scanner("123 A 3b c,45, x5x,76 82 L"). &lt;br /&gt;&lt;br /&gt;useDelimiter(" "); &lt;br /&gt;&lt;br /&gt;while(sc.hasNextlnt()) System.out.print(sc.nextlnt() + " "); &lt;br /&gt;&lt;br /&gt;Scanner sc = new Scanner("123 A 3b c,45, x5x,76 82 L"); &lt;br /&gt;&lt;br /&gt;useDelimiter(" "); &lt;br /&gt;&lt;br /&gt;while(sc.hasNext()) { &lt;br /&gt;&lt;br /&gt;if (sc.hasNextlnt()) System.out.print(sc.nextlnt() + " ") ; &lt;br /&gt;&lt;br /&gt;else sc.next(); } &lt;br /&gt;&lt;br /&gt;Scanner sc = new Scanner("123 A 3b c,45, x5x,76 82 L"). &lt;br /&gt;&lt;br /&gt;useDelimiter(" "); &lt;br /&gt;&lt;br /&gt;while(sc.hasNext()) } &lt;br /&gt;&lt;br /&gt;if (sc.hasNextlnt()) System.out.print(sc.nextlnt() + " ") ; &lt;br /&gt;&lt;br /&gt;else sc.next(); } &lt;br /&gt;&lt;br /&gt;Scanner sc = new Scanner ("123 A 3b c,45, x5x, 76 82 L"); &lt;br /&gt;&lt;br /&gt;do { &lt;br /&gt;&lt;br /&gt;if (sc.hasNextInt()) System.out.print (sc.nextInt() + ""); &lt;br /&gt;&lt;br /&gt;} while (sc.hasNext()); &lt;br /&gt;&lt;br /&gt;Scanner sc = new Scanner("12,3 A 3b c,45, x5x, 76 82 L"). &lt;br /&gt;&lt;br /&gt;useDelimiter(" "); &lt;br /&gt;&lt;br /&gt;do { &lt;br /&gt;&lt;br /&gt;if(sc.hasNextlnt()) System.out.print(sc.nextInt() + " "); &lt;br /&gt;&lt;br /&gt;} while ( sc.hasNext() ); &lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;15.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;import java.io.*;&lt;br /&gt;&lt;br /&gt;public class TestSer {&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    SpecialSerial s = new SpecialSerial() ;&lt;br /&gt;    try {&lt;br /&gt;      ObjectOutputStream os = new ObjectOutputStream(&lt;br /&gt;         new FileOutputStream("myFile"));&lt;br /&gt;      os.writeObject(s);  os. close();&lt;br /&gt;      System.out.print( + + s.z + " ");&lt;br /&gt;&lt;br /&gt;      ObjectlnputStream is = new ObjectlnputStream(&lt;br /&gt;         new FileInputStream("myFile"));&lt;br /&gt;      SpecialSerial s2 = (SpecialSerial)is.readObject();&lt;br /&gt;      is.close();&lt;br /&gt;      System.out.println(s2.y + " " + s2.z);&lt;br /&gt;    } catch (Exception x) {System.out.println("exc"); }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;class SpecialSerial implements Serializable {&lt;br /&gt;  transient int y = 7;&lt;br /&gt;  static int z = 9;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Which are true? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;&lt;br /&gt;The output is 10 0 9 &lt;br /&gt;&lt;br /&gt;The output is 10 0 10 &lt;br /&gt;&lt;br /&gt;The Output is 10 7 9 &lt;br /&gt;&lt;br /&gt;The output is 10 7 10 &lt;br /&gt;&lt;br /&gt;In order to alter the standard deserialization process you would override the readobject() method in SpecialSerial.&lt;br /&gt;&lt;br /&gt;In order to alter the standard deserialization process you would override the defaultReadObject() method in SpecialSerial.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-562518040317172180?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/562518040317172180/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=562518040317172180' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/562518040317172180'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/562518040317172180'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/java-interview-questions-part31.html' title='Java interview questions Part31'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-3381087123677825823</id><published>2007-10-26T12:51:00.000-07:00</published><updated>2007-10-26T12:52:17.085-07:00</updated><title type='text'>Java interview questions Part30</title><content type='html'>1. What do you understand by UML. How to interpret UML diagrams?&lt;br /&gt;2. State the effect of encapsulation, inheritance, and use of interfaces on architectural characteristics?&lt;br /&gt;3. Differentiate between 2 tier, 3 tier and n-tier architectures.&lt;br /&gt;4. How do the following characteristics scalability,performance, high availabilty behave based on the above architecture selected.&lt;br /&gt;5. In what all ways (methods/concepts) can we achieve integration with legacy/n-n-legacy applications using JAVA technologies.&lt;br /&gt;6. List the required classes/interfaces that must be provided for an EJB technology.&lt;br /&gt;7. Distinguish stateful and stateless Session beans.&lt;br /&gt;8. Distinguish Session and Entity beans.&lt;br /&gt;7.  &lt;br /&gt; Using the fewest fragments possible (and filling the fewest slots possible), complete the code below so that the class builds a directory named "dir3" and creates a file named "file3" inside "dir3". Note you can use each fragment either zero or one times.&lt;br /&gt;&lt;br /&gt;Code: &lt;br /&gt;&lt;br /&gt;import java.io.________________&lt;br /&gt;&lt;br /&gt;class Maker {&lt;br /&gt;  public static void main(String [] args) {&lt;br /&gt;    ___________  ___________  ___________&lt;br /&gt;    ___________  ___________  ___________&lt;br /&gt;    ___________  ___________  ___________&lt;br /&gt;    ___________  ___________  ___________&lt;br /&gt;    ___________  ___________  ___________&lt;br /&gt;    ___________  ___________  ___________&lt;br /&gt;    ___________  ___________  ___________&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Fragments: &lt;br /&gt;&lt;br /&gt;File;     FileDescriptor;     FileWriter;    Directory;&lt;br /&gt;try {     .createNewDir();    File dir       File&lt;br /&gt;{ }       (Exception x)       ("dir3");      file&lt;br /&gt;file      .createNewFile();   = new File     = new File&lt;br /&gt;dir       (dir, "file3");     (dir, file);   .createFile() ;&lt;br /&gt;} catch   ("dir3", "file3");  .mkdir();      File file&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;8.  &lt;br /&gt; Which are true? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;The DateFormat.getDate() is used to convert a String to a Date instance.&lt;br /&gt;&lt;br /&gt;Both DateFormat and NumberFormat objects can be constructed to be Locale specific.&lt;br /&gt;&lt;br /&gt;Both Currency and NumberFormat objects must be constructed using static methods.&lt;br /&gt;&lt;br /&gt;If a NumberFormat instance's Locale is to be different than the current Locale, it must be specified at creation time.&lt;br /&gt;&lt;br /&gt;A single instance of NumberFormat can be used to create Number objects from Strings and to create formatted numbers from numbers.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;9.  &lt;br /&gt; Which will compile and run without exception? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;System.out.format("%b", 123); &lt;br /&gt;&lt;br /&gt;System.out.format("%c", "x"); &lt;br /&gt;&lt;br /&gt;System.out.printf("%d", 123); &lt;br /&gt;&lt;br /&gt;System.out.printf("%f", 123); &lt;br /&gt;&lt;br /&gt;System.out.printf("%d", 123.45); &lt;br /&gt;&lt;br /&gt;System out. printf ("%f", 123.45); &lt;br /&gt;&lt;br /&gt;System.out.format("%s", new Long("123")); &lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;10.  &lt;br /&gt; Which about the three java.lang classes String, StringBuilder, and StringBuffer are true? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;All three classes have a length() method.&lt;br /&gt;&lt;br /&gt;Objects of type StringBuffer are thread-safe.&lt;br /&gt;&lt;br /&gt;All three classes have overloaded append() methods.&lt;br /&gt;&lt;br /&gt;The "+" is an overloaded operator for all three classes.&lt;br /&gt;&lt;br /&gt;According to the API, StringBuffer will be faster than StringBuilder under most implementations.&lt;br /&gt;&lt;br /&gt;The value of an instance of any of these three types can be modified through various methods in the API.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-3381087123677825823?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/3381087123677825823/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=3381087123677825823' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/3381087123677825823'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/3381087123677825823'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/java-interview-questions-part30_26.html' title='Java interview questions Part30'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-8908528686736387142</id><published>2007-10-26T12:50:00.001-07:00</published><updated>2007-10-26T12:50:54.733-07:00</updated><title type='text'>Java interview questions Part30</title><content type='html'>Given:&lt;br /&gt;&lt;br /&gt;import java.util.regex.*;&lt;br /&gt;class Regex2 {&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    Pattern p = Pattern.compile(args[o]);&lt;br /&gt;    Matcher m = p.matcher(args[1]);&lt;br /&gt;    boolean b = false;&lt;br /&gt;    while(b = m.find()) {&lt;br /&gt;      System.out.print(m.start() + m.group());&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;And the command line:&lt;br /&gt;&lt;br /&gt;java Regex2 "\d*" ab34ef&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;234 &lt;br /&gt;&lt;br /&gt;334 &lt;br /&gt;&lt;br /&gt;2334 &lt;br /&gt;&lt;br /&gt;0123456 &lt;br /&gt;&lt;br /&gt;01234456 &lt;br /&gt;&lt;br /&gt;12334567 &lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;2.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;import java.io.*;&lt;br /&gt;class Player {&lt;br /&gt;  Player() { System.out.print("p"); }&lt;br /&gt;}&lt;br /&gt;class CardPlayer extends Player implements Serializable {&lt;br /&gt;  CardPlayer() { System.out.print("c"); }&lt;br /&gt;  public static void main(String[] args){&lt;br /&gt;    CardPlayer cl = new CardPlayer();&lt;br /&gt;&lt;br /&gt;    try {&lt;br /&gt;      FileOutputStream fos = new FileOutputStream("play.txt");&lt;br /&gt;      ObjectOutputStream os = new ObjectOutputStream(fos);&lt;br /&gt;      os.writeObject(c1);&lt;br /&gt;      os.close() ;&lt;br /&gt;      FileInputStream fis = new FileInputStream("play.txt");&lt;br /&gt;      ObjectInputStream is = new ObjectInputStream(fis);&lt;br /&gt;      CardPlayer c2 = (CardPlayer) is.readObject();&lt;br /&gt;      is.close();&lt;br /&gt;    } catch (Exception x ) { }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;pc &lt;br /&gt;&lt;br /&gt;pcc &lt;br /&gt;&lt;br /&gt;pcp &lt;br /&gt;&lt;br /&gt;pcpc &lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;&lt;br /&gt;An exception is thrown at runtime.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;3.  &lt;br /&gt; Given that bw is a reference to a valid BufferedWriter &lt;br /&gt;&lt;br /&gt;And the snippet:&lt;br /&gt;&lt;br /&gt;15.  BufferedWriter b1 = new BufferedWriter(new File("f"));&lt;br /&gt;16.  BufferedWriter b2 = new BufferedWriter(new FileWriter("f1"));&lt;br /&gt;17.  BufferedWriter b3 = new BufferedWriter(new PrintWriter("f2"));&lt;br /&gt;18.  BufferedWriter b4 = new BufferedWriter(new BufferedWriter(bw));&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;Compilation succeeds.&lt;br /&gt;&lt;br /&gt;Compilation fails due only to an error on line 15.&lt;br /&gt;&lt;br /&gt;Compilation fails due only to an error on line 16.&lt;br /&gt;&lt;br /&gt;Compilation fails due only to an error on line 17.&lt;br /&gt;&lt;br /&gt;Compilation fails due only to an error on line 18.&lt;br /&gt;&lt;br /&gt;Compilation fails due to errors on multiple lines.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;4.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;Class TKO {&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    String s = "-";&lt;br /&gt;    Integer x = 343;&lt;br /&gt;    long L343 = 343L;&lt;br /&gt;    if(x.equals(L343)) s += ".e1 ";&lt;br /&gt;    if(x.equals(343)) s += ".e2 ";&lt;br /&gt;    Short s1 = (short)((new Short((short)343)) / (new Short((short)49)));&lt;br /&gt;    if (s1 == 7)       s += "=s ";&lt;br /&gt;    if(sl &lt; new Integer(7+1)) s += "fly ";&lt;br /&gt;    System.out.println(s);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Which of the following will be included in the output String s? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;.e1 &lt;br /&gt;&lt;br /&gt;.e2 &lt;br /&gt;&lt;br /&gt;=s &lt;br /&gt;&lt;br /&gt;fly &lt;br /&gt;&lt;br /&gt;None of the above.&lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;&lt;br /&gt;An exception is thrown at runtime.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;5.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;1. import java.text.*;&lt;br /&gt;2. class DateOne {&lt;br /&gt;3.   public static void main(String[] args) {&lt;br /&gt;4.     Date d = new Date(1123631685981L);&lt;br /&gt;5.     DateFormat df = new DateFormat();&lt;br /&gt;6.     System.out.println(df.format(d));&lt;br /&gt;7.   }&lt;br /&gt;8. }&lt;br /&gt;&lt;br /&gt;And given that 1123631685981L is the number of milliseconds between Jan. 1, 1970, and sometime on Aug. 9, 2005, what is the result? (Note: the time of day in option A may vary.) &lt;br /&gt;&lt;br /&gt;8/9/05 5:54 PM&lt;br /&gt;&lt;br /&gt;1123631685981L,&lt;br /&gt;&lt;br /&gt;An exception is thrown at runtime.&lt;br /&gt;&lt;br /&gt;Compilation fails due to a single error in the code.&lt;br /&gt;&lt;br /&gt;Compilation fails due to multiple errors in the code.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;6.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;import java.io.*;&lt;br /&gt;&lt;br /&gt;class Keyboard { }&lt;br /&gt;public class Computer implements Serializable {&lt;br /&gt;  private Keyboard k = new Keyboard();&lt;br /&gt;  public static void main(String[] args)&lt;br /&gt;    Computer c = new Computer();&lt;br /&gt;    c.storeIt(c) ;&lt;br /&gt;  }&lt;br /&gt;  void storeIt(Computer c) {&lt;br /&gt;    try {&lt;br /&gt;      ObjectOutputStream os = new ObjectOutputStream(&lt;br /&gt;         new FileOutputStream("myFile"));&lt;br /&gt;      os.writeObject(c);&lt;br /&gt;      os.close() ;&lt;br /&gt;      System.out.println("done");&lt;br /&gt;    } catch (Exception x) {System.out.println("exc"); } }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What is the result? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;exc &lt;br /&gt;&lt;br /&gt;done &lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;&lt;br /&gt;Exactly one object is serialized.&lt;br /&gt;&lt;br /&gt;Exactly two objects are serialized&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-8908528686736387142?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/8908528686736387142/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=8908528686736387142' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/8908528686736387142'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/8908528686736387142'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/java-interview-questions-part30.html' title='Java interview questions Part30'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-6320751689870789520</id><published>2007-10-26T12:49:00.002-07:00</published><updated>2007-10-26T12:50:07.520-07:00</updated><title type='text'>Java interview questions Part29</title><content type='html'>Given:&lt;br /&gt;&lt;br /&gt;class Emu {&lt;br /&gt;  static String s = "-";&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    try {&lt;br /&gt;      throw new Exception();&lt;br /&gt;    } catch (Exception e) {&lt;br /&gt;        try {&lt;br /&gt;          try { throw new Exception();&lt;br /&gt;          } catch (Exception ex) { s += "ic "; }&lt;br /&gt;          throw new Exception(); }&lt;br /&gt;        catch (Exception x) { s += "mc "; }&lt;br /&gt;        finally { s += "mf "; }&lt;br /&gt;    } finally { s += "of "; }&lt;br /&gt;    System.out.println(s);&lt;br /&gt;} }&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;-ic of &lt;br /&gt;&lt;br /&gt;-mf of &lt;br /&gt;&lt;br /&gt;-mc mf &lt;br /&gt;&lt;br /&gt;-ic mf of &lt;br /&gt;&lt;br /&gt;-ic mc mf of &lt;br /&gt;&lt;br /&gt;-ic mc of mf &lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;15.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class Mineral { }&lt;br /&gt;class Gem extends Mineral { }&lt;br /&gt;class Miner {&lt;br /&gt;  static int x = 7;&lt;br /&gt;  static String s = null;&lt;br /&gt;  public static void getWeight(Mineral m) {&lt;br /&gt;    int y = 0 / x;&lt;br /&gt;    System.out.print(s + " ");&lt;br /&gt;  }&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    Mineral[] ma = {new Mineral(), new Gem()};&lt;br /&gt;&lt;br /&gt;   for(Object o : ma)&lt;br /&gt;     getWeight((Mineral) o);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;And the command-line invocation:&lt;br /&gt;&lt;br /&gt;java Miner.java&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;null &lt;br /&gt;&lt;br /&gt;null null &lt;br /&gt;&lt;br /&gt;A ClassCastException is thrown.&lt;br /&gt;&lt;br /&gt;A NullPointerException is thrown.&lt;br /&gt;&lt;br /&gt;A NoClassDefFoundError is thrown.&lt;br /&gt;&lt;br /&gt;An ArithmeticException is thrown.&lt;br /&gt;&lt;br /&gt;An IllegalArgumentException is thrown.&lt;br /&gt;&lt;br /&gt;An ArrayIndexOutOfBoundsException is thrown.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;16.  &lt;br /&gt; Which are most typically thrown by an API developer or an application developer as opposed to being thrown by the JVM? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;ClassCastException &lt;br /&gt;&lt;br /&gt;IllegalStateException &lt;br /&gt;&lt;br /&gt;NumberFormatException &lt;br /&gt;&lt;br /&gt;IllegalArgumentException &lt;br /&gt;&lt;br /&gt;ExceptionInInitializerError&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-6320751689870789520?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/6320751689870789520/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=6320751689870789520' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/6320751689870789520'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/6320751689870789520'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/java-interview-questions-part29.html' title='Java interview questions Part29'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-7912689705833789058</id><published>2007-10-26T12:49:00.001-07:00</published><updated>2007-10-26T12:49:42.806-07:00</updated><title type='text'>Java interview questions Part27</title><content type='html'>Given:&lt;br /&gt;&lt;br /&gt;1. class Crivitch {&lt;br /&gt;2.   public static void main(String [] args) {&lt;br /&gt;3.     int x = 0;&lt;br /&gt;4.     // insert code here&lt;br /&gt;5.     do { } while (x++ &lt; y);&lt;br /&gt;6.     System.out.println(x);&lt;br /&gt;7.   }&lt;br /&gt;8. }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Which, inserted at line 4, produces the output 12?&lt;br /&gt;&lt;br /&gt;int y = x; &lt;br /&gt;&lt;br /&gt;int y = 10; &lt;br /&gt;&lt;br /&gt;int y = 11; &lt;br /&gt;&lt;br /&gt;int y = 12; &lt;br /&gt;&lt;br /&gt;int y = 13; &lt;br /&gt;&lt;br /&gt;None of the above will allow compilation to succeed.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;6.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class Plane {&lt;br /&gt;  static String s = "-";&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    new Plane().s1() ;&lt;br /&gt;    System.out.println(s);&lt;br /&gt;  }&lt;br /&gt;  void sl() {&lt;br /&gt;    try { s2();&lt;br /&gt;    catch (Exception e) { s += "c"; }&lt;br /&gt;  }&lt;br /&gt;  void s2() throws Exception  {&lt;br /&gt;    s3();  s += "2";&lt;br /&gt;    s3();  s += "2b";&lt;br /&gt;  }&lt;br /&gt;  void s3() throws Exception {&lt;br /&gt;    throw new Exception();&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;-&lt;br /&gt;&lt;br /&gt;-c &lt;br /&gt;&lt;br /&gt;-c2 &lt;br /&gt;&lt;br /&gt;-2c &lt;br /&gt;&lt;br /&gt;-c22b &lt;br /&gt;&lt;br /&gt;-2c2b &lt;br /&gt;&lt;br /&gt;-2c2bc &lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;7.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;try { int x = Integer.parselnt("two"); }&lt;br /&gt;&lt;br /&gt;Which could be used to create an appropriate catch block? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;ClassCastException &lt;br /&gt;&lt;br /&gt;IllegalStateException &lt;br /&gt;&lt;br /&gt;NumberFormatException &lt;br /&gt;&lt;br /&gt;IllegalArgumentException &lt;br /&gt;&lt;br /&gt;ExceptionInInitializerError &lt;br /&gt;&lt;br /&gt;ArrayIndexOutOfBoundsException &lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;8.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt; 1. class Ping extends Utils {&lt;br /&gt; 2.   public static void main(String [] args) {&lt;br /&gt; 3.     Utils u = new Ping();&lt;br /&gt; 4.     System.out.print(u.getInt(args[0]));&lt;br /&gt; 5.   }&lt;br /&gt; 6.   int getInt(String arg) {&lt;br /&gt; 7.     return Integer.parseInt(arg);&lt;br /&gt; 8.   }&lt;br /&gt; 9. }&lt;br /&gt;10. class Utils {&lt;br /&gt;11.   int getInt(String x) throws Exception { return 7; }&lt;br /&gt;12. }&lt;br /&gt;&lt;br /&gt;And the following three possible changes:&lt;br /&gt;&lt;br /&gt;C1. Declare that main() throws an Exception.&lt;br /&gt;&lt;br /&gt;C2. Declare that Ping.getInt() throws an Exception.&lt;br /&gt;&lt;br /&gt;C3. Wrap the invocation of getInt() in a try / catch block.&lt;br /&gt;&lt;br /&gt;Which change(s) allow the code to compile? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;Just C1 is sufficient.&lt;br /&gt;&lt;br /&gt;Just C2 is sufficient.&lt;br /&gt;&lt;br /&gt;Just C3 is sufficient.&lt;br /&gt;&lt;br /&gt;Both C1 and C2 are required.&lt;br /&gt;&lt;br /&gt;Both C1 and C3 are required.&lt;br /&gt;&lt;br /&gt;Both C2 and C3 are required.&lt;br /&gt;&lt;br /&gt;All three changes are required.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;9.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class Swill {&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    String s = "-";&lt;br /&gt;    switch(TimeZone.CST) {&lt;br /&gt;      case EST: s += "e";&lt;br /&gt;      case CST: s += "c";&lt;br /&gt;      case MST: s += "m";&lt;br /&gt;      default:  s += "X";&lt;br /&gt;      case PST: s += "p";&lt;br /&gt;    }&lt;br /&gt;    System.out.println(s);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;enum TimeZone {EST, CST, MST, PST }&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;-c &lt;br /&gt;&lt;br /&gt;-X &lt;br /&gt;&lt;br /&gt;-cm &lt;br /&gt;&lt;br /&gt;-cmp &lt;br /&gt;&lt;br /&gt;-cmXp &lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;&lt;br /&gt;An exception is thrown at runtime.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;10.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class Circus {&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    int x = 9;&lt;br /&gt;    int y = 6;&lt;br /&gt;    for(int z = 0; z &lt; 6; z++, y--) {&lt;br /&gt;      if(x &gt; 2)  x--;&lt;br /&gt;      label:&lt;br /&gt;        if(x &gt; 5) {&lt;br /&gt;          System.out.print(x + " "};&lt;br /&gt;          --X;&lt;br /&gt;          continue label;&lt;br /&gt;&lt;br /&gt;           }&lt;br /&gt;         X--;&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;8 &lt;br /&gt;&lt;br /&gt;8 7 &lt;br /&gt;&lt;br /&gt;8 7 6 &lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;&lt;br /&gt;An exception is thrown at runtime.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;11.  &lt;br /&gt; Which are true? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;It is appropriate to use assertions to validate arguments to methods marked public.&lt;br /&gt;&lt;br /&gt;It is appropriate to catch and handle assertion errors.&lt;br /&gt;&lt;br /&gt;It is NOT appropriate to use assertions to validate command-line arguments.&lt;br /&gt;&lt;br /&gt;It is appropriate to use assertions to generate alerts when you reach code that should not be reachable.&lt;br /&gt;&lt;br /&gt;It is NOT appropriate for assertions to change a program's state.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;12.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;1. class Loopy {&lt;br /&gt;2.   public static void main(String[] args) {&lt;br /&gt;3.     int[] x = {7,6,5,4,3,2,1};&lt;br /&gt;4.     // insert code here&lt;br /&gt;5.       System.out.print(y + " ");&lt;br /&gt;6.     }&lt;br /&gt;7.   }&lt;br /&gt;8. }&lt;br /&gt;&lt;br /&gt;Which, inserted independently at line 4, compiles? (Choose all that apply.) &lt;br /&gt;&lt;br /&gt;for(int y : x) { &lt;br /&gt;&lt;br /&gt;for(x : Int y) { &lt;br /&gt;&lt;br /&gt;int y = 0; for(y : x) { &lt;br /&gt;&lt;br /&gt;for(int y=0, z=0; z&lt;x.length; z++) { y = x[z]; &lt;br /&gt;&lt;br /&gt;for(int y=0, int z=0, int z=0; z&lt;x.length; z++) { y = x[z]; &lt;br /&gt;&lt;br /&gt;int y = 0; for(int z=0; z&lt;x.length; z++) { y = x[z]; &lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;13.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt; 1. class Ring {&lt;br /&gt; 2.   final static int x2 = 7;&lt;br /&gt; 3.   final static Integer x4 = 8;&lt;br /&gt; 4.   public static void main(String[] args) {&lt;br /&gt; 5.     Integer x1 = 5;&lt;br /&gt; 6.     String s = "a";&lt;br /&gt; 7.     if(xl &lt; 9) s += "b";&lt;br /&gt; 8.     switch(x1) {&lt;br /&gt; 9.       case 5:  s += "c";&lt;br /&gt;10.       case x2: s += "d";&lt;br /&gt;11.       case x4: s += "e";&lt;br /&gt;12.     }&lt;br /&gt;13.     System.out.println(s);&lt;br /&gt;14.   }&lt;br /&gt;15. }&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;abc &lt;br /&gt;&lt;br /&gt;abcde &lt;br /&gt;&lt;br /&gt;Compilation fails due only to an error on line 7.&lt;br /&gt;&lt;br /&gt;Compilation fails due only to an error on line 8.&lt;br /&gt;&lt;br /&gt;Compilation fails due only to an error on line 10.&lt;br /&gt;&lt;br /&gt;Compilation fails due only to an error on line 11.&lt;br /&gt;&lt;br /&gt;Compilation fails due to errors on multiple lines.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-7912689705833789058?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/7912689705833789058/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=7912689705833789058' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7912689705833789058'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7912689705833789058'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/java-interview-questions-part27.html' title='Java interview questions Part27'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-6705935388994242687</id><published>2007-10-26T12:48:00.001-07:00</published><updated>2007-10-26T12:48:40.747-07:00</updated><title type='text'>Java interview questions Part22</title><content type='html'>Given the following code:&lt;br /&gt;&lt;br /&gt;public class OrtegorumFunction {&lt;br /&gt;  public int computeDiscontinuous(int x) {&lt;br /&gt;    int r = 1;&lt;br /&gt;    r += X;&lt;br /&gt;    if ((x &gt; 4) &amp;&amp; (x &lt; 10)) {&lt;br /&gt;      r += 2 * x;&lt;br /&gt;    } else (x &lt;= 4) {&lt;br /&gt;      r += 3 * x;&lt;br /&gt;    } else {&lt;br /&gt;      r += 4 * x;&lt;br /&gt;    }&lt;br /&gt;    r += 5 * x;&lt;br /&gt;    return r;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public static void main(String [] args) {&lt;br /&gt;    OrtegorumFunction o = new OrtegorumFunction();&lt;br /&gt;    System.out.println("OF(11) is: " + o.computeDiscontinuous (11));&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;OF(11) is: 45 &lt;br /&gt;&lt;br /&gt;OF(11) is: 56 &lt;br /&gt;&lt;br /&gt;OF(11) is: 89 &lt;br /&gt;&lt;br /&gt;OF(11) is: 111 &lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;&lt;br /&gt;An exception is thrown at runtime.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;2.  &lt;br /&gt; Given two files:&lt;br /&gt;&lt;br /&gt;1. class One {&lt;br /&gt;2.   public static void main(String[] args) {&lt;br /&gt;3.     int assert = 0;&lt;br /&gt;4.   }&lt;br /&gt;5. }&lt;br /&gt;&lt;br /&gt;1. class Two {&lt;br /&gt;2.   public static void main(String[] args) {&lt;br /&gt;&lt;br /&gt;3.      assert(false);&lt;br /&gt;4.    }&lt;br /&gt;5. }&lt;br /&gt;&lt;br /&gt;And the four command-line invocations:&lt;br /&gt;&lt;br /&gt;javac -source 1.3 One.java&lt;br /&gt;javac -source 1.4 One.java&lt;br /&gt;javac -source 1.3 Two.java&lt;br /&gt;javac -source 1.4 Two.java&lt;br /&gt;&lt;br /&gt;What is the result? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;Only one compilation will succeed.&lt;br /&gt;&lt;br /&gt;Exactly two compilations will succeed.&lt;br /&gt;&lt;br /&gt;Exactly three compilations will succeed.&lt;br /&gt;&lt;br /&gt;All four compilations will succeed.&lt;br /&gt;&lt;br /&gt;No compiler warnings will be produced.&lt;br /&gt;&lt;br /&gt;At least one compiler warning will be produced.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;3.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;import java.io.*;&lt;br /&gt;class Master {&lt;br /&gt;  String doFileStuff() throws FileNotFoundException { return "a"; }&lt;br /&gt;}&lt;br /&gt;class Slave extends Master {&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    String s = null;&lt;br /&gt;    try { s = new Slave().doFileStuff();&lt;br /&gt;    } catch ( Exception x) {&lt;br /&gt;      s = "b"; }&lt;br /&gt;    System.out.println(s);&lt;br /&gt;  }&lt;br /&gt;  // insert code here&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Which, inserted independently at // insert code here, will compile, and produce the output b? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;String doFileStuff() { return "b"; } &lt;br /&gt;&lt;br /&gt;String doFileStuff() throws IOException ( return "b"; } &lt;br /&gt;&lt;br /&gt;String doFileStuff(int. x) throws IOException ( return "b"; } &lt;br /&gt;&lt;br /&gt;String doFileStuff() throws FileNotFoundException { return "b"; } &lt;br /&gt;&lt;br /&gt;String doFileStuff() throws NumberFormatException { return "b"; } &lt;br /&gt;&lt;br /&gt;String doFileStuff() throws NumberFormatException, FileNotFoundException { return "b"; } &lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;4.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class Input {&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    String s = "- " ;&lt;br /&gt;    try {&lt;br /&gt;      doMath(args[0]);&lt;br /&gt;      s += "t ";        // line 6&lt;br /&gt;    }&lt;br /&gt;    finally { System.out.println(s += "f "); }&lt;br /&gt;  }&lt;br /&gt;  public static void doMath(String a) {&lt;br /&gt;    int y = 7 / Integer.parseInt(a);&lt;br /&gt;} }&lt;br /&gt;&lt;br /&gt;And the command-line invocations:&lt;br /&gt;&lt;br /&gt;java Input&lt;br /&gt;java Input 0&lt;br /&gt;&lt;br /&gt;Which are true? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;Line 6 is executed exactly 0 times.&lt;br /&gt;&lt;br /&gt;Line 6 is executed exactly 1 time.&lt;br /&gt;&lt;br /&gt;Line 6 is executed exactly 2 times.&lt;br /&gt;&lt;br /&gt;The finally block is executed exactly 0 times.&lt;br /&gt;&lt;br /&gt;The finally block is executed exactly 1 time.&lt;br /&gt;&lt;br /&gt;The finally block is executed exactly 2 times.&lt;br /&gt;&lt;br /&gt;Both invocations produce the same exceptions.&lt;br /&gt;&lt;br /&gt;Each invocation produces a different exception.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-6705935388994242687?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/6705935388994242687/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=6705935388994242687' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/6705935388994242687'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/6705935388994242687'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/java-interview-questions-part22_2629.html' title='Java interview questions Part22'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-7903551049508667241</id><published>2007-10-26T12:46:00.000-07:00</published><updated>2007-10-26T12:47:01.233-07:00</updated><title type='text'>Java interview questions Part26</title><content type='html'>Given:&lt;br /&gt;&lt;br /&gt;class Foozit {&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    Integer x = 0;&lt;br /&gt;    Integer y = 0;&lt;br /&gt;    for(Short z = 0; z &lt; 5; z++)&lt;br /&gt;      if((++x &gt; 2) || (++y &gt; 2))&lt;br /&gt;        X++ ;&lt;br /&gt;    System.out.println (x + " " + y);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;5 1 &lt;br /&gt;&lt;br /&gt;5 2 &lt;br /&gt;&lt;br /&gt;5 3 &lt;br /&gt;&lt;br /&gt;8 1 &lt;br /&gt;&lt;br /&gt;8 2 &lt;br /&gt;&lt;br /&gt;8 3 &lt;br /&gt;&lt;br /&gt;10 2 &lt;br /&gt;&lt;br /&gt;10 3 &lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;6.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class Titanic {&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    Boolean bl = true;&lt;br /&gt;    boolean b2 = false;&lt;br /&gt;    boolean b3 = true;&lt;br /&gt;    if((bl &amp; b2) | (b2 &amp; b3) &amp; b3)&lt;br /&gt;      System.out.print("alpha ");&lt;br /&gt;    if((bl = false) | (b1 &amp; b3) | (bl | b2))&lt;br /&gt;      System.out.print("beta "};&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;beta &lt;br /&gt;&lt;br /&gt;alpha &lt;br /&gt;&lt;br /&gt;alpha beta &lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;&lt;br /&gt;No output is produced.&lt;br /&gt;&lt;br /&gt;An exception is thrown at runtime.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;7.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class Feline {&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    Long x = 42L;&lt;br /&gt;    Long y = 44L;&lt;br /&gt;    System.out.print (" " + 7 + 2 + " ") ;&lt;br /&gt;    System.out.print(foo () + x + 5 + " ");&lt;br /&gt;    System.out.println(x + y + foo());&lt;br /&gt;  }&lt;br /&gt;  static String foo() { return "foo"; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;9 foo47 86foo &lt;br /&gt;&lt;br /&gt;9 foo47 4244foo &lt;br /&gt;&lt;br /&gt;9 foo425 86foo &lt;br /&gt;&lt;br /&gt;9 foo425 4244foo &lt;br /&gt;&lt;br /&gt;72 foo47 86foo &lt;br /&gt;&lt;br /&gt;72 foo47 4244foo &lt;br /&gt;&lt;br /&gt;72 foo425 86foo &lt;br /&gt;&lt;br /&gt;72 foo425 4244foo &lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;8.  &lt;br /&gt; Place the fragments into the code to produce the output 33. Note, you must use each fragment exactly once.&lt;br /&gt;&lt;br /&gt;CODE:&lt;br /&gt;&lt;br /&gt;class Incr {&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    Integer x = 7;&lt;br /&gt;    int y = 2 ;&lt;br /&gt;&lt;br /&gt;    X    ___  ___;&lt;br /&gt;    ___  ___  ___;&lt;br /&gt;    ___  ___  ___;&lt;br /&gt;    ___  ___  ___;&lt;br /&gt;&lt;br /&gt;    System.out.println(x);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;FRAGMENTS:&lt;br /&gt;&lt;br /&gt;Y &lt;br /&gt; Y &lt;br /&gt; Y &lt;br /&gt; Y &lt;br /&gt; &lt;br /&gt;y &lt;br /&gt; x &lt;br /&gt; x &lt;br /&gt;   &lt;br /&gt;-= &lt;br /&gt; *= &lt;br /&gt; *= &lt;br /&gt; *= &lt;br /&gt; &lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;9.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;1. class Maybe {&lt;br /&gt;2.   public static void main(String[] args) {&lt;br /&gt;3.     boolean bl = true;&lt;br /&gt;4.     boolean b2 = false;&lt;br /&gt;5.     System.out.print(!false ^ false);&lt;br /&gt;6.     System.out.print(" " + (!b1 &amp; (b2 = true)));&lt;br /&gt;7.     System.out.println(" " + (b2 ^ b1));&lt;br /&gt;8.   }&lt;br /&gt;9. }&lt;br /&gt;&lt;br /&gt;Which are true?&lt;br /&gt;&lt;br /&gt;Line 5 produces true.&lt;br /&gt;&lt;br /&gt;Line 5 produces false.&lt;br /&gt;&lt;br /&gt;Line 6 produces true.&lt;br /&gt;&lt;br /&gt;Line 6 produces false.&lt;br /&gt;&lt;br /&gt;Line 7 produces true.&lt;br /&gt;&lt;br /&gt;Line 7 produces false.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;10.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class Sixties {&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    int x = 5;  int y = 7 ;&lt;br /&gt;    System.out.print(((y * 2) % x));&lt;br /&gt;    System.out.print(" " + (y % x));&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;1 1 &lt;br /&gt;&lt;br /&gt;1 2 &lt;br /&gt;&lt;br /&gt;2 1 &lt;br /&gt;&lt;br /&gt;2 2 &lt;br /&gt;&lt;br /&gt;4 1 &lt;br /&gt;&lt;br /&gt;4 2 &lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;&lt;br /&gt;An exception is thrown at runtime&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-7903551049508667241?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/7903551049508667241/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=7903551049508667241' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7903551049508667241'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7903551049508667241'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/java-interview-questions-part26_26.html' title='Java interview questions Part26'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-2355353619719600568</id><published>2007-10-26T12:45:00.004-07:00</published><updated>2007-10-26T12:46:23.400-07:00</updated><title type='text'>Java interview questions Part26</title><content type='html'>Given:&lt;br /&gt;&lt;br /&gt;class Hexy {&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    Integer i = 42;&lt;br /&gt;    String s = (i&lt;40)?"life":(i&gt;50)?"universe":"everything";&lt;br /&gt;    System.out.println(s);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;null &lt;br /&gt;&lt;br /&gt;life &lt;br /&gt;&lt;br /&gt;universe &lt;br /&gt;&lt;br /&gt;everything &lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;&lt;br /&gt;An exception is thrown at runtime.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;2.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;1. class Example {&lt;br /&gt;2.   public static void main(String[] args) {&lt;br /&gt;3.     Short s = 15;&lt;br /&gt;4.     Boolean b;&lt;br /&gt;5.     // insert code here&lt;br /&gt;6.   }&lt;br /&gt;7. }&lt;br /&gt;&lt;br /&gt;Which, inserted independently at line 5, will compile? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;b = (Number instanceof s); &lt;br /&gt;&lt;br /&gt;b = (s instanceof Short); &lt;br /&gt;&lt;br /&gt;b = s.instanceof(Short); &lt;br /&gt;&lt;br /&gt;b = (s instanceof Number); &lt;br /&gt;&lt;br /&gt;b = s.instanceof(Object); &lt;br /&gt;&lt;br /&gt;b = (s instanceof String); &lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;3.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt; 1. class Comp2 {&lt;br /&gt; 2.   public static void main(String[] args) {&lt;br /&gt; 3.     float f1 = 2.3f;&lt;br /&gt; 4.     float[][] f2 = {{42.Of}, {l.7f, 2.3f}, {2.6f, 2.7f}};&lt;br /&gt; 5.     float[] f3 = {2.7f};&lt;br /&gt; 6.     Long x = 42L;&lt;br /&gt; 7.     // insert code here&lt;br /&gt; 8.       System.out.println("true");&lt;br /&gt; 9.   }&lt;br /&gt;10. }&lt;br /&gt;&lt;br /&gt;And the following five code fragments:&lt;br /&gt;&lt;br /&gt;F1.  if (f1 == f2)&lt;br /&gt;F2.  if (f1 == f2[2][1])&lt;br /&gt;F3.  if (x == f2[0][0])&lt;br /&gt;F4.  if (f1 == f2 [1,1] )&lt;br /&gt;F5.  if (f3 == f2 [2] )&lt;br /&gt;&lt;br /&gt;What is true?&lt;br /&gt;&lt;br /&gt;One of them will compile, only one will be true.&lt;br /&gt;&lt;br /&gt;Two of them will compile, only one will be true.&lt;br /&gt;&lt;br /&gt;Two of them will compile, two will be true.&lt;br /&gt;&lt;br /&gt;Three of them will compile, only one will be true.&lt;br /&gt;&lt;br /&gt;Three of them will compile, exactly two will be true.&lt;br /&gt;&lt;br /&gt;Three of them will compile, exactly three will be true.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;4.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class  Fork {&lt;br /&gt;  public static void main(String[] args)    {&lt;br /&gt;    if(args.length == 1 | args[1] .equals("test")) {&lt;br /&gt;      System.out.println ("test  case");&lt;br /&gt;    } else {&lt;br /&gt;      System.out.println("production " + args[0]) ;&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;And the command-line invocation:&lt;br /&gt;&lt;br /&gt;java Fork live2&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;test case &lt;br /&gt;&lt;br /&gt;production &lt;br /&gt;&lt;br /&gt;test case live2 &lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;&lt;br /&gt;An exception is thrown at runtime.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;5.  &lt;br /&gt; Given:&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-2355353619719600568?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/2355353619719600568/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=2355353619719600568' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2355353619719600568'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2355353619719600568'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/java-interview-questions-part26.html' title='Java interview questions Part26'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-5477313037347126623</id><published>2007-10-26T12:45:00.003-07:00</published><updated>2007-10-26T12:45:47.881-07:00</updated><title type='text'>Java interview questions Part25</title><content type='html'>14.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class Bird {&lt;br /&gt;  { System.out.print("bl "); }&lt;br /&gt;  public Bird() { System.out.print("b2 "); }&lt;br /&gt;}&lt;br /&gt;class Raptor extends Bird {&lt;br /&gt;  static { System.out.print("r1 "); }&lt;br /&gt;  public Raptor() { System.out.print("r2 "); }&lt;br /&gt;  { System.out.print("r3 "); }&lt;br /&gt;  static { System.out.print("r4 "); }&lt;br /&gt;}&lt;br /&gt;class Hawk extends Raptor {&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    System.out.print("pre ");&lt;br /&gt;    new Hawk();&lt;br /&gt;    System.out.println("hawk ");&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;pre b1 b2 r3 r2 hawk &lt;br /&gt;&lt;br /&gt;pre b2 b1 r2 r3 hawk &lt;br /&gt;&lt;br /&gt;pre b2 b1 r2 r3 hawk r1 r4 &lt;br /&gt;&lt;br /&gt;r1 r4 pre b1 b2 r3 r2 hawk &lt;br /&gt;&lt;br /&gt;r1 r4 pre b2 b1 r2 r3 hawk &lt;br /&gt;&lt;br /&gt;pre r1 r4 b1 b2 r3 r2 hawk &lt;br /&gt;&lt;br /&gt;pre r1 r4 b2 b1 r2 r3 hawk &lt;br /&gt;&lt;br /&gt;The order of output cannot be predicted.&lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-5477313037347126623?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/5477313037347126623/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=5477313037347126623' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5477313037347126623'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5477313037347126623'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/java-interview-questions-part25.html' title='Java interview questions Part25'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-2692986934114549066</id><published>2007-10-26T12:45:00.001-07:00</published><updated>2007-10-26T12:45:17.940-07:00</updated><title type='text'>Java interview questions Part22</title><content type='html'>6.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class Mixer {&lt;br /&gt;  Mixer() { }&lt;br /&gt;  Mixer(Mixer m) { ml = m;}&lt;br /&gt;  Mixer m1;&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    Mixer m2 = new Mixer();&lt;br /&gt;    Mixer m3 = new Mixer(m2);  m3.go();&lt;br /&gt;    Mixer m4 = m3.m1;          m4.go();&lt;br /&gt;    Mixer m5 = m2.m1;          m5.go();&lt;br /&gt;  }&lt;br /&gt;  void go() { System.out.print("hi "); }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;hi &lt;br /&gt;&lt;br /&gt;hi hi &lt;br /&gt;&lt;br /&gt;hi hi hi &lt;br /&gt;&lt;br /&gt;Compilation fails&lt;br /&gt;&lt;br /&gt;hi, followed by an exception&lt;br /&gt;&lt;br /&gt;hi hi, followed by an exception&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;7.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;1. class Zippy {&lt;br /&gt;2.   String[] x;&lt;br /&gt;3.   int[] a [] = {{1,2}, {l}};&lt;br /&gt;4.   Object c = new long [4] ;&lt;br /&gt;5.   Object[] d = x;&lt;br /&gt;6. }&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;Compilation succeeds.&lt;br /&gt;&lt;br /&gt;Compilation fails due only to an error on line 3.&lt;br /&gt;&lt;br /&gt;Compilation fails due only to an error on line 4.&lt;br /&gt;&lt;br /&gt;Compilation fails due only to an error on line 5.&lt;br /&gt;&lt;br /&gt;Compilation fails due to errors on lines 3 and 5.&lt;br /&gt;&lt;br /&gt;Compilation fails due to errors on lines 3, 4, and 5.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;8.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class Fizz {&lt;br /&gt;  int x = 5;&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    final Fizz f1 = new Fizz();&lt;br /&gt;    Fizz f2 = new Fizz();&lt;br /&gt;    Fizz f3 = FizzSwitch(f1,f2);&lt;br /&gt;    System.out.println((f1 == f3) + " " + (f1.x == f3.x));&lt;br /&gt;  }&lt;br /&gt;  static Fizz FizzSwitch(Fizz x, Fizz y) {&lt;br /&gt;    final Fizz z = x;&lt;br /&gt;    z.x = 6;&lt;br /&gt;    return z;&lt;br /&gt;} }&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;true true &lt;br /&gt;&lt;br /&gt;false true &lt;br /&gt;&lt;br /&gt;true false &lt;br /&gt;&lt;br /&gt;false false &lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;&lt;br /&gt;An exception is thrown at runtime.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;9.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class Knowing {&lt;br /&gt;  static final long tooth = 343L;&lt;br /&gt;  static long doIt(long tooth) {&lt;br /&gt;    System.out.print(++tooth + " ");&lt;br /&gt;&lt;br /&gt;    return ++tooth;&lt;br /&gt;  }&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    System.out.print(tooth + " ");&lt;br /&gt;    final long tooth = 340L;&lt;br /&gt;    new Knowing().doIt(tooth);&lt;br /&gt;    System.out.println(tooth);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;343 340 340 &lt;br /&gt;&lt;br /&gt;343 340 342 &lt;br /&gt;&lt;br /&gt;343 341 342 &lt;br /&gt;&lt;br /&gt;343 341 340 &lt;br /&gt;&lt;br /&gt;343 341 343 &lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;&lt;br /&gt;An exception is thrown at runtime.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;10.  &lt;br /&gt; Which is true? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;The invocation of an object's finalize() method is always the last thing that happens before an object is garbage collected (GCed).&lt;br /&gt;&lt;br /&gt;When a stack variable goes out of scope it is eligible for GC.&lt;br /&gt;&lt;br /&gt;Some reference variables live on the stack, and some live on the heap.&lt;br /&gt;&lt;br /&gt;Only objects that have no reference variables referring to them can be eligible for GC.&lt;br /&gt;&lt;br /&gt;It's possible to request the GC via methods in either java. lang. Runtime or java.lang.System classes.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;11.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt; 1. class Convert {&lt;br /&gt; 2.   public static void main(String[] args) {&lt;br /&gt; 3.     Long xL = new Long(456L);&lt;br /&gt; 4.     long x1 = Long.valueOf("123");&lt;br /&gt; 5.     Long x2 = Long.valueOf("123");&lt;br /&gt; 6.     long x3 = xL.longValue();&lt;br /&gt; 7.     Long x4 = xL.longValue();&lt;br /&gt; 8.     Long x5 = Long.parseLong("456");&lt;br /&gt; 9.     long x6 = Long.parseLong("123");&lt;br /&gt;10.  }&lt;br /&gt;11. }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Which will compile using Java 5, but will NOT compile using Java 1.4? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;Line 4&lt;br /&gt;&lt;br /&gt;Line 5&lt;br /&gt;&lt;br /&gt;Line 6&lt;br /&gt;&lt;br /&gt;Line 7&lt;br /&gt;&lt;br /&gt;Line 8&lt;br /&gt;&lt;br /&gt;Line 9&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;12.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;1. class Eco {&lt;br /&gt;2.   public static void main(String[] args)    {&lt;br /&gt;3.     Eco e1 = new Eco();&lt;br /&gt;4.     Eco e2 = new Eco();&lt;br /&gt;5.     Eco e3 = new Eco();&lt;br /&gt;6.     e3.e = e2;&lt;br /&gt;7.     e1.e = e3;&lt;br /&gt;8.     e2 = null;&lt;br /&gt;9.     e3 = null;&lt;br /&gt;10.    e2.e = el;&lt;br /&gt;11.    e1   =  null;&lt;br /&gt;12.  }&lt;br /&gt;13.  Eco e;&lt;br /&gt;14. }&lt;br /&gt;&lt;br /&gt;At what point is only a single object eligible for GC?&lt;br /&gt;&lt;br /&gt;After line 8 runs.&lt;br /&gt;&lt;br /&gt;After line 9 runs.&lt;br /&gt;&lt;br /&gt;After line 10 runs.&lt;br /&gt;&lt;br /&gt;After line 11 runs.&lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;&lt;br /&gt;Never in this program.&lt;br /&gt;&lt;br /&gt;An exception is thrown at runtime.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;13.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;1. class Bigger {&lt;br /&gt;2.   public static void main(String[] args) {&lt;br /&gt;3.   // insert code here&lt;br /&gt;4.   }&lt;br /&gt;5. }&lt;br /&gt;6. class Better {&lt;br /&gt;7.   enum Faster {Higher, Longer};&lt;br /&gt;8. }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Which, inserted independently at line 3, will compile? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;Faster f = Faster.Higher; &lt;br /&gt;&lt;br /&gt;Faster f = Better.Faster.Higher; &lt;br /&gt;&lt;br /&gt;Better.Faster f = Better.Faster.Higher; &lt;br /&gt;&lt;br /&gt;Bigger.Faster f = Bigger.Faster.Higher; &lt;br /&gt;&lt;br /&gt;Better. Faster f2; f2 = Better.Faster.Longer; &lt;br /&gt;&lt;br /&gt;Better b; b.Faster = f3; f3 = Better.Faster.Longer;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-2692986934114549066?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/2692986934114549066/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=2692986934114549066' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2692986934114549066'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2692986934114549066'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/java-interview-questions-part22_26.html' title='Java interview questions Part22'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-1351165269061359886</id><published>2007-10-26T12:44:00.001-07:00</published><updated>2007-10-26T12:44:33.542-07:00</updated><title type='text'>Java interview questions Part23</title><content type='html'>1.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class Scoop {&lt;br /&gt;  static int thrower() throws Exception { return 42; }&lt;br /&gt;  public static void main(String [] args) {&lt;br /&gt;    try {&lt;br /&gt;      int x = thrower();&lt;br /&gt;    } catch (Exception e) {&lt;br /&gt;      X++;&lt;br /&gt;    } finally {&lt;br /&gt;      System.out.printIn("x = " + ++x);&lt;br /&gt;} } }&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;x = 42 &lt;br /&gt;&lt;br /&gt;x = 43 &lt;br /&gt;&lt;br /&gt;x = 44 &lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;&lt;br /&gt;The code runs with no output.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;2.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class CardBoard {&lt;br /&gt;  Short story = 5;&lt;br /&gt;  CardBoard go(CardBoard cb) {&lt;br /&gt;    cb = null;&lt;br /&gt;    return cb;&lt;br /&gt;  }&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    CardBoard c1 = new CardBoard();&lt;br /&gt;    CardBoard c2 = new CardBoard();&lt;br /&gt;    CardBoard c3 = c1.go(c2);&lt;br /&gt;    c1 = null;&lt;br /&gt;    // do Stuff&lt;br /&gt;} }&lt;br /&gt;&lt;br /&gt;When // doStuff is reached, how many objects are eligible for GC?&lt;br /&gt;&lt;br /&gt;0&lt;br /&gt;&lt;br /&gt;1&lt;br /&gt;&lt;br /&gt;2&lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;&lt;br /&gt;It is not possible to know.&lt;br /&gt;&lt;br /&gt;An exception is thrown at runtime.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;3.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class Alien {&lt;br /&gt;  String invade(short ships) { return "a few"; }&lt;br /&gt;  String invade(short... ships) { return "many"; }&lt;br /&gt;}&lt;br /&gt;class Defender {&lt;br /&gt;  public static void main(String [] args) {&lt;br /&gt;    System.out.println(new Alien().invade(7));&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;many &lt;br /&gt;&lt;br /&gt;a few &lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;&lt;br /&gt;The output is not predictable.&lt;br /&gt;&lt;br /&gt;An exception is thrown at runtime.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;4.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;1. class Dims {&lt;br /&gt;2.   public static void main(String[] args) {&lt;br /&gt;3.     int[] [] a = {{1,2,}, {3,4}};&lt;br /&gt;4.     int [] b = (int [] ) a [1] ;&lt;br /&gt;5.     Object o1 = a;&lt;br /&gt;6.     int [] [] a2 = (int[] [] )   o1;&lt;br /&gt;7.     int [] b2 = (int []) o1;&lt;br /&gt;8.     System.out.println(b[1]);&lt;br /&gt;9. } }&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;2&lt;br /&gt;&lt;br /&gt;4&lt;br /&gt;&lt;br /&gt;An exception is thrown at runtime.&lt;br /&gt;&lt;br /&gt;Compilation fails due to an error on line 4.&lt;br /&gt;&lt;br /&gt;Compilation fails due to an error on line 5.&lt;br /&gt;&lt;br /&gt;Compilation fails due to an error on line 6.&lt;br /&gt;&lt;br /&gt;Compilation fails due to an error on line 7.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;5.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class Eggs {&lt;br /&gt;  int doX(Long x, Long y) { return 1; }&lt;br /&gt;  int doX(long... x) { return 2; }&lt;br /&gt;  int doX(Integer x, Integer y) { return 3; }&lt;br /&gt;  int doX(Number n, Number m) { return 4; }&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    new Eggs().go();&lt;br /&gt;  }&lt;br /&gt;  void go () {&lt;br /&gt;    short s = 7;&lt;br /&gt;    System.out.print(doX(s,s) + " ");&lt;br /&gt;    System.out.println(doX(7,7));&lt;br /&gt;} }&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;1 1 &lt;br /&gt;&lt;br /&gt;2 1 &lt;br /&gt;&lt;br /&gt;3 1 &lt;br /&gt;&lt;br /&gt;4 1 &lt;br /&gt;&lt;br /&gt;2 3 &lt;br /&gt;&lt;br /&gt;3 3 &lt;br /&gt;&lt;br /&gt;4 3&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-1351165269061359886?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/1351165269061359886/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=1351165269061359886' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/1351165269061359886'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/1351165269061359886'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/java-interview-questions-part23.html' title='Java interview questions Part23'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-8206363530746067317</id><published>2007-10-26T12:42:00.002-07:00</published><updated>2007-10-26T12:43:09.519-07:00</updated><title type='text'>Java interview questions Part22</title><content type='html'>7.  &lt;br /&gt; Using the fragments below, complete the following code so it compiles. Note, you may not have to fill all of the slots.&lt;br /&gt;&lt;br /&gt;Code: &lt;br /&gt;&lt;br /&gt;class AgedP {&lt;br /&gt;  __________   _________   _________   _________   _________&lt;br /&gt;  public AgedP(int x) {&lt;br /&gt;_   ________ _   ________ _  ________   _________   ___________&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;public class Kinder extends AgedP {&lt;br /&gt;  _________   _________   _________   _________   _________   _________&lt;br /&gt;  public Kinder(int x) {&lt;br /&gt;    _________   _________   _________   _________   ___________() ;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Fragments: Use the following fragments zero or more times:&lt;br /&gt;&lt;br /&gt;AgedP &lt;br /&gt; super &lt;br /&gt; this &lt;br /&gt;   &lt;br /&gt;( &lt;br /&gt; ) &lt;br /&gt; { &lt;br /&gt; } &lt;br /&gt; &lt;br /&gt;; &lt;br /&gt;       &lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;8.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;1. class Plant {&lt;br /&gt;2.  String getName() { return "plant"; }&lt;br /&gt;3.  Plant getType() { return this; }&lt;br /&gt;4. }&lt;br /&gt;5. class Flower extends Plant {&lt;br /&gt;6.  // insert code here&lt;br /&gt;7. }&lt;br /&gt;8. class Tulip extends Flower {}&lt;br /&gt;&lt;br /&gt;Which statement(s), inserted at line 6, will compile? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;Flower getType() { return this; } &lt;br /&gt;&lt;br /&gt;String getType() { return "this"; } &lt;br /&gt;&lt;br /&gt;Plant getType() { return this; } &lt;br /&gt;&lt;br /&gt;Tulip getType() { return new Tulip() ;} &lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;9.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;1. class Zing {&lt;br /&gt;2.   protected Hmpf h;&lt;br /&gt;3. }&lt;br /&gt;4. class Woop extends Zing { }&lt;br /&gt;5. class Hmpf { }&lt;br /&gt;&lt;br /&gt;Which is true? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;Woop is-a Hmpf and has-a zing.&lt;br /&gt;&lt;br /&gt;zing is-a Woop and has-a Hmpf.&lt;br /&gt;&lt;br /&gt;Hmpf has-a Woop and Woop is-a Zing.&lt;br /&gt;&lt;br /&gt;Woop has-a Hmpf and Woop is-a zing.&lt;br /&gt;&lt;br /&gt;Zing has-a Hmpf and Zing is-a Woop.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;10.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;1. class Programmer {&lt;br /&gt;2.   Programmer debug() { return this; }&lt;br /&gt;3. }&lt;br /&gt;4. class SCJP extends Programmer {&lt;br /&gt;5.   // insert code here&lt;br /&gt;6. }&lt;br /&gt;&lt;br /&gt;Which, inserted at line 5, will compile? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;Programmer debug() { return this; } &lt;br /&gt;&lt;br /&gt;SCJP debug() { return this; } &lt;br /&gt;&lt;br /&gt;Object debug() { return this; } &lt;br /&gt;&lt;br /&gt;int debug() { return 1; } &lt;br /&gt;&lt;br /&gt;int debug(int x) { return 1; } &lt;br /&gt;&lt;br /&gt;Object debug (int x) { return this; } &lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;11.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class Uber {&lt;br /&gt;  static int y = 2;&lt;br /&gt;  Uber(int x) { this(); y = y * 2; }&lt;br /&gt;  Uber() { y++; }&lt;br /&gt;}&lt;br /&gt;class Minor extends Uber {&lt;br /&gt;  Minor() { super(y); y = y + 3; }&lt;br /&gt;  public static void main(String [] args) {&lt;br /&gt;    new Minor();&lt;br /&gt;    System.out.println(y);&lt;br /&gt;} }&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;6&lt;br /&gt;&lt;br /&gt;7&lt;br /&gt;&lt;br /&gt;8&lt;br /&gt;&lt;br /&gt;9&lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;&lt;br /&gt;An exception is thrown.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;12.  &lt;br /&gt; Which statement(s) are true? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;Cohesion is the OO principle most closely associated with hiding implementation details.&lt;br /&gt;&lt;br /&gt;Cohesion is the OO principle most closely associated with making sure that classes know about other classes only through their APIs.&lt;br /&gt;&lt;br /&gt;Cohesion is the OO principle most closely associated with making sure that a class is designed with a single, well-focused purpose.&lt;br /&gt;&lt;br /&gt;Cohesion is the OO principle most closely associated with allowing a single object to be seen as having many types.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;13.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt; 1. class Dog { }&lt;br /&gt; 2. class Beagle extends Dog { }&lt;br /&gt; 3. &lt;br /&gt; 4. class Kennel {&lt;br /&gt; 5.   public static void main(String [] arfs) {&lt;br /&gt; 6.     Beagle bl = new Beagle();&lt;br /&gt; 7.     Dog dogl = new Dog();&lt;br /&gt; 8.     Dog dog2 = bl;&lt;br /&gt; 9.     // insert code here&lt;br /&gt;10. } }&lt;br /&gt;&lt;br /&gt;Which, inserted at line 9, will compile? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;Beagle b2 = (Beagle) dog1; &lt;br /&gt;&lt;br /&gt;Beagle b3 = (Beagle) dog2; &lt;br /&gt;&lt;br /&gt;Beagle b4 = dog2; &lt;br /&gt;&lt;br /&gt;None of the above statements will compile.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;14.  &lt;br /&gt; Given the following,&lt;br /&gt;&lt;br /&gt; 1. class X { void dol() { } }&lt;br /&gt; 2. class Y extends X { void do2() { } }&lt;br /&gt; 3. &lt;br /&gt; 4. class Chrome {&lt;br /&gt; 5.   public static void main(String [] args) {&lt;br /&gt; 6.     X x1 = new X();&lt;br /&gt; 7.     X x2 = new Y();&lt;br /&gt; 8.     Y y1 = new Y();&lt;br /&gt; 9.     // insert code here&lt;br /&gt;10. } }&lt;br /&gt;&lt;br /&gt;Which, inserted at line 9, will compile? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;x2.do2( ); &lt;br /&gt;&lt;br /&gt;(Y) x2. do2( ); &lt;br /&gt;&lt;br /&gt;((Y)x2).do2(); &lt;br /&gt;&lt;br /&gt;None of the above statements will compile.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-8206363530746067317?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/8206363530746067317/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=8206363530746067317' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/8206363530746067317'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/8206363530746067317'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/java-interview-questions-part22.html' title='Java interview questions Part22'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-4276634506429256808</id><published>2007-10-26T12:42:00.001-07:00</published><updated>2007-10-26T12:42:25.907-07:00</updated><title type='text'>Java interview questions Part21</title><content type='html'>1.  &lt;br /&gt; Which statement(s) are true? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;Has-a relationships always rely on inheritance.&lt;br /&gt;&lt;br /&gt;Has-a relationships always rely on instance variables.&lt;br /&gt;&lt;br /&gt;Has-a relationships always require at least two class types.&lt;br /&gt;&lt;br /&gt;Has-a relationships always rely on polymorphism.&lt;br /&gt;&lt;br /&gt;Has-a relationships are always tightly coupled.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;2.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class Clidders {&lt;br /&gt;  public final void flipper() { System.out.println("Clidder"); }&lt;br /&gt;}&lt;br /&gt;public class Clidlets extends Clidders {&lt;br /&gt;  public void flipper() {&lt;br /&gt;    System.out.println("Flip a Clidlet");&lt;br /&gt;    super.flipper();&lt;br /&gt;  }&lt;br /&gt;  public static void main(String [] args) {&lt;br /&gt;    new Clidlets().flipper();&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;Flip a Clidlet &lt;br /&gt;&lt;br /&gt;Flip a Clidder &lt;br /&gt;&lt;br /&gt;Flip a Clidder &lt;br /&gt;&lt;br /&gt;Flip a Clidlet &lt;br /&gt;&lt;br /&gt;Flip a Clidlet &lt;br /&gt;&lt;br /&gt;Flip a Clidder &lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;3.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;public abstract interface Frobnicate { public void twiddle(String s) ; }&lt;br /&gt;&lt;br /&gt;Which is a correct class? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;public abstract class Frob implements Frobnicate { &lt;br /&gt;&lt;br /&gt;public abstract void twiddle(String s){} &lt;br /&gt;&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;public abstract class Frob implements Frobnicate { } &lt;br /&gt;&lt;br /&gt;public class Frob extends Frobnicate { &lt;br /&gt;&lt;br /&gt;public void twiddle(Integer i) { } &lt;br /&gt;&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;public class Frob implements Frobnicate { &lt;br /&gt;&lt;br /&gt;public void twiddle(Integer i) { } &lt;br /&gt;&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;public class Frob implements Frobnicate { &lt;br /&gt;&lt;br /&gt;public void twiddle(String i) { } &lt;br /&gt;&lt;br /&gt;public void twiddle(Integer s) { } &lt;br /&gt;&lt;br /&gt;} &lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;4.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class Top {&lt;br /&gt;  public Top(String s) { System.out.print("B"); }&lt;br /&gt;}&lt;br /&gt;public class Bottom2 extends Top {&lt;br /&gt;  public Bottom2(String s) { System.out.print("D"); }&lt;br /&gt;  public static void main(String [] args) {&lt;br /&gt;    new Bottom2("C");&lt;br /&gt;    System.out.println(" ");&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;BD &lt;br /&gt;&lt;br /&gt;DB &lt;br /&gt;&lt;br /&gt;BDC &lt;br /&gt;&lt;br /&gt;DBC &lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;5.  &lt;br /&gt; Select the two statements that best indicate a situation with low coupling. (Choose two.)&lt;br /&gt;&lt;br /&gt;The attributes of the class are all private.&lt;br /&gt;&lt;br /&gt;The class refers to a small number of other objects.&lt;br /&gt;&lt;br /&gt;The object contains only a small number of variables.&lt;br /&gt;&lt;br /&gt;The object is referred to using an anonymous variable, not directly.&lt;br /&gt;&lt;br /&gt;The reference variable is declared for an interface type, not a class. The interface provides a small number of methods.&lt;br /&gt;&lt;br /&gt;It is unlikely that changes made to one class will require any changes in another.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;6.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;class Clidder {&lt;br /&gt;  private final void flipper() { System.out.println ("Clidder"); }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class Clidlet extends Clidder {&lt;br /&gt;  public final void flipper() { System.out.println("Clidlet");  }&lt;br /&gt;  public static void main(String [] args) {&lt;br /&gt;    new Clidlet().flipper();&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;Clidlet &lt;br /&gt;&lt;br /&gt;Clidder &lt;br /&gt;&lt;br /&gt;Clidder &lt;br /&gt;&lt;br /&gt;Clidlet &lt;br /&gt;&lt;br /&gt;Clidlet &lt;br /&gt;&lt;br /&gt;Clidder &lt;br /&gt;&lt;br /&gt;Compilation fails.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-4276634506429256808?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/4276634506429256808/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=4276634506429256808' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4276634506429256808'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4276634506429256808'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/java-interview-questions-part21_2147.html' title='Java interview questions Part21'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-5008915071986899476</id><published>2007-10-26T12:39:00.000-07:00</published><updated>2007-10-26T12:40:19.191-07:00</updated><title type='text'>Java interview questions Part21</title><content type='html'>3.  &lt;br /&gt; Which is true? (Choose all that apply. )&lt;br /&gt;&lt;br /&gt;"X extends Y" is correct if and only if X is a class and Y is an interface.&lt;br /&gt;&lt;br /&gt;"X extends Y" is correct if and only if X is an interface and Y is a class.&lt;br /&gt;&lt;br /&gt;"X extends Y" is correct if X and Y are either both classes or both interfaces.&lt;br /&gt;&lt;br /&gt;"X extends Y" is correct for all combinations of X and Y being classes and/or interfaces.&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;4.  &lt;br /&gt; Which are valid declarations? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;int $x; &lt;br /&gt;&lt;br /&gt;int 123; &lt;br /&gt;&lt;br /&gt;int _123; &lt;br /&gt;&lt;br /&gt;int #dim; &lt;br /&gt;&lt;br /&gt;int %percent; &lt;br /&gt;&lt;br /&gt;int *divide; &lt;br /&gt;&lt;br /&gt;int central_sales_region_Summer_2005_gross_sales; &lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;5.  &lt;br /&gt; Which method names follow the JavaBeans standard? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;addSize &lt;br /&gt;&lt;br /&gt;getCust &lt;br /&gt;&lt;br /&gt;deleteRep &lt;br /&gt;&lt;br /&gt;isColorado &lt;br /&gt;&lt;br /&gt;putDimensions &lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;6.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;1. class Voop {&lt;br /&gt;2.   public static void main(String [] args) {&lt;br /&gt;3.     doStuff(1);&lt;br /&gt;4.     doStuff(1, 2);&lt;br /&gt;5.   }&lt;br /&gt;6.   // insert code here&lt;br /&gt;7. }&lt;br /&gt;&lt;br /&gt;Which, inserted independently at line 6, will compile? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;static void doStuff(int... doArgs) { } &lt;br /&gt;&lt;br /&gt;static void doStuff (int [] doArgs) { } &lt;br /&gt;&lt;br /&gt;static void doStuff(int doArgs...) { } &lt;br /&gt;&lt;br /&gt;static void doStuff(int... doArgs, int y) { } &lt;br /&gt;&lt;br /&gt;static void doStuff(int x, int... doArgs) { } &lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;7.  &lt;br /&gt; Which are legal declarations? (Choose all that apply. )&lt;br /&gt;&lt;br /&gt;short x []; &lt;br /&gt;&lt;br /&gt;short [] y; &lt;br /&gt;&lt;br /&gt;short [5] x2; &lt;br /&gt;&lt;br /&gt;short z2 [5]; &lt;br /&gt;&lt;br /&gt;short [] z [] []; &lt;br /&gt;&lt;br /&gt;short [] y2 = [5]; &lt;br /&gt;  &lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;google_ad_client = "pub-1862025744131424";&lt;br /&gt;google_ad_width = 234;&lt;br /&gt;google_ad_height = 60;&lt;br /&gt;google_ad_format = "234x60_as";&lt;br /&gt;google_ad_type = "text_image";&lt;br /&gt;google_ad_channel = "";&lt;br /&gt;google_color_border = "FFFFFF";&lt;br /&gt;google_color_bg = "FFFFFF";&lt;br /&gt;google_color_link = "E895CC";&lt;br /&gt;google_color_text = "940F04";&lt;br /&gt;google_color_url = "008000";&lt;br /&gt;//--&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript"&lt;br /&gt;  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt; &lt;br /&gt;8.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;1. enum Animals {&lt;br /&gt;2.   DOG ("woof"), CAT ("meow"), FISH ("burble");&lt;br /&gt;3.   String sound;&lt;br /&gt;4.   Animals(String s) { sound = s; }&lt;br /&gt;5. }&lt;br /&gt;6. class TestEnum {&lt;br /&gt;7.   static Animals a;&lt;br /&gt;8.   public static void main(String[] args) {&lt;br /&gt;9.     System.out.println(a.DOG.sound + " " + a.FISH.sound);&lt;br /&gt;10.  }&lt;br /&gt;11. }&lt;br /&gt;&lt;br /&gt;What is the result?&lt;br /&gt;&lt;br /&gt;woof burble &lt;br /&gt;&lt;br /&gt;Multiple compilation errors&lt;br /&gt;&lt;br /&gt;Compilation fails due to an error on line 2&lt;br /&gt;&lt;br /&gt;Compilation fails due to an error on line 3&lt;br /&gt;&lt;br /&gt;Compilation fails due to an error on line 4&lt;br /&gt;&lt;br /&gt;Compilation fails due to an error on line 9&lt;br /&gt;  &lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;google_ad_client = "pub-1862025744131424";&lt;br /&gt;google_ad_width = 234;&lt;br /&gt;google_ad_height = 60;&lt;br /&gt;google_ad_format = "234x60_as";&lt;br /&gt;google_ad_type = "text_image";&lt;br /&gt;google_ad_channel = "";&lt;br /&gt;google_color_border = "FFFFFF";&lt;br /&gt;google_color_bg = "FFFFFF";&lt;br /&gt;google_color_link = "E895CC";&lt;br /&gt;google_color_text = "940F04";&lt;br /&gt;google_color_url = "008000";&lt;br /&gt;//--&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript"&lt;br /&gt;  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt; &lt;br /&gt;9.  &lt;br /&gt; Given:&lt;br /&gt;&lt;br /&gt;1. enum A { A }&lt;br /&gt;2. class E2 {&lt;br /&gt;3.   enum B { B }&lt;br /&gt;4.   void C() {&lt;br /&gt;5.     enum D { D }&lt;br /&gt;6.   }&lt;br /&gt;7. }&lt;br /&gt;&lt;br /&gt;Which statements are true? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;The code compiles.&lt;br /&gt;&lt;br /&gt;If only line 1 is removed the code compiles.&lt;br /&gt;&lt;br /&gt;If only line 3 is removed the code compiles.&lt;br /&gt;&lt;br /&gt;If only line 5 is removed the code compiles.&lt;br /&gt;&lt;br /&gt;If lines 1 and 3 are removed the code compiles&lt;br /&gt;&lt;br /&gt;If lines 1, 3 and 5 are removed the code compiles&lt;br /&gt; &lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;google_ad_client = "pub-1862025744131424";&lt;br /&gt;google_ad_width = 234;&lt;br /&gt;google_ad_height = 60;&lt;br /&gt;google_ad_format = "234x60_as";&lt;br /&gt;google_ad_type = "text_image";&lt;br /&gt;google_ad_channel = "";&lt;br /&gt;google_color_border = "FFFFFF";&lt;br /&gt;google_color_bg = "FFFFFF";&lt;br /&gt;google_color_link = "E895CC";&lt;br /&gt;google_color_text = "940F04";&lt;br /&gt;google_color_url = "008000";&lt;br /&gt;//--&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript"&lt;br /&gt;  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;&lt;br /&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-5008915071986899476?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/5008915071986899476/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=5008915071986899476' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5008915071986899476'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5008915071986899476'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/java-interview-questions-part21_26.html' title='Java interview questions Part21'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-2319337464959052476</id><published>2007-10-26T12:34:00.000-07:00</published><updated>2007-10-26T12:35:13.133-07:00</updated><title type='text'>Java interview questions Part21</title><content type='html'>Which declare a compilable abstract class? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;public abstract class Canine { public Bark speak(); } &lt;br /&gt;&lt;br /&gt;public abstract class Canine { public Bark speak() { } } &lt;br /&gt;&lt;br /&gt;public class Canine { public abstract Bark speak(); } &lt;br /&gt;&lt;br /&gt;public class Canine abstract { public abstract Bark speak(); } &lt;br /&gt; &lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;google_ad_client = "pub-1862025744131424";&lt;br /&gt;google_ad_width = 234;&lt;br /&gt;google_ad_height = 60;&lt;br /&gt;google_ad_format = "234x60_as";&lt;br /&gt;google_ad_type = "text_image";&lt;br /&gt;google_ad_channel = "";&lt;br /&gt;google_color_border = "FFFFFF";&lt;br /&gt;google_color_bg = "FFFFFF";&lt;br /&gt;google_color_link = "E895CC";&lt;br /&gt;google_color_text = "940F04";&lt;br /&gt;google_color_url = "008000";&lt;br /&gt;//--&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript"&lt;br /&gt;  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-2319337464959052476?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/2319337464959052476/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=2319337464959052476' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2319337464959052476'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2319337464959052476'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/java-interview-questions-part21.html' title='Java interview questions Part21'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-4385834046399962883</id><published>2007-10-26T12:28:00.000-07:00</published><updated>2007-10-26T12:33:29.995-07:00</updated><title type='text'>Java interview questions Part20</title><content type='html'>Given the following,&lt;br /&gt;&lt;br /&gt;1. interface Base {&lt;br /&gt;2.   boolean m1 ();&lt;br /&gt;3.   byte m2(short s);&lt;br /&gt;4. }&lt;br /&gt;&lt;br /&gt;Which code fragments will compile? (Choose all that apply.)&lt;br /&gt;&lt;br /&gt;interface Base2 implements Base { } &lt;br /&gt;&lt;br /&gt;abstract class Class2 extends Base { &lt;br /&gt;&lt;br /&gt;public boolean ml() { return true; } } &lt;br /&gt;&lt;br /&gt;abstract class Class2 implements Base { } &lt;br /&gt;&lt;br /&gt;abstract class Class2. implements Base { &lt;br /&gt;&lt;br /&gt;public boolean m1() { return (true); } } &lt;br /&gt;&lt;br /&gt;class Class2 implements Base { &lt;br /&gt;&lt;br /&gt;boolean m1( ) { return false; } &lt;br /&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;google_ad_client = "pub-1862025744131424";&lt;br /&gt;google_ad_width = 234;&lt;br /&gt;google_ad_height = 60;&lt;br /&gt;google_ad_format = "234x60_as";&lt;br /&gt;google_ad_type = "text_image";&lt;br /&gt;google_ad_channel = "";&lt;br /&gt;google_color_border = "FFFFFF";&lt;br /&gt;google_color_bg = "FFFFFF";&lt;br /&gt;google_color_link = "E895CC";&lt;br /&gt;google_color_text = "940F04";&lt;br /&gt;google_color_url = "008000";&lt;br /&gt;//--&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript"&lt;br /&gt;  src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;&lt;br /&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-4385834046399962883?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/4385834046399962883/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=4385834046399962883' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4385834046399962883'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4385834046399962883'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/java-interview-questions-part20.html' title='Java interview questions Part20'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-5538619073935544556</id><published>2007-10-25T11:27:00.000-07:00</published><updated>2007-10-25T11:29:07.544-07:00</updated><title type='text'>XML Interview Question Part4</title><content type='html'>50. How to transform an XML document to an HTML document?&lt;br /&gt;&lt;br /&gt;To perform the transformation, you need to obtain an XSLT transformer and use it to apply the style sheet to the XML data. The following code fragment obtains a transformer by instantiating a TransformerFactory object, reading in the style sheet and XML files, creating a file for the HTML output, and then finally obtaining the Transformer object transformer from the TransformerFactory object tFactory.&lt;br /&gt;&lt;br /&gt;TransformerFactory tFactory = TransformerFactory.newInstance();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;String stylesheet = "xxx.xsl";&lt;br /&gt;&lt;br /&gt;String sourceId = "newXML.xml";&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;File yyyHTML = new File("yyyHTML.html");&lt;br /&gt;&lt;br /&gt;FileOutputStream os = new FileOutputStream(yyyHTML);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Transformer transformer = tFactory.newTransformer(new StreamSource(stylesheet));&lt;br /&gt;&lt;br /&gt;transformer.transform(new StreamSource(sourceId), new StreamResult(os));&lt;br /&gt;&lt;br /&gt;51. What are major subcomponents of XSL?&lt;br /&gt;&lt;br /&gt;The XML Stylesheet Language (XSL) has three major subcomponents: &lt;br /&gt;&lt;br /&gt;1. XSL-FO -- The largest subcomponent. It describes font sizes, page layouts, and how information "flows" from one page to another. &lt;br /&gt;&lt;br /&gt;2. XSLT -- A transformation language that lets you define a transformation from XML into some other format. Like producing HTML, a different XML structure, a plain text or other document format.&lt;br /&gt;&lt;br /&gt;3. XPath -- A specification that lets you specify a path to an element.&lt;br /&gt;&lt;br /&gt;52. What is transformation language in XSL?&lt;br /&gt;&lt;br /&gt;Extensible Styles Language(XSL) has two parts: &lt;br /&gt;&lt;br /&gt;a transformation language(XSLT) and a formatting language. &lt;br /&gt;&lt;br /&gt;The transformation language lets you transform documents into different forms, while the formatting language actually formats and styles documents in various ways.&lt;br /&gt;&lt;br /&gt;53. What is JAX-RPC?&lt;br /&gt;&lt;br /&gt;JAX-RPC stands for Java API for XML-based RPC(Remote Procedure Call). It is an API for building Web services and clients that use RPC and XML.&lt;br /&gt;&lt;br /&gt;In JAX-RPC, a remote procedure call is represented by an XML-based protocol such as SOAP. The SOAP specification defines the envelope structure, encoding rules, and convention for representing remote procedure calls and responses. These calls and responses are transmitted as SOAP messages (XML files) over HTTP. &lt;br /&gt;&lt;br /&gt;With JAX-RPC, the developer does not generate or parse SOAP messages. It is the JAX-RPC runtime system that converts the API calls and responses to and from SOAP messages. &lt;br /&gt;&lt;br /&gt;54. What is value type?&lt;br /&gt;&lt;br /&gt;A value type is a class whose state may be passed between a client and remote service as a method parameter or return value. For example, an account class may have account number, account owner and amount field. These information may be passed between client and server as a method deposit parameter and a return value of method account query.&lt;br /&gt;&lt;br /&gt;55. What kind of rules do the value type must follow? &lt;br /&gt;&lt;br /&gt;To be supported by JAX-RPC, a value type must conform to the following rules: &lt;br /&gt;&lt;br /&gt;o It must have a public default constructor.&lt;br /&gt;&lt;br /&gt;o It must not implement (either directly or indirectly) the java.rmi.Remote interface.&lt;br /&gt;&lt;br /&gt;o Its fields must be supported JAX-RPC types.&lt;br /&gt;&lt;br /&gt;o The value type may contain public, private, or protected fields. The field of a value type must meet these requirements: &lt;br /&gt;&lt;br /&gt; A public field cannot be final or transient.&lt;br /&gt;&lt;br /&gt; A non-public field must have corresponding getter and setter methods. &lt;br /&gt;&lt;br /&gt;Return to top &lt;br /&gt;&lt;br /&gt;________________________________________&lt;br /&gt;&lt;br /&gt;56. What is SAAJ?&lt;br /&gt;&lt;br /&gt;SAAJ stands for SOAP(Simple Object Access Protocal) with Attachments API for Java. SAAJ is used mainly for the SOAP messaging that goes on behind the scenes in JAX-RPC and JAXR implementations. &lt;br /&gt;&lt;br /&gt;Secondarily, it is an API that developers can use when they choose to write SOAP messaging applications directly rather than using JAX-RPC. &lt;br /&gt;&lt;br /&gt;57. What is XML Registry?&lt;br /&gt;&lt;br /&gt;An XML registry is an infrastructure that enables the building, deployment, and discovery of Web services. It is a neutral third party that facilitates dynamic and loosely coupled business-to-business (B2B) interactions. A registry is available to organizations as a shared resource, often in the form of a Web-based service. &lt;br /&gt;&lt;br /&gt;There are many kinds of specifications for XML registries, including ebXML Registry and Repository and The Universal Description, Discovery, and Integration (UDDI). &lt;br /&gt;&lt;br /&gt;58. What is JAXR?&lt;br /&gt;&lt;br /&gt;JAXR stands for Java API for XML Registries. It enables Java software programmers to use an API to access a variety of XML registries. The current version of the JAXR specification can be found at http://java.sun.com/xml/downloads/jaxr.html&lt;br /&gt;&lt;br /&gt;59. What is XHTML?&lt;br /&gt;&lt;br /&gt;XHTML is an application of XML that tries to make XML documents look and act like HTML documents. The XHTML specification is a reformulation of HTML 4.0 into XML. The following is code of XHTML.&lt;br /&gt;&lt;br /&gt;1. &lt;?xml version="1.0"?&gt;&lt;br /&gt;&lt;br /&gt;2. &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"&lt;br /&gt;&lt;br /&gt;3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;&lt;br /&gt;&lt;br /&gt;4. &lt;html xmlns="http://www.w3.org/2002/xhtml" xml:lang="en" lang="en"&gt;&lt;br /&gt;&lt;br /&gt;5. &lt;head&gt;&lt;title&gt;Welcome to see xhtml&lt;/title&gt;&lt;/head&gt;&lt;br /&gt;&lt;br /&gt;6. &lt;body&gt;&lt;br /&gt;&lt;br /&gt;7. &lt;h1 align="center"&gt; Welcome to XHTML!&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;8. &lt;/body&gt;&lt;br /&gt;&lt;br /&gt;9. &lt;/html&gt;&lt;br /&gt;&lt;br /&gt;The following is the display on your browser. &lt;br /&gt;&lt;br /&gt;________________________________________&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-5538619073935544556?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/5538619073935544556/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=5538619073935544556' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5538619073935544556'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5538619073935544556'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/xml-interview-question-part4.html' title='XML Interview Question Part4'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-7050940273411250045</id><published>2007-10-25T11:26:00.000-07:00</published><updated>2007-10-25T11:27:43.841-07:00</updated><title type='text'>XML Interview Question 4</title><content type='html'>35. How to declare an image tag in a DTD file?&lt;br /&gt;&lt;br /&gt;You can declare an image tag in the following form:&lt;br /&gt;&lt;br /&gt;1. &lt;!ELEMENT image EMPTY&gt;&lt;br /&gt;&lt;br /&gt;2. &lt;!ATTLIST image &lt;br /&gt;&lt;br /&gt;    alt    CDATA    #IMPLIED&lt;br /&gt;&lt;br /&gt;    src    CDATA    #REQUIRED&lt;br /&gt;&lt;br /&gt;    type   CDATA    "image/gif"&lt;br /&gt;&lt;br /&gt;   &gt; &lt;br /&gt;&lt;br /&gt;3. &lt;!NOTATION GIF SYSTEM "image/gif"&gt;&lt;br /&gt;&lt;br /&gt;4. &lt;!ENTITY some SYSTEM "image.gif" NDARA GIF&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The line one declares image as an optional element. The line 2 declares attributes of an image tag. For the moment, you can not declare an image tag like type ("image/gif", "image/jpeg"). The line 3 declares a notation named GIF that stands for the image/gif MIME type. The line 4 creates an external unparsed entity named some to refer to the external image file, image.gif. &lt;br /&gt;&lt;br /&gt;36. What is conditional section?&lt;br /&gt;&lt;br /&gt;Conditional section is a way to let XML document to choose which dtd should be "included" or "ignored". Use &lt;![ as a start and ]]&gt; as an end. For example, you want to use a different versions of a DTD for xml document or sgml document, you may code as follows:&lt;br /&gt;&lt;br /&gt;&lt;![ INCLUDE [&lt;br /&gt;&lt;br /&gt;    ... XML-only definitions&lt;br /&gt;&lt;br /&gt;  ]]&gt;&lt;br /&gt;&lt;br /&gt;  &lt;![ IGNORE [&lt;br /&gt;&lt;br /&gt;    ... SGML-only definitions&lt;br /&gt;&lt;br /&gt;  ]]&gt;&lt;br /&gt;&lt;br /&gt;  ... common definitions &lt;br /&gt;&lt;br /&gt;37. How many entities are catagorized in dtd?&lt;br /&gt;&lt;br /&gt;o Internal entity: An entity that is referenced in its own document content.&lt;br /&gt;&lt;br /&gt;o External entity: An entity that is referenced in another file.&lt;br /&gt;&lt;br /&gt;o General entity: including internal or external entity&lt;br /&gt;&lt;br /&gt;o Parameter entity: An entity that contains DTD specifications that are referenced from within the DTD.&lt;br /&gt;&lt;br /&gt;o Parsed entity: An entity that contains XML(text and markup) and is therefore parsed.&lt;br /&gt;&lt;br /&gt;o Unparsed entity: An entity that contains binary data(like images)&lt;br /&gt;&lt;br /&gt;Return to top &lt;br /&gt;&lt;br /&gt;________________________________________&lt;br /&gt;&lt;br /&gt;38. What is xmlns?&lt;br /&gt;&lt;br /&gt;The xmlns stands for XML NameSpace. It is an attribute for a tag. It is used in DTD to prevent conflicts. For example, the following tells us the title element will use designated DTD.&lt;br /&gt;&lt;br /&gt;&lt;!ELEMENT title (%inline;)*&gt;&lt;br /&gt;&lt;br /&gt;&lt;!ATTLIST title &lt;br /&gt;&lt;br /&gt;  xmlns CDATA #FIXED "http://www.example.com/slideshow"&gt;&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;or &lt;br /&gt;&lt;br /&gt;&lt;title xmlns="http://www.example.com/slideshow"&gt;&lt;br /&gt;&lt;br /&gt;  Overview&lt;br /&gt;&lt;br /&gt;&lt;/title&gt;&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;&lt;SL:slideshow xmlns:SL='http:/www.example.com/slideshow'&lt;br /&gt;&lt;br /&gt;    ...&gt;&lt;br /&gt;&lt;br /&gt;  ...&lt;br /&gt;&lt;br /&gt;&lt;/SL:slideshow&gt;&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;&lt;SL:slideshow xmlns:SL='http:/www.example.com/slideshow'&lt;br /&gt;&lt;br /&gt;      ...&gt;&lt;br /&gt;&lt;br /&gt;  ...&lt;br /&gt;&lt;br /&gt;  &lt;slide&gt;&lt;br /&gt;&lt;br /&gt;    &lt;SL:title&gt;Overview&lt;/SL:title&gt;&lt;br /&gt;&lt;br /&gt;  &lt;/slide&gt;&lt;br /&gt;&lt;br /&gt;  ...&lt;br /&gt;&lt;br /&gt;&lt;/SL:slideshow&gt; &lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;&lt;SL:slideshow xmlns:SL='http:/www.example.com/slideshow'&lt;br /&gt;&lt;br /&gt;      xmlns:xhtml='urn:...'&gt;&lt;br /&gt;&lt;br /&gt;  ... &lt;br /&gt;&lt;br /&gt;&lt;/SL:slideshow&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here we use "http:", you may use "urn:" instead. &lt;br /&gt;&lt;br /&gt;39. What is xsi?&lt;br /&gt;&lt;br /&gt;The "xsi" stands for XML Schema Instance like:&lt;br /&gt;&lt;br /&gt;xsi:noNamespaceSchemaLocation='YourSchemaDefinition.xsd'&lt;br /&gt;&lt;br /&gt;The line specifies the schema to use for elements in the document that do not have a namespace prefix. &lt;br /&gt;&lt;br /&gt;40. Where to use XML?&lt;br /&gt;&lt;br /&gt;XML can be used in many places:&lt;br /&gt;&lt;br /&gt;o Data representation in Web, especially for Java client/server web.&lt;br /&gt;&lt;br /&gt;o Data interchange in all sorts of transactions as long as both sides agree on.&lt;br /&gt;&lt;br /&gt;o Document-Driven Programming(DDP)&lt;br /&gt;&lt;br /&gt;o Binding&lt;br /&gt;&lt;br /&gt;o Archiving&lt;br /&gt;&lt;br /&gt;41. What is JAXP?&lt;br /&gt;&lt;br /&gt;JAXP stands for Java APIs for XML, which let you write your Web application entirely in the Java programming language. There are two broad categories:&lt;br /&gt;&lt;br /&gt;o Document-oriented -- processes XML documents using various parsers. &lt;br /&gt;&lt;br /&gt;o Procedure-oriented -- including JAX-RPC, JAXM, and JAXR. &lt;br /&gt;&lt;br /&gt;42. What is RELAX NG?&lt;br /&gt;&lt;br /&gt;RELAX NG stands for Regular Language description for XML. It is simpler than XML structure schema and an emerging standard under the auspices of OASIS. NG stands for Next Generation. For more information on RELAX NG, see www.oasis-open.org/committees/relax-ng/ &lt;br /&gt;&lt;br /&gt;43. What is XML schema&lt;br /&gt;&lt;br /&gt;XML Schema is a large, complex standard that has two parts. One part specifies structure relationships. (This is the largest and most complex part.) The other part specifies mechanisms for validating the content of XML elements by specifying a (potentially very sophisticated) datatype for each element. For more information on XML schema, visit www.w3c.org/XML/Schema &lt;br /&gt;&lt;br /&gt;44. What is JAXM?&lt;br /&gt;&lt;br /&gt;JAXM stands for Java APIs for XML Messaging. It provides a standard way to send XML documents over the internet form the Java platform. It is based on the SOAP 1.1 and SOAP with Attaqchements specifications which define a basic framework for exchanging XML messages. It can make one-way (asynchronous) messaging, rout of a message to more than one party and guarantee the delivery, whereas the JAX-RPC cannot. &lt;br /&gt;&lt;br /&gt;45. How to get a Point-to-Point connection via JAXM?&lt;br /&gt;&lt;br /&gt;All JAXM connections are created by using connection factory methods.&lt;br /&gt;&lt;br /&gt;SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();&lt;br /&gt;&lt;br /&gt;SOAPConnection con = factory.createConnection();&lt;br /&gt;&lt;br /&gt;46. How to get a connection to the Messaging Provider via JAXM?&lt;br /&gt;&lt;br /&gt;There are two ways to obtain this connection.&lt;br /&gt;&lt;br /&gt;ProviderConnectionFactory pcFactory = ProviderConnectionFactory.newInstance();&lt;br /&gt;&lt;br /&gt;ProviderConnection pcCon = pcFactory.createConnection();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Context ctx = getInitialContext();&lt;br /&gt;&lt;br /&gt;ProviderConnectionFactory pcFactory = (ProviderConnectionFactory)ctx.lookup("SomeMsgProvider");&lt;br /&gt;&lt;br /&gt;ProviderConnection con = pcFactory.createConnection();&lt;br /&gt;&lt;br /&gt;47. How XML is related with other technologies?&lt;br /&gt;&lt;br /&gt;There are many XML related technologies directly or non-directly:&lt;br /&gt;&lt;br /&gt;o SAX -- Simple API for XML: reads and writes XML data in a server.&lt;br /&gt;&lt;br /&gt;o DOM -- Document Object Model: converts an XML document into a collection of objects.&lt;br /&gt;&lt;br /&gt;o JDOM -- Java DOM: processes more data-oriented structures.&lt;br /&gt;&lt;br /&gt;o dom4j -- DOM for Java: a factory-based implementation, easier to modify for complex, special-purpose apps.&lt;br /&gt;&lt;br /&gt;o DTD -- Document Type Definition: specifies the kinds of tags that can be included in XML document.&lt;br /&gt;&lt;br /&gt;o Namespace -- writes an XML document that uses two or more sets of XML tags in modular fashion.&lt;br /&gt;&lt;br /&gt;o XSL -- Extensible Stylesheet Language: specifies how to identify data, not how to display it.&lt;br /&gt;&lt;br /&gt;o XSLT -- Extensible Stylesheet Language for Transformations: specifies what to convert an XML tag into.&lt;br /&gt;&lt;br /&gt;o XSL-FO -- Extensible Stylesheet Language for Formatting Objects: specifies how to link multiple areas on a page.&lt;br /&gt;&lt;br /&gt;o SAAJ -- SOAP with Attachments API for Java.&lt;br /&gt;&lt;br /&gt;o JAXR -- Java API for XML Registries, used to look and find web services.&lt;br /&gt;&lt;br /&gt;o TREX -- Tree Regular Expressions for XML, part of RELAX NG&lt;br /&gt;&lt;br /&gt;o SOX -- Schema for Object-Oriented XML&lt;br /&gt;&lt;br /&gt;o Schematron -- Schema for Object-Oriented XML, an assetion based schema by www.ascc.net.&lt;br /&gt;&lt;br /&gt;o ebXML -- Electronic Business with XML developed by UN/CEFACT and OASIS&lt;br /&gt;&lt;br /&gt;o cxml -- Commerce XML, more info at www.rosettanet.org&lt;br /&gt;&lt;br /&gt;o etc.&lt;br /&gt;&lt;br /&gt;48. What is the difference between SAX and DOM?&lt;br /&gt;&lt;br /&gt;The Simple API for XML(SAX) and the Document Object Model(DOM) are both defined by the W3C. Unlike a SAX parser, a DOM parser allows random access to particular pieces of data in an XML document. Another difference is that with a SAX parser, you can only read an XML document, but with a DOM parser, you can build an object representation of the document and manipulate it in memory, adding a new element or deleting an existing one.&lt;br /&gt;&lt;br /&gt;49. How to transform a DOM tree to an XML document?&lt;br /&gt;&lt;br /&gt;Use the following code:&lt;br /&gt;&lt;br /&gt;DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();&lt;br /&gt;&lt;br /&gt;DocumentBuilder builder = factory.newDocumentBuilder();&lt;br /&gt;&lt;br /&gt;Document document = builder.parse("xxxList.xml");&lt;br /&gt;&lt;br /&gt;Node rootNode = document.getDocumentElement();&lt;br /&gt;&lt;br /&gt;NodeList list = document.getElementsByTagName("xxxx");&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;//add node&lt;br /&gt;&lt;br /&gt;Text tnNode = document.createTextNode("yyyy");&lt;br /&gt;&lt;br /&gt;newNameNode.appendChild(tnNode);&lt;br /&gt;&lt;br /&gt;....&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;TransformerFactory transFactory = TransformerFactory.newInstance();&lt;br /&gt;&lt;br /&gt;Transformer transformer = transFactory.newTransformer();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;DOMSource source = new DOMSource(document);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;File newXML = new File("newXML.xml");&lt;br /&gt;&lt;br /&gt;FileOutputStream os = new FileOutputStream(newXML);&lt;br /&gt;&lt;br /&gt;StreamResult result = new StreamResult(os);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;transformer.transform(source, result);&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-7050940273411250045?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/7050940273411250045/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=7050940273411250045' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7050940273411250045'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7050940273411250045'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/xml-interview-question-4.html' title='XML Interview Question 4'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-7176977161148741079</id><published>2007-10-25T11:25:00.000-07:00</published><updated>2007-10-25T11:26:07.982-07:00</updated><title type='text'>Java EJB Interview questions Part2</title><content type='html'>25. What syntax should be used to describe a more children elements?&lt;br /&gt;&lt;br /&gt;For example, if a and b represent child elements:&lt;br /&gt;&lt;br /&gt;o a+ -- one or more occurences of a&lt;br /&gt;&lt;br /&gt;o a* -- zero or more occurences of a&lt;br /&gt;&lt;br /&gt;o a? -- a or nothing&lt;br /&gt;&lt;br /&gt;o a, b -- a followed by b&lt;br /&gt;&lt;br /&gt;o a | b -- a or b, but not both&lt;br /&gt;&lt;br /&gt;o (expression) -- a unit may have more of above expressions&lt;br /&gt;&lt;br /&gt;26. What the following tells us in a dtd file?&lt;br /&gt;&lt;br /&gt;1. &lt;!ELEMENT slideshow (slide+)&gt;&lt;br /&gt;&lt;br /&gt;2. &lt;!ELEMENT slide (title, item*)&gt;&lt;br /&gt;&lt;br /&gt;3. &lt;!ELEMENT title (#PCDATA)&gt;&lt;br /&gt;&lt;br /&gt;4. &lt;!ELEMENT item (#PCDATA | item)*&gt;&lt;br /&gt;&lt;br /&gt;5. &lt;!ELEMENT %content; &gt;&lt;br /&gt;&lt;br /&gt;The first line says that a slideshow element contains one or more slide elements. The second line says that a slide element consists of a title followed by zero or more item elements. The third line says that a title element consists entirely of parsed character data(PCDATA). The "#" sign that precedes PCDATA indicates that what follows is a special word. The fourth line says the item element is either PCDATA or an item. The asterisk at the end says that either one can occur zero or more times in succession. The fifth line says that content is a parameter entity reference.&lt;br /&gt;&lt;br /&gt;27. What is mixed-content model?&lt;br /&gt;&lt;br /&gt;The content of a tag in the xml file can be #PCDATA or any number of item elements like the fourth line above.&lt;br /&gt;&lt;br /&gt;28. Is DTD definition hierarchical?&lt;br /&gt;&lt;br /&gt;No. The DTD definition is not hierarchical. But you can work around to make your xml tags hierarchical. For example, if you have a title for slideshow and a title for each slide, you can use slide-title to represent the title in slide and make a definition for slide-title. It is so called "hyphenation hierarchy. Otherwise, the title definition will work for every title in xml file.&lt;br /&gt;&lt;br /&gt;29. What is special element value and how to use it?&lt;br /&gt;&lt;br /&gt;There are two special values: ANY or EMPTY. The "ANY" notation says that the element may contain any other defined element, or PCDATA. The "EMPTY" notation says that the element contains no contents. For example an empty tag contains no contents. &lt;br /&gt;&lt;br /&gt;30. How to reference a DTD file?&lt;br /&gt;&lt;br /&gt;If the DTD definition is in a separate file from the XML document, you have to write something to reference it from the XML document. For example, if your slideshow.dtd is ready for use, then, in your xml document file, after the xml declaration, write:&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;!DOCTYPE slideshow SYSTEM "slideshow.dtd"&gt;&lt;br /&gt;&lt;br /&gt;The above statement says that the element slideshow tag will use definition in slideshow.dtd. The SYSTEM identifier specifies the location of the DTD file and the path is relative to the location of the xml document. You may use http:// or file:/ to indicate the path of the DTD file. &lt;br /&gt;&lt;br /&gt;Or you can reference a definition within the XML document by using a square brackets like the following, rather than referring to an external DTD file.&lt;br /&gt;&lt;br /&gt;&lt;!DOCTYPE slideshow SYSTEM "slideshow1.dtd" [&lt;br /&gt;&lt;br /&gt;  ...local subset definitions here...&lt;br /&gt;&lt;br /&gt;]&gt; &lt;br /&gt;&lt;br /&gt;31. How to declare a public DTD?&lt;br /&gt;&lt;br /&gt;Replace SYSTEM to PUBLIC and give url to that dtd. &lt;br /&gt;&lt;br /&gt;&lt;!DOCTYPE slideshow PUBLIC "-//somewhere//customized XML Version 1.0//EN" &lt;br /&gt;&lt;br /&gt;      "http://www.somewhere.com/someones/slideshow1.dtd" &gt; &lt;br /&gt;&lt;br /&gt;32. What is the meaning of ATTLIST? What do the following statements tell us?&lt;br /&gt;&lt;br /&gt;ATTLIST means attribute list. The name that follows ATTLIST specifies the element for which the attributes are being defined. For example, you have a slideshow tag with title, date and author attributes, you may code as:&lt;br /&gt;&lt;br /&gt;&lt;!ELEMENT slideshow (slide+)&gt;&lt;br /&gt;&lt;br /&gt;&lt;!ATTLIST slideshow &lt;br /&gt;&lt;br /&gt;    title    CDATA    #REQUIRED&lt;br /&gt;&lt;br /&gt;    date     CDATA    #IMPLIED&lt;br /&gt;&lt;br /&gt;    author   CDATA    "unknown"&lt;br /&gt;&lt;br /&gt;&gt;&lt;br /&gt;&lt;br /&gt;&lt;!ELEMENT slide (title, item*)&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The DTD tag ATTLIST begins the series of attribute definitions. The slideshow element has three attributes. The title, date and author are the names of attributes of slideshow. CDATA is a type of the attribute; it means unparsed charater data or a text string. &lt;br /&gt;&lt;br /&gt;The #REQUIRED means the attribute value must be specified in the document. The #IMPLIED means the value need not be specified in the document.&lt;br /&gt;&lt;br /&gt;33. What does the &amp; sign mean in dtd file?&lt;br /&gt;&lt;br /&gt;The &amp; sign means an entity variable name. Note it should be ended with semicolon ";" sign. For example:&lt;br /&gt;&lt;br /&gt;&lt;!DOCTYPE slideshow SYSTEM "slideshow.dtd" [&lt;br /&gt;&lt;br /&gt;  &lt;!ENTITY copyright "&amp;#169" &gt;&lt;br /&gt;&lt;br /&gt;  ...&lt;br /&gt;&lt;br /&gt;]&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt; &amp;copyright; ...&lt;br /&gt;&lt;br /&gt;Wherever the &amp;copyright; is parsed, it will be replaced with entity copyright sign ©. &lt;br /&gt;&lt;br /&gt;34. How to declare a parameter entity reference?&lt;br /&gt;&lt;br /&gt;Use &lt;!ENTITY&gt; to declare it and use an &amp; as start and ; as end to enclose the parameter entity reference. For example, TODAY is a parameter entity reference.&lt;br /&gt;&lt;br /&gt;&lt;?xml version='1.0' standalone="yes"?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;!DOCTYPE DOCUMENT [&lt;br /&gt;&lt;br /&gt;&lt;!ELEMENT GREETING (#PCDATA)&gt;&lt;br /&gt;&lt;br /&gt;&lt;!ELEMENT MESSAGE (#PCDATA)&gt;&lt;br /&gt;&lt;br /&gt;&lt;!ELEMENT DATE (#PCDATA)&gt;&lt;br /&gt;&lt;br /&gt;&lt;!ENTITY TODAY "NOV 1, 2003"&gt;&lt;br /&gt;&lt;br /&gt;]&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;DOCUMENT&gt;&lt;br /&gt;&lt;br /&gt; &lt;GREETING&gt;&lt;br /&gt;&lt;br /&gt;  HELLO FROM HTML&lt;br /&gt;&lt;br /&gt; &lt;/GREETING&gt;&lt;br /&gt;&lt;br /&gt; &lt;MESSAGE&gt;&lt;br /&gt;&lt;br /&gt;  WELCOME TO THE WILD WORLD &lt;br /&gt;&lt;br /&gt; &lt;/MESSAGE&gt;&lt;br /&gt;&lt;br /&gt;        &lt;DATE&gt; &amp;TODAY; &lt;/DATE&gt;&lt;br /&gt;&lt;br /&gt;&lt;/DOCUMENT&gt;&lt;br /&gt;&lt;br /&gt;Save above file as greeting.xml, use your browser to look at it. You may get a similar display, except that the &lt;DATE&gt; tag will display "NOV 1, 2003". Or you can click here to see the result. &lt;br /&gt;&lt;br /&gt;Note: It is possible that your browser may not support XML. If you use MS IE 5.5 above, or NS 5.0 above, you may be able to see it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-7176977161148741079?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/7176977161148741079/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=7176977161148741079' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7176977161148741079'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7176977161148741079'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/java-ejb-interview-questions-part2_25.html' title='Java EJB Interview questions Part2'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-1349475877419984911</id><published>2007-10-25T11:24:00.001-07:00</published><updated>2007-10-25T11:24:40.136-07:00</updated><title type='text'>XML Interview Question Part3</title><content type='html'>18. How to use JavaScript to display XML document?&lt;br /&gt;&lt;br /&gt;To illustrate it, we use a simple XML document hello.xml as follows:&lt;br /&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;br /&gt;&lt;br /&gt;&lt;DOCUMENT&gt;&lt;br /&gt;&lt;br /&gt;    &lt;MESSAGE&gt;&lt;br /&gt;&lt;br /&gt;        Hello guys!&lt;br /&gt;&lt;br /&gt;    &lt;/MESSAGE&gt;&lt;br /&gt;&lt;br /&gt;&lt;/DOCUMENT&gt; &lt;br /&gt;&lt;br /&gt;In an HTML file called getxml.html:&lt;br /&gt;&lt;br /&gt;&lt;html&gt;&lt;br /&gt;&lt;br /&gt;  &lt;head&gt;&lt;br /&gt;&lt;br /&gt;    &lt;xml id="Myxml" src="hello.xml"&gt;&lt;/xml&gt;&lt;br /&gt;&lt;br /&gt;      &lt;script language="JavaScript"&gt;&lt;br /&gt;&lt;br /&gt;         function getData(){&lt;br /&gt;&lt;br /&gt;            xmldoc=document.all("Myxml").XMLDocument;&lt;br /&gt;&lt;br /&gt;            node=xmldoc.documentElement;&lt;br /&gt;&lt;br /&gt;            nodeMsg=node.firstChild;&lt;br /&gt;&lt;br /&gt;            output="From hello.xml file, you get -- " + nodeMsg.firstChild.nodeValue;&lt;br /&gt;&lt;br /&gt;            message.innerHTML=output;&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;     &lt;/script&gt;&lt;br /&gt;&lt;br /&gt;  &lt;/head&gt;&lt;br /&gt;&lt;br /&gt;&lt;body&gt;&lt;br /&gt;&lt;br /&gt;  &lt;h1 align=center&gt;Get data from XML document&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;Here comes: &lt;div id ="message"&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;input type="button" value="get data from xml" onclick="getData()"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/body&gt;&lt;br /&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;&lt;br /&gt;Here is the display in your browser. Click the button to see what happens? Press the "F5" button on your keyboard to refresh the display. If you cannot see the result from your browser, check if your browser blocks active contents or not. &lt;br /&gt;&lt;br /&gt;________________________________________&lt;br /&gt;&lt;br /&gt;Get data from XML document&lt;br /&gt;&lt;br /&gt;Here comes: &lt;br /&gt;&lt;br /&gt;________________________________________&lt;br /&gt;&lt;br /&gt;19. What is DTD tag?&lt;br /&gt;&lt;br /&gt;A DTD tag is a tag used in DTD definition file. It starts with &lt;! and ends with &gt;. It tells parser how to handle xml file.&lt;br /&gt;&lt;br /&gt;20. What is CDATA?&lt;br /&gt;&lt;br /&gt;A CDATA is a section mark which works like &lt;pre&gt;...&lt;/pre&gt; in HTML, only more so--all whitespace in a CDATA section is significant, and characters in it are not interpreted as XML. A CDATA section starts with &lt;![CDATA[ and ends with ]]&gt;. If you have a section which contains many &amp; or &lt;, you can mark it, so the XML processor will not parse it. &lt;br /&gt;&lt;br /&gt;21. What is the basic syntax for the document type declaration?&lt;br /&gt;&lt;br /&gt;The basic syntax:&lt;br /&gt;&lt;br /&gt;&lt;!DOCTYPE root-name [DTD]&gt;&lt;br /&gt;&lt;br /&gt;where the &lt;!DOCTYPE&gt; is part of a document's prolog; the root-name is the name of root tag; the DTD is a document type definition. It can be internal or external.&lt;br /&gt;&lt;br /&gt;The document type declaration may have the following forms:&lt;br /&gt;&lt;br /&gt;&lt;!DOCTYPE root-name [DTD]&gt;&lt;br /&gt;&lt;br /&gt;&lt;!DOCTYPE root-name SYSTEM URL&gt;&lt;br /&gt;&lt;br /&gt;&lt;!DOCTYPE root-name SYSTEM URL [DTD]&gt;&lt;br /&gt;&lt;br /&gt;&lt;!DOCTYPE root-name PUBLIC identifier URL&gt;&lt;br /&gt;&lt;br /&gt;&lt;!DOCTYPE root-name PUBLIC identifier URL [DTD]&gt;&lt;br /&gt;&lt;br /&gt;22. How the internal DTD looks like?&lt;br /&gt;&lt;br /&gt;&lt;?xml version="1.0" standalone="yes"?&gt;&lt;br /&gt;&lt;br /&gt;&lt;!DOCTYPE DOCUMENT [&lt;br /&gt;&lt;br /&gt;&lt;!ELEMENT DOCUMENT (CUSTOMER) *&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;]&gt;&lt;br /&gt;&lt;br /&gt;&lt;DOCUMENT&gt;&lt;br /&gt;&lt;br /&gt;    &lt;CUSTOMER&gt;&lt;br /&gt;&lt;br /&gt;....&lt;br /&gt;&lt;br /&gt;&lt;/DOCUMENT&gt;&lt;br /&gt;&lt;br /&gt;23. What is the syntax of element declaration?&lt;br /&gt;&lt;br /&gt;&lt;!ELEMENT NAME CONTENT_MODEL&gt;&lt;br /&gt;&lt;br /&gt;where name is the name of the element; CONTENT_MODEL can be set to EMPTY or ANY, or it can hold mixed content or child elements. &lt;br /&gt;&lt;br /&gt;24. What is the meaning of the following statement?&lt;br /&gt;&lt;br /&gt;&lt;!ELEMENT slideshow (slide+)&gt;&lt;br /&gt;&lt;br /&gt;This is a DTD tag definition. The notation says that a slideshow element consists of one or more slide elements. If there is no plus sign after slide, it says that a slideshow has only one slide element. If the plus sign is replaced with question mark "?", it says there may be zero or one slide. If the plus sign is replaced with asterisk "*", it say that there may be zero or more slide elements.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-1349475877419984911?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/1349475877419984911/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=1349475877419984911' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/1349475877419984911'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/1349475877419984911'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/xml-interview-question-part3.html' title='XML Interview Question Part3'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-3427195294269306161</id><published>2007-10-25T11:23:00.001-07:00</published><updated>2007-10-25T11:23:50.481-07:00</updated><title type='text'>XML Interview Question Part2</title><content type='html'>11. What is Unicode?&lt;br /&gt;&lt;br /&gt;Unicode uses 2 bytes to represent characters, extending from 0 to 65,535. ASCII(American Standard Code for Information Interchange) code uses 1 byte to represent characters, extending from 0 to 255. The Unicodes 0 to 255 correspond to the ASCII 0 to 255 codes. Therefore, Unicode can include many of the symbols commonly used in worldwide character and ideograph sets.&lt;br /&gt;&lt;br /&gt;UTF-8 means using a compressed version of Unicode that uses 8 bits to represent characters. UTF-16 is a special encoding that represents UCS(Universal Character System) symbols using 2 bytes to represent characters.&lt;br /&gt;&lt;br /&gt;12. How to write XML processing instructions?&lt;br /&gt;&lt;br /&gt;The XML processing instructions give commands or information to an application that is processing the XML data; it is application specific. It has the following format: &lt;br /&gt;&lt;br /&gt;  &lt;?target instructions?&gt; &lt;br /&gt;&lt;br /&gt;where &lt;? is the start and ?&gt; is the end of procession instruction, the "target" is the name of the application that is expected to do the processing, and "instructions" is a string of characters that embodies the information or commands for the application to process. Note: there cannot be any space between the initial &lt;? and the target identifier. The "instructions" begins after the first space. Fully qualifying the target with the complete web-unique package prefix is recommended. For readability, use a (:) after the target name. Like &lt;br /&gt;&lt;br /&gt;&lt;?my.subdirectory.myprograme: query="..."?&gt;&lt;br /&gt;&lt;br /&gt;An XML file may have multiple processing instructions to tell different applications to do similar things.&lt;br /&gt;&lt;br /&gt;13. How XML treats with whitespace?&lt;br /&gt;&lt;br /&gt;The spaces, carriage returns, line feeds and tabs are all treated as whitespace in XML. XML document uses the UNIX convention for line endings, which means that lines are ended with a linefeed character only -- ASCII code 10(DOS file uses a pair of ASCII codes 13 and 10). When parsed, that is treated simply as a single linefeed.&lt;br /&gt;&lt;br /&gt;If you want to preserve whitespace, use a special attribute xml:space or set attribute to default to indicate it in a element declaration. &lt;br /&gt;&lt;br /&gt;14. Is XML tag case-sensitive?&lt;br /&gt;&lt;br /&gt;Yes. XML tags are case-sensitive. The start and end tags should be matched exactly.&lt;br /&gt;&lt;br /&gt;15. Why do people say that XML is portable?&lt;br /&gt;&lt;br /&gt;There are several reasons. First, it is written in a text format, which is readable by both human beings and text-editing software. Second, applications can parse and process XML documents, and human beings can also read them in case there is an error in processing. Third, XML document does not include formatting instructions, it can be displayed in various ways. Keeping data separate from formatting instructions means that the same data can be published to different media.&lt;br /&gt;&lt;br /&gt;16. How to let browser display XML file?&lt;br /&gt;&lt;br /&gt;There are two ways to do so:&lt;br /&gt;&lt;br /&gt;o Use a style sheet to indicate to a browser how you want the content of the elements to be displayed, like Cascading Style Sheet(CSS) or Extensible Style Sheet Language(XSL).&lt;br /&gt;&lt;br /&gt;o use a programming language to handle the XML document in programming code,like Java or JavaScript.&lt;br /&gt;&lt;br /&gt;17. Which is better to store data using elements or using attributes?&lt;br /&gt;&lt;br /&gt;There is no clear-cut to say which is better. It depends on the case. But it is worth noting that too many attributes make documents hard to read and attribute names must be unique. If more than 4 attributes in a tag are used, think about breaking up the tag into a number of enclosed tags.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-3427195294269306161?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/3427195294269306161/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=3427195294269306161' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/3427195294269306161'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/3427195294269306161'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/xml-interview-question-part2.html' title='XML Interview Question Part2'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-9068238076987092730</id><published>2007-10-25T11:22:00.000-07:00</published><updated>2007-10-25T11:23:30.685-07:00</updated><title type='text'>XML Interview Question Part1</title><content type='html'>7. What is an empty tag?&lt;br /&gt;&lt;br /&gt;Empty tag is a tag with ending "/&gt;" and used to mark something in your well-formed tags. It doesn't contain any content, so it is called "empty tag". It has two forms:&lt;br /&gt;&lt;br /&gt;&lt;info/&gt;&lt;br /&gt;&lt;br /&gt;Note: not &lt;/info&gt;&lt;br /&gt;&lt;br /&gt;or &lt;br /&gt;&lt;br /&gt;&lt;tg&gt; &lt;/tg&gt;&lt;br /&gt;&lt;br /&gt;or &lt;br /&gt;&lt;br /&gt;&lt;Greeting text="hello guys" /&gt;&lt;br /&gt;&lt;br /&gt;8. What comments should be used in XML?&lt;br /&gt;&lt;br /&gt;Comments are ignored by XML parsers. A program will never see them in fact, unless you activate special settings in the parser. XML comments are very much like HTML comments.&lt;br /&gt;&lt;br /&gt;&lt;!-- this is a comment --&gt;&lt;br /&gt;&lt;br /&gt;It is worth noting that Comments must not come before an XML declaration or inside markups. You cannot use "--" between your comments. You can use comments to hide or remove parts of documents as long as the enclosed parts do not themselves contain any comments. &lt;br /&gt;&lt;br /&gt;9. How to deal with special characters in XML like &lt; or &amp;, etc.?&lt;br /&gt;&lt;br /&gt;Like HTML, you should use entity reference to replace them, even if in embeded JavaScript code.&lt;br /&gt;&lt;br /&gt;10. What is XML Prolog?&lt;br /&gt;&lt;br /&gt;Prologs come at the very beginning of XML documents. Like HTML's tag &lt;html&gt;, XML prolog is a declaration that is used to indicate the start of XML file like the following:&lt;br /&gt;&lt;br /&gt;&lt;?xml version="1.0"?&gt;&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;&lt;?xml version='1.0' encoding='utf-8'?&gt;&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?&gt;&lt;br /&gt;&lt;br /&gt;It contains some or all of three attributes:&lt;br /&gt;&lt;br /&gt;o version -- not optional&lt;br /&gt;&lt;br /&gt;o encoding -- default UTF-8&lt;br /&gt;&lt;br /&gt;o standalone -- "yes" or "no"&lt;br /&gt;&lt;br /&gt;It is a good practice to include XML prolog whenever you create an XML file, though it is optional.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-9068238076987092730?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/9068238076987092730/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=9068238076987092730' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/9068238076987092730'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/9068238076987092730'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/xml-interview-question-part1.html' title='XML Interview Question Part1'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-3117558167767582740</id><published>2007-10-25T11:20:00.000-07:00</published><updated>2007-10-25T11:22:31.544-07:00</updated><title type='text'>XML Interview Question</title><content type='html'>1. What Is XML? &lt;br /&gt;&lt;br /&gt;XML stands for Extensible Markup Language. It is a text-based meta-markup language defined by the World Wide Web Consortium. It has become the standard for data interchange on the Web. &lt;br /&gt;&lt;br /&gt;2. Why do we need to learn XML?&lt;br /&gt;&lt;br /&gt;Because XML is a meta-markup language, it lets you create your own markup language.&lt;br /&gt;&lt;br /&gt;It is easy for data exchange, customization, self-describing, structured and integrated.&lt;br /&gt;&lt;br /&gt;3. What does XML look like?&lt;br /&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;br /&gt;&lt;br /&gt;   &lt;DOCUMENT&gt;&lt;br /&gt;&lt;br /&gt;        &lt;MESSAGE&gt;&lt;br /&gt;&lt;br /&gt;            Hello guys!&lt;br /&gt;&lt;br /&gt;        &lt;/MESSAGE&gt;&lt;br /&gt;&lt;br /&gt;   &lt;/DOCUMENT&gt; &lt;br /&gt;&lt;br /&gt;4. What is the difference between HTML and XML?&lt;br /&gt;&lt;br /&gt;HTML and XML both are based on Standard Generalized Markup Language(SGML), but&lt;br /&gt;&lt;br /&gt;o HTML uses predefined tags, whereas XML uses user-defined tags which can be used to identify data relationships like hierarchical structure(elements, subelements, subsubelements,and so on.)&lt;br /&gt;&lt;br /&gt;o HTML specifies its representation, whereas XML identifies the content for the data.&lt;br /&gt;&lt;br /&gt;o Unlike HTML, XML tags are well-formed. XML data is searchable, format-free and reusable.&lt;br /&gt;&lt;br /&gt;5. What is XML attribute?&lt;br /&gt;&lt;br /&gt;Attribute is an additional information attached to a tag. For example&lt;br /&gt;&lt;br /&gt;&lt;message to="judy@javacamp.com" from="you@yahoo.com" &lt;br /&gt;&lt;br /&gt;    subject="Discuss XML issues"&gt; &lt;br /&gt;&lt;br /&gt; &lt;text&gt;    &lt;br /&gt;&lt;br /&gt;    here we go&lt;br /&gt;&lt;br /&gt;  &lt;/text&gt;&lt;br /&gt;&lt;br /&gt;&lt;/message&gt; &lt;br /&gt;&lt;br /&gt;The "to", "from" and "subject" are attributes of "message" tag. &lt;br /&gt;&lt;br /&gt;6. How to deal with double quotes in attribute assignment?&lt;br /&gt;&lt;br /&gt;Use a single quote to enclose a double quotes, for example,&lt;br /&gt;&lt;br /&gt;&lt;quote txt='he said, "hello guys" ' /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-3117558167767582740?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/3117558167767582740/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=3117558167767582740' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/3117558167767582740'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/3117558167767582740'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/xml-interview-question.html' title='XML Interview Question'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-4601919234825116207</id><published>2007-10-25T11:19:00.003-07:00</published><updated>2007-10-25T11:19:50.406-07:00</updated><title type='text'>Java Newworking questions Part2</title><content type='html'>5. What are the two important TCP Socket classes?&lt;br /&gt;Socket and ServerSocket. ServerSocket is used for normal two-way socket communication. Socket class allows us to read and write through the sockets. getInputStream() and getOutputStream() are the two methods available in Socket class. &lt;br /&gt;________________________________________&lt;br /&gt;6. When MalformedURLException and UnknownHostException throws?&lt;br /&gt;When the specified URL is not connected then the URL throw MalformedURLException and If InetAddress? methods getByName and getLocalHost are unable to resolve the host name they throw an UnknownHostException. &lt;br /&gt;________________________________________&lt;br /&gt;7. What does RMI stand for?&lt;br /&gt;It stands for Remote Method Invocation. &lt;br /&gt;________________________________________&lt;br /&gt;8. What is RMI?&lt;br /&gt;RMI is a set of APIs that allows to build distributed applications. RMI uses interfaces to define remote objects to turn local method invocations into remote method invocations. &lt;br /&gt;________________________________________&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-4601919234825116207?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/4601919234825116207/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=4601919234825116207' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4601919234825116207'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4601919234825116207'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/java-newworking-questions-part2.html' title='Java Newworking questions Part2'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-197966591589691145</id><published>2007-10-25T11:19:00.001-07:00</published><updated>2007-10-25T11:19:27.289-07:00</updated><title type='text'>Java Newworking questions Part1</title><content type='html'>1. What is the difference between URL instance and URLConnection instance?&lt;br /&gt;A URL instance represents the location of a resource, and a URLConnection instance represents a link for accessing or communicating with the resource at the location. &lt;br /&gt;________________________________________&lt;br /&gt;2. How do I make a connection to URL?&lt;br /&gt;You obtain a URL instance and then invoke openConnection on it. URLConnection is an abstract class, which means you can't directly create instances of it using a constructor. We have to invoke openConnection method on a URL instance, to get the right kind of connection for your URL. Eg. URL url; &lt;br /&gt;URLConnection connection;&lt;br /&gt;    try{ url = new URL("...");&lt;br /&gt;        connection = url.openConnection();&lt;br /&gt;    }catch (MalFormedURLException e) { }&lt;br /&gt;________________________________________&lt;br /&gt;3. What Is a Socket?&lt;br /&gt;A socket is one end-point of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent. Socket classes are used to represent the connection between a client program and a server program. The java.net package provides two classes--Socket and ServerSocket--which implement the client side of the connection and the server side of the connection, respectively. &lt;br /&gt;________________________________________&lt;br /&gt;4. What information is needed to create a TCP Socket? &lt;br /&gt;The Local System?s IP Address and Port Number. And the Remote System's IPAddress and Port Number. &lt;br /&gt;________________________________________&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-197966591589691145?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/197966591589691145/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=197966591589691145' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/197966591589691145'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/197966591589691145'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/java-newworking-questions-part1.html' title='Java Newworking questions Part1'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-5820797131420582570</id><published>2007-10-25T11:18:00.001-07:00</published><updated>2007-10-25T11:18:46.541-07:00</updated><title type='text'>Java MVC</title><content type='html'>MVC&lt;br /&gt;The MVC (Model-View-Controller) architecture the client request is first intercepted by a servlet referred as controller servlet. this servlet handles the initial processing of the request and determines which JSP page to display next. Here the controller servlet is the single point of entry, there is a clear sepration of business logic, presentation output and request processing. MCV architecture is a way of decomposing an application into three parts:&lt;br /&gt;&lt;br /&gt;The model maintains the state and data that the application represents.&lt;br /&gt;The view allows the display of information about the model to the user.&lt;br /&gt;The controller allows the user to manipulate the application. &lt;br /&gt;the model, the view and the controller.&lt;br /&gt;&lt;br /&gt;MVC was originally applied in the graphical user interaction model of input, processing and output.&lt;br /&gt;&lt;br /&gt;In Struts, the view is handled by JSPs and presentation components, the model is represented by Java Beans and the controller uses Servlets to perform its action. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Model &lt;br /&gt;A model represents an application’s data and contains the logic for accessing and manipulating that data. Any data that is part of the persistent state of the application should reside in the model objects. The business objects update the application state. ActionForm bean represents the Model state at a session or request level, and not at a persistent level. Model services are accessed by the controller for either querying or effecting a change in the model state. The model notifies the view when a state change occurs in the model.The JSP file reads information from the ActionForm bean using JSP tags. &lt;br /&gt;&lt;br /&gt;View&lt;br /&gt;The view is responsible for rendering the state of the model. The presentation semantics are encapsulated within the view, therefore model data can be adapted for several different kinds of clients.The view modifies itself when a change in the model is communicated to the view. A view forwards user input to the controller.The view is simply a JSP or HTML file. There is no flow logic, no business logic, and no model information -- just tags. Tags are one of the things that make Struts unique compared to other frameworks like Velocity.&lt;br /&gt;&lt;br /&gt;Controller&lt;br /&gt;The controller is responsible for intercepting and translating user input into actions to&lt;br /&gt;be performed by the model. The controller is responsible for selecting the next view based on user input and the outcome of model operations.The Controller receives the request from the browser, and makes the decision where to send the request. With Struts, the Controller is a command design pattern implemented as a servlet. The struts-config.xml file configures the Controller.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-5820797131420582570?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/5820797131420582570/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=5820797131420582570' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5820797131420582570'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/5820797131420582570'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/java-mvc.html' title='Java MVC'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-2278791427817074886</id><published>2007-10-25T11:17:00.001-07:00</published><updated>2007-10-25T11:17:29.154-07:00</updated><title type='text'>JMS Interview Questions</title><content type='html'>Q: What is the use of Message object?&lt;br /&gt;A: Message is a light weight message having only header and properties and no payload. Thus if the received are to be notified abt an event, and no data needs to be exchanged then using Message can be very efficient.&lt;br /&gt;  [ Received from Sandesh Sadhale] &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: What is the basic difference between Publish Subscribe model and P2P model?&lt;br /&gt;A: Publish Subscribe model is typically used in one-to-many situation. It is unreliable but very fast. P2P model is used in one-to-one situation. It is highly reliable.&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: What is the use of BytesMessage?&lt;br /&gt;A: BytesMessage contains an array of primitive bytes in it's payload. Thus it can be used for transfer of data between two applications in their native format which may not be compatible with other Message types. It is also useful where JMS is used purely as a transport between two systems and the message payload is opaque to the JMS client. Whenever you store any primitive type, it is converted into it's byte representation and then stored in the payload. There is no boundary line between the different data types stored. Thus you can even read a long as short. This would result in erroneous data and hence it is advisable that the payload be read in the same order and using the same type in which it was created by the sender.&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: What is the use of StreamMessage?&lt;br /&gt;A: StreamMessage carries a stream of Java primitive types as it's payload. It contains some conveient methods for reading the data stored in the payload. However StreamMessage prevents reading a long value as short, something that is allwed in case of BytesMessage. This is so because the StreamMessage also writes the type information alonwgith the value of the primitive type and enforces a set of strict conversion rules which actually prevents reading of one primitive type as another. &lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: What is the use of TextMessage?&lt;br /&gt;A: TextMessage contains instance of java.lang.String as it's payload. Thus it is very useful for exchanging textual data. It can also be used for exchanging complex character data such as an XML document.&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: What is the use of ObjectMessage?&lt;br /&gt;A: ObjectMessage contains a Serializable java object as it's payload. Thus it allows exchange of Java objects between applications. This in itself mandates that both the applications be Java applications. The consumer of the message must typecast the object received to it's appropriate type. Thus the consumer should before hand know the actual type of the object sent by the sender. Wrong type casting would result in ClassCastException. Moreover the class definition of the object set in the payload should be available on both the machine, the sender as well as the consumer. If the class definition is not available in the consumer machine, an attempt to type cast would result in ClassNotFoundException. Some of the MOMs might support dynamic loading of the desired class over the network, but the JMS specification does not mandate this behavior and would be a value added service if provided by your vendor. And relying on any such vendor specific functionality would hamper the portability of your application. Most of the time the class need to be put in the classpath of both, the sender and the consumer, manually by the developer.&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: What is the use of MapMessage?&lt;br /&gt;A: A MapMessage carries name-value pair as it's payload. Thus it's payload is similar to the java.util.Properties object of Java. The values can be Java primitives or their wrappers.&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: What is the difference between BytesMessage and StreamMessage??&lt;br /&gt;A: BytesMessage stores the primitive data types by converting them to their byte representation. Thus the message is one contiguous stream of bytes. While the StreamMessage maintains a boundary between the different data types stored because it also stores the type information along with the value of the primitive being stored. BytesMessage allows data to be read using any type. Thus even if your payload contains a long value, you can invoke a method to read a short and it will return you something. It will not give you a semantically correct data but the call will succeed in reading the first two bytes of data. This is strictly prohibited in the StreamMessage. It maintains the type information of the data being stored and enforces strict conversion rules on the data being read.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-2278791427817074886?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/2278791427817074886/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=2278791427817074886' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2278791427817074886'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/2278791427817074886'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/jms-interview-questions_4324.html' title='JMS Interview Questions'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-4001425964466978507</id><published>2007-10-25T11:16:00.001-07:00</published><updated>2007-10-25T11:16:53.065-07:00</updated><title type='text'>JMS Interview Questions</title><content type='html'>Q: What is JMS?&lt;br /&gt;A: JMS is an acronym used for Java Messaging Service. It is Java's answer to creating software using asynchronous messaging. It is one of the official specifications of the J2EE technologies and is a key technology.&lt;br /&gt;   &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: How JMS is different from RPC?&lt;br /&gt;A: In RPC the method invoker waits for the method to finish execution and return the control back to the invoker. Thus it is completely synchronous in nature. While in JMS the message sender just sends the message to the destination and continues it's own processing. The sender does not wait for the receiver to respond. This is asynchronous behavior.&lt;br /&gt;   &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: What are the advantages of JMS?&lt;br /&gt;A: JMS is asynchronous in nature. Thus not all the pieces need to be up all the time for the application to function as a whole. Even if the receiver is down the MOM will store the messages on it's behalf and will send them once it comes back up. Thus at least a part of application can still function as there is no blocking.   &lt;br /&gt;   &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: Are you aware of any major JMS products available in the market? &lt;br /&gt;A: IBM's MQ Series is one of the most popular product used as Message Oriented Middleware. Some of the other products are SonicMQ, iBus etc. Weblogic application server also comes with built in support for JMS messaging. &lt;br /&gt;   &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: What are the different types of messages available in the JMS API? &lt;br /&gt;A: Message, TextMessage, BytesMessage, StreamMessage, ObjectMessage, MapMessage are the different messages available in the JMS API. &lt;br /&gt;   &lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Q: What are the different messaging paradigms JMS supports?&lt;br /&gt;A: Publish and Subscribe i.e. pub/suc and Point to Point i.e. p2p.&lt;br /&gt;   &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: What is the difference between topic and queue?&lt;br /&gt;A: A topic is typically used for one to many messaging i.e. it supports publish subscribe model of messaging. While queue is used for one-to-one messaging i.e. it supports Point to Point Messaging.&lt;br /&gt;   &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: What is the role of JMS in enterprise solution development?&lt;br /&gt;A: JMS is typically used in the following scenarios&lt;br /&gt;1. Enterprise Application Integration: - Where a legacy application is integrated with a new application via messaging.&lt;br /&gt;2. B2B or Business to Business: - Businesses can interact with each other via messaging because JMS allows organizations to cooperate without tightly coupling their business systems.&lt;br /&gt;3. Geographically dispersed units: - JMS can ensure safe exchange of data amongst the geographically dispersed units of an organization.&lt;br /&gt;4. One to many applications: - The applications that have to push data in packet to huge number of clients in a one-to-many fashion are good candidates for the use JMS. Typical such applications are Auction Sites, Stock Quote Services etc.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-4001425964466978507?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/4001425964466978507/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=4001425964466978507' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4001425964466978507'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4001425964466978507'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/jms-interview-questions_25.html' title='JMS Interview Questions'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-4615314652537892780</id><published>2007-10-25T11:12:00.002-07:00</published><updated>2007-10-25T11:13:09.684-07:00</updated><title type='text'>Jdbc Interview Questions Part4</title><content type='html'>31. How to store and retrive an object?&lt;br /&gt;A class can be serialized to a binary database field in much the same way as the image. You may use the code above to store and retrive an object. &lt;br /&gt;________________________________________&lt;br /&gt;32. How to use meta data to check a column type?&lt;br /&gt;Use getMetaData().getColumnType() method to check data type. For example to retrieve an Integer, you may check it first:&lt;br /&gt;  int count=0;&lt;br /&gt;  Connection con=getConnection();&lt;br /&gt;  Statement stmt= con.createStatement();&lt;br /&gt;  stmt.executeQuery("select counter from aTable");&lt;br /&gt;  ResultSet rs = stmt.getResultSet();&lt;br /&gt;  if(rs.next()) {&lt;br /&gt;      if(rs.getMetaData().getColumnType(1) == Types.INTEGER) {&lt;br /&gt;      Integer i=(Integer)rs.getObject(1);&lt;br /&gt;      count=i.intValue();&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;  rs.close();&lt;br /&gt;________________________________________&lt;br /&gt;33. Why cannot java.util.Date match with java.sql.Date?&lt;br /&gt;Because java.util.Date represents both date and time. SQL has three types to represent date and time. &lt;br /&gt;o java.sql.Date -- (00/00/00) &lt;br /&gt;o java.sql.Time -- (00:00:00) &lt;br /&gt;o java.sql.Timestamp -- in nanoseconds &lt;br /&gt;Note that they are subclasses of java.util.Date. &lt;br /&gt;________________________________________&lt;br /&gt;34. How to convert java.util.Date value to java.sql.Date?&lt;br /&gt;Use the code below:&lt;br /&gt;Calendar currenttime=Calendar.getInstance();&lt;br /&gt;java.sql.Date startdate= new java.sql.Date((currenttime.getTime()).getTime());&lt;br /&gt;&lt;br /&gt;or &lt;br /&gt;&lt;br /&gt;SimpleDateFormat template = new SimpleDateFormat("yyyy-MM-dd"); &lt;br /&gt;java.util.Date enddate = new java.util.Date("10/31/99"); &lt;br /&gt;java.sql.Date sqlDate = java.sql.Date.valueOf(template.format(enddate)); &lt;br /&gt;________________________________________&lt;br /&gt;Note: Most of sample codes are cited from Sun's JDBC tutorials.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-4615314652537892780?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/4615314652537892780/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=4615314652537892780' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4615314652537892780'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/4615314652537892780'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/jdbc-interview-questions-part4.html' title='Jdbc Interview Questions Part4'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-8365133872413203547</id><published>2007-10-25T11:12:00.001-07:00</published><updated>2007-10-25T11:12:50.000-07:00</updated><title type='text'>Jdbc Interview Questions Part3</title><content type='html'>21. How to make an update?&lt;br /&gt;Creates a Statement object and calls the Statement.executeUpdate method. &lt;br /&gt; &lt;br /&gt;String updateString = "INSERT INTO aDatabase VALUES (some text)";&lt;br /&gt;int count = stmt.executeUpdate(updateString);&lt;br /&gt;________________________________________&lt;br /&gt;22. How to update a ResultSet?&lt;br /&gt;You can update a value in a result set by calling the ResultSet.update method on the row where the cursor is positioned. The type value here is the same used when retrieving a value from the result set, for example, updateString updates a String value and updateDouble updates a double value in the result set. &lt;br /&gt; rs.first();&lt;br /&gt; updateDouble("balance", rs.getDouble("balance") - 5.00);&lt;br /&gt;The update applies only to the result set until the call to rs.updateRow(), which updates the underlying database. &lt;br /&gt;To delete the current row, use rs.deleteRow().&lt;br /&gt;To insert a new row, use rs.moveToInsertRow().&lt;br /&gt;________________________________________&lt;br /&gt;23. How can you use PreparedStatement? &lt;br /&gt;This special type of statement is derived from the more general class, Statement. If you want to execute a Statement object many times, it will normally reduce execution time to use a PreparedStatement object instead. The advantage to this is that in most cases, this SQL statement will be sent to the DBMS right away, where it will be compiled. As a result, the PreparedStatement object contains not just an SQL statement, but an SQL statement that has been precompiled. This means that when the PreparedStatement is executed, the DBMS can just run the PreparedStatement 's SQL statement without having to compile it first. &lt;br /&gt;PreparedStatement updateSales = con.prepareStatement("UPDATE COFFEES SET SALES = ? WHERE COF_NAME LIKE ?");&lt;br /&gt;________________________________________&lt;br /&gt;24. How to call a Stored Procedure from JDBC?&lt;br /&gt;The first step is to create a CallableStatement object. As with Statement an and PreparedStatement objects, this is done with an open Connection object. A CallableStatement object contains a call to a stored procedure; &lt;br /&gt;E.g.&lt;br /&gt;CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");&lt;br /&gt;ResultSet rs = cs.executeQuery();&lt;br /&gt;________________________________________&lt;br /&gt;25. How to Retrieve Warnings?&lt;br /&gt;SQLWarning objects are a subclass of SQLException that deal with database access warnings. Warnings do not stop the execution of an application, as exceptions do; they simply alert the user that something did not happen as planned. A warning can be reported on a Connection object, a Statement object (including PreparedStatement and CallableStatement objects), or a ResultSet object. Each of these classes has a getWarnings method, which you must invoke in order to see the first warning reported on the calling object &lt;br /&gt;SQLWarning warning = stmt.getWarnings();&lt;br /&gt;    if (warning != null) {&lt;br /&gt;&lt;br /&gt;        while (warning != null) {&lt;br /&gt;          System.out.println("Message: " + warning.getMessage());&lt;br /&gt;          System.out.println("SQLState: " + warning.getSQLState());&lt;br /&gt;          System.out.print("Vendor error code: ");&lt;br /&gt;          System.out.println(warning.getErrorCode());&lt;br /&gt;          warning = warning.getNextWarning();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;________________________________________&lt;br /&gt;26. How to Make Updates to Update ResultSets?&lt;br /&gt;Another new feature in the JDBC 2.0 API is the ability to update rows in a result set using methods in the Java programming language rather than having to send an SQL command. But before you can take advantage of this capability, you need to create a ResultSet object that is updatable. In order to do this, you supply the ResultSet constant CONCUR_UPDATABLE to the createStatement method. &lt;br /&gt;Connection con = DriverManager.getConnection("jdbc:mySubprotocol:mySubName");&lt;br /&gt;Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, &lt;br /&gt;ResultSet.CONCUR_UPDATABLE);&lt;br /&gt;ResultSet uprs = ("SELECT COF_NAME, PRICE FROM COFFEES");&lt;br /&gt;________________________________________&lt;br /&gt;27. How to set a scroll type?&lt;br /&gt;Both Statements and PreparedStatements have an additional constructor that accepts a scroll type and an update type parameter. The scroll type value can be one of the following values: &lt;br /&gt;o ResultSet.TYPE_FORWARD_ONLY &lt;br /&gt;Default behavior in JDBC 1.0, application can only call next() on the result set. &lt;br /&gt;o ResultSet.SCROLL_SENSITIVE &lt;br /&gt;ResultSet is fully navigable and updates are reflected in the result set as they occur. &lt;br /&gt;o ResultSet.SCROLL_INSENSITIVE &lt;br /&gt;Result set is fully navigable, but updates are only visible after the result set is closed. You need to create a new result set to see the results. &lt;br /&gt;________________________________________&lt;br /&gt;28. How to set update type parameter?&lt;br /&gt;In the constructors of Statements and PreparedStatements, you may use&lt;br /&gt;o ResultSet.CONCUR_READ_ONLY&lt;br /&gt;The result set is read only. &lt;br /&gt;o ResultSet.CONCUR_UPDATABLE&lt;br /&gt;The result set can be updated. &lt;br /&gt;You may verify that your database supports these types by calling con.getMetaData().supportsResultSetConcurrency(ResultSet.SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); &lt;br /&gt;________________________________________&lt;br /&gt;29. How to do a batch job?&lt;br /&gt;By default, every JDBC statement is sent to the database individually. To send multiple statements at one time , use addBatch() method to append statements to the original statement and call executeBatch() method to submit entire statement.&lt;br /&gt;Statement stmt = con.createStatement();&lt;br /&gt;stmt.addBatch("update registration set balance=balance-5.00 where theuser="+theuser);&lt;br /&gt;stmt.addBatch("insert into auctionitems(description, startprice) values("+description+","+startprice+")");&lt;br /&gt;...&lt;br /&gt;int[] results = stmt.executeBatch();&lt;br /&gt;The return result of the addBatch() method is an array of row counts affected for each statement executed in the batch job. If a problem occurred, a java.sql.BatchUpdateException is thrown. An incomplete array of row counts can be obtained from BatchUpdateException by calling its getUpdateCounts() method. &lt;br /&gt;30. How to store and retrieve an image?&lt;br /&gt;To store an image, you may use the code: &lt;br /&gt;int itemnumber=400456;&lt;br /&gt;&lt;br /&gt;File file = new File(itemnumber+".jpg");&lt;br /&gt;FileInputStream fis = new FileInputStream(file);&lt;br /&gt;PreparedStatement pstmt = con.prepareStatement("update auctionitems set theimage=? where id= ?");&lt;br /&gt;pstmt.setBinaryStream(1, fis, (int)file.length()):&lt;br /&gt;pstmt.setInt(2, itemnumber);&lt;br /&gt;pstmt.executeUpdate();&lt;br /&gt;pstmt.close();&lt;br /&gt;fis.close();&lt;br /&gt;To retrieve an image: &lt;br /&gt;int itemnumber=400456;&lt;br /&gt;byte[] imageBytes;//hold an image bytes to pass to createImage().&lt;br /&gt; &lt;br /&gt;PreparedStatement pstmt = con.prepareStatement("select theimage from auctionitems where id= ?");&lt;br /&gt;pstmt.setInt(1, itemnumber);&lt;br /&gt;ResultSet rs=pstmt.executeQuery();&lt;br /&gt;if(rs.next()) {&lt;br /&gt;    imageBytes = rs.getBytes(1);&lt;br /&gt;}&lt;br /&gt;pstmt.close();&lt;br /&gt;rs.close();&lt;br /&gt;&lt;br /&gt;Image auctionimage = Toolkit.getDefaultToolkit().createImage(imageBytes);&lt;br /&gt;________________________________________&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-8365133872413203547?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/8365133872413203547/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=8365133872413203547' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/8365133872413203547'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/8365133872413203547'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/jdbc-interview-questions-part3.html' title='Jdbc Interview Questions Part3'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-3664309068304537700</id><published>2007-10-25T11:11:00.001-07:00</published><updated>2007-10-25T11:11:59.979-07:00</updated><title type='text'>Jdbc Interview Questions Part2</title><content type='html'>15. How to make a query? &lt;br /&gt;Create a Statement object and calls the Statement.executeQuery method to select data from the database. The results of the query are returned in a ResultSet object. &lt;br /&gt;Statement stmt = con.createStatement();&lt;br /&gt;ResultSet results = stmt.executeQuery("SELECT data FROM aDatabase ");&lt;br /&gt;________________________________________&lt;br /&gt;16. How can you retrieve data from the ResultSet?&lt;br /&gt;Use get methods to retrieve data from returned ResultSet object. &lt;br /&gt;ResultSet rs = stmt.executeQuery("SELECT COF_NAME, PRICE FROM COFFEES");&lt;br /&gt;String s = rs.getString("COF_NAME");&lt;br /&gt;The method getString is invoked on the ResultSet object rs , so getString will retrieve (get) the value stored in the column COF_NAME in the current row of rs &lt;br /&gt;________________________________________&lt;br /&gt;17. How to navigate the ResultSet?&lt;br /&gt;By default the result set cursor points to the row before the first row of the result set. A call to next() retrieves the first result set row. The cursor can also be moved by calling one of the following ResultSet methods: &lt;br /&gt;o beforeFirst(): Default position. Puts cursor before the first row of the result set. &lt;br /&gt;o first(): Puts cursor on the first row of the result set. &lt;br /&gt;o last(): Puts cursor before the last row of the result set. &lt;br /&gt;o afterLast() Puts cursor beyond last row of the result set. Calls to previous moves backwards through the ResultSet. &lt;br /&gt;o absolute(pos): Puts cursor at the row number position where absolute(1) is the first row and absolute(-1) is the last row.&lt;br /&gt;o relative(pos): Puts cursor at a row relative to its current position where relative(1) moves row cursor one row forward. &lt;br /&gt;________________________________________&lt;br /&gt;18. What are the different types of Statements?&lt;br /&gt;0. Statement (use createStatement method)&lt;br /&gt;1. Prepared Statement (Use prepareStatement method)&lt;br /&gt;2. Callable Statement (Use prepareCall)&lt;br /&gt;________________________________________&lt;br /&gt;19. If you want to use the percent sign (%) as the percent sign and not have it interpreted as the SQL wildcard used in SQL LIKE queries, how to do that?&lt;br /&gt;Use escape keyword. For example: &lt;br /&gt;stmt.executeQuery("select tax from sales where tax like '10\%' {escape '\'}");&lt;br /&gt;________________________________________&lt;br /&gt;20. How to escape ' symbol found in the input line?&lt;br /&gt;You may use a method to do so: &lt;br /&gt;static public String escapeLine(String s) {&lt;br /&gt;  String retvalue = s;&lt;br /&gt;  if (s.indexOf ("'") != -1 ) {&lt;br /&gt;    StringBuffer hold = new StringBuffer();&lt;br /&gt;    char c;&lt;br /&gt;    for(int i=0; i &lt; s.length(); i++ ) {&lt;br /&gt;      if ((c=s.charAt(i)) == '\'' ) {&lt;br /&gt;      hold.append ("''");&lt;br /&gt;    }else {&lt;br /&gt;      hold.append(c);&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;  retvalue = hold.toString();&lt;br /&gt;  }&lt;br /&gt;  return retvalue;&lt;br /&gt;}&lt;br /&gt;Note that such method can be extended to escape any other characters that the database driver may interprete another way. &lt;br /&gt;________________________________________&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-3664309068304537700?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/3664309068304537700/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=3664309068304537700' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/3664309068304537700'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/3664309068304537700'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/jdbc-interview-questions-part2.html' title='Jdbc Interview Questions Part2'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-6868804674620522673</id><published>2007-10-25T11:09:00.002-07:00</published><updated>2007-10-25T11:11:19.285-07:00</updated><title type='text'>Jdbc Interview Questions Part1</title><content type='html'>6. What are four types of JDBC driver?&lt;br /&gt;1. Type 1 Drivers&lt;br /&gt;Bridge drivers such as the jdbc-odbc bridge. They rely on an intermediary such as ODBC to transfer the SQL calls to the database and also often rely on native code. &lt;br /&gt;2. Type 2 Drivers&lt;br /&gt;Use the existing database API to communicate with the database on the client. Faster than Type 1, but need native code and require additional permissions to work in an applet. Good for client-side connection.&lt;br /&gt;3. Type 3 Drivers&lt;br /&gt;Call the database API on the server.Flexible. Pure Java and no native code. &lt;br /&gt;4. Type 4 Drivers&lt;br /&gt;The hightest level of driver reimplements the database network API in Java. No native code. &lt;br /&gt;________________________________________&lt;br /&gt;7. What packages are used by JDBC?&lt;br /&gt;There are at least 8 packages: &lt;br /&gt;0. java.sql.Driver&lt;br /&gt;1. Connection&lt;br /&gt;2. Statement&lt;br /&gt;3. PreparedStatement&lt;br /&gt;4. CallableStatement&lt;br /&gt;5. ResultSet&lt;br /&gt;6. ResultSetMetaData&lt;br /&gt;7. DatabaseMetaData&lt;br /&gt;________________________________________&lt;br /&gt;8. There are three basic types of SQL statements, what are they?&lt;br /&gt;0. Statement&lt;br /&gt;1. callableStatement&lt;br /&gt;2. PreparedStatement&lt;br /&gt;________________________________________&lt;br /&gt;9. What are the flow statements of JDBC?&lt;br /&gt;A URL string --&gt;getConnection--&gt;DriverManager--&gt;Driver--&gt;Connection--&gt;Statement--&gt;executeQuery--&gt;ResultSet. &lt;br /&gt;________________________________________&lt;br /&gt;10. What are the steps involved in establishing a connection? &lt;br /&gt;This involves two steps: (1) loading the driver and (2) making the connection. &lt;br /&gt;________________________________________&lt;br /&gt;11. How can you load the drivers?&lt;br /&gt;Loading the driver or drivers you want to use is very simple and involves just one line of code. If, for example, you want to use the JDBC-ODBC Bridge driver, the following code will load it: &lt;br /&gt;Eg.&lt;br /&gt;Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");&lt;br /&gt;Your driver documentation will give you the class name to use. For instance, if the class name is jdbc.DriverXYZ , you would load the driver with the following line of code: &lt;br /&gt;E.g.&lt;br /&gt;Class.forName("jdbc.DriverXYZ");&lt;br /&gt;________________________________________&lt;br /&gt;12. What Class.forName will do while loading drivers?&lt;br /&gt;It is used to create an instance of a driver and register it with the DriverManager. When you have loaded a driver, it is available for making a connection with a DBMS. &lt;br /&gt;________________________________________&lt;br /&gt;13. How can you make the connection?&lt;br /&gt;In establishing a connection is to have the appropriate driver connect to the DBMS. The following line of code illustrates the general idea: &lt;br /&gt;E.g.&lt;br /&gt;String url = "jdbc:odbc:Fred";&lt;br /&gt;Connection con = DriverManager.getConnection(url, "Fernanda", "J8");&lt;br /&gt;________________________________________&lt;br /&gt;14. How can you create JDBC statements?&lt;br /&gt;A Statement object is what sends your SQL statement to the DBMS. You simply create a Statement object and then execute it, supplying the appropriate execute method with the SQL statement you want to send. For a SELECT statement, the method to use is executeQuery. For statements that create or modify tables, the method to use is executeUpdate. E.g. It takes an instance of an active connection to create a Statement object. In the following example, we use our Connection object con to create the Statement object stmt : &lt;br /&gt;Statement stmt = con.createStatement();&lt;br /&gt;________________________________________&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-6868804674620522673?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/6868804674620522673/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=6868804674620522673' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/6868804674620522673'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/6868804674620522673'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/jdbc-interview-questions-part1.html' title='Jdbc Interview Questions Part1'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-1640006648780083186</id><published>2007-10-25T11:09:00.001-07:00</published><updated>2007-10-25T11:09:32.402-07:00</updated><title type='text'>Jdbc Interview Questions</title><content type='html'>1. What is JDBC?&lt;br /&gt;JDBC may stand for Java Database Connectivity. It is also a trade mark. JDBC is a layer of abstraction that allows users to choose between databases. It allows you to change to a different database engine and to write to a single API. JDBC allows you to write database applications in Java without having to concern yourself with the underlying details of a particular database. &lt;br /&gt;________________________________________&lt;br /&gt;2. What are the two major components of JDBC?&lt;br /&gt;One implementation interface for database manufacturers, the other implementation interface for application and applet writers. &lt;br /&gt;________________________________________&lt;br /&gt;3. What is JDBC Driver interface?&lt;br /&gt;The JDBC Driver interface provides vendor-specific implementations of the abstract classes provided by the JDBC API. Each vendors driver must provide implementations of the java.sql.Connection,Statement,PreparedStatement, CallableStatement, ResultSet and Driver. &lt;br /&gt;________________________________________&lt;br /&gt;4. What are the common tasks of JDBC?&lt;br /&gt;o Create an instance of a JDBC driver or load JDBC drivers through jdbc.drivers&lt;br /&gt;o Register a driver&lt;br /&gt;o Specify a database&lt;br /&gt;o Open a database connection&lt;br /&gt;o Submit a query&lt;br /&gt;o Receive results&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-1640006648780083186?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/1640006648780083186/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=1640006648780083186' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/1640006648780083186'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/1640006648780083186'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/jdbc-interview-questions.html' title='Jdbc Interview Questions'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-7469482898871253828</id><published>2007-10-25T11:05:00.000-07:00</published><updated>2007-10-25T11:06:13.020-07:00</updated><title type='text'>java Servelet Exampel</title><content type='html'>Java Servlets&lt;br /&gt;     Java Servlets are server side components that provides a powerful mechanism for developing server side of web application. Earlier CGI was developed to provide server side capabilities to the web applications. Although CGI played a major role in the explosion of the Internet, its performance, scalability and reusability issues make it less than optimal solutions. Java Servlets changes all that. Built from ground up using Sun's write once run anywhere technology java servlets provide excellent framework for server side processing. &lt;br /&gt;   With Java servlets web developers can create fast and efficient server side application   and can run it on any Servlet enabled web server. Servlets runs entirely inside the Java Virtual Machine. Because the Servlet is running on the server side, it does not depend on browser compatibility. I just sends the result in html formats.&lt;br /&gt;    Java Servlets have a number of advantages over CGI and other API's. They are: &lt;br /&gt;1. Platform Independence&lt;br /&gt;Java Servlets are 100% pure Java, so it is platform independence. It can run on any Servlet enabled web server. For example if you develop an web application in windows machine running Java web server. You can easily run the same on apache web server (if Apache Serve is installed) without modification or compilation of code. Platform independency of servlets provide a great advantages over alternatives of servlets.&lt;br /&gt;2. Performance&lt;br /&gt;Due to interpreted nature of java, programs written in java are slow. But the java servlets runs very fast. These are due to the way servlets run on web server. For any program initialization takes significant amount of time. But in case of servlets initialization takes place very first time it receives a request and remains in memory till times out or server shut downs. After servlet is loaded, to handle a new request it simply creates a new thread and runs service method of servlet. In comparison to traditional CGI scripts which creates a new process to serve the request. This intuitive method of servlets could be use to develop high speed data driven web sites.&lt;br /&gt;3. Extensibility&lt;br /&gt;Java Servlets are developed in java which is robust, well-designed and object oriented language which can be extended or polymorphed into new objects. So the java servlets takes all these advantages and can be extended from existing class the provide the ideal solutions.&lt;br /&gt;4. Safety&lt;br /&gt;Java provides a very good safety features like memory management, exception handling etc. Servlets inherits all these features and emerged as a very powerful web server extension.&lt;br /&gt;5. Secure&lt;br /&gt;Servlets are server side components, so it inherits the security provided by the web server. Servlets are also benefited with Java Security Manager.&lt;br /&gt;Java Servlet API Java Servlet API contains two core packages: &lt;br /&gt;• javax.servlet&lt;br /&gt;• javax.servlet.http&lt;br /&gt;     Servlets implement the javax.servlet.Servlet interface. The javax.servlet package contains the generic interfaces and classes that are implemented and extended by all servlets. While the javax.servlet.http package contains the classes that are used when developing HTTP - specific servlets. The HttpServlet is extended from GenericServlet base class and it implements the Servlet interface. HttpServlet class provides a framework for handling the HTTP requests.&lt;br /&gt;The  javax.servlet.Servlet defines five methods: &lt;br /&gt;1. service() metho called by servlet to handle the client request in a new thead. service() methos accepts ServletRequest and a ServletResponse ohjects as parameters. ServletRequest object represents the client request. It contains the data sent in name/value pairs. ServletResponse object is used to send the response to the client.&lt;br /&gt;2. init() is called once when servlet is loaded. It is a good place to initialize global variables. This methos accepts ServletConfig as parameter which provides initialization arguments for the servlet.&lt;br /&gt;3. getServletConfig() returns the ServletConfig object passed to init().&lt;br /&gt;4. destory() is called when wervlet is unloaded from memory. This is a good place to clean up any resources(such as open files or database connections).&lt;br /&gt;5. getServletInfo() returns a string with version, copyright informations etc.&lt;br /&gt;  &lt;br /&gt;Installing Servlets       The servlet run inside a Web Server program. After it has been compiled, it must be installed onto Web Server in order to test it. Thus we have to follow the following steps: &lt;br /&gt;1. Install the servlet in a hosting server&lt;br /&gt;2. Request the servlet through web browser.&lt;br /&gt;Java servlets are supported by a number of web servers. Java Web Server from JavaSoft was first servlet enabled web server. Now a days a number of web server supports java servlets. In this article we will use Java Web Server, whose evaluation copy can be downloaded from http://jserv.javasoft.com . In order to compile your servlet you also need Java Servlet Development Kit (JSDK) which is available at same place.&lt;br /&gt; &lt;br /&gt;Installing on Windows95 and Win NT       &lt;br /&gt;1. Download the distribution of Java Web Server from http://www.javasoft.com/products . Distribution is in the form of self-extracting file.&lt;br /&gt;2. The Java Web Server can be installed in any directory, so you can choose your favorite directory for installation. Move the downloaded file into your favorite directory.&lt;br /&gt;3. To begin the installation just double-click on the self-extracting file and the file extract itself and then installation begins.&lt;br /&gt;4. Follow the instruction and complete the installation.&lt;br /&gt;To run the Web Server go to your installation directory and then to bin directory and then double click httpd.exe. To test the Web Server open your browser and type http://localhost:8080 in address bar and then press enter. Browser should display default index.html into browser.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4138177214764955465-7469482898871253828?l=interview-questions-and-answers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://interview-questions-and-answers.blogspot.com/feeds/7469482898871253828/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4138177214764955465&amp;postID=7469482898871253828' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7469482898871253828'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4138177214764955465/posts/default/7469482898871253828'/><link rel='alternate' type='text/html' href='http://interview-questions-and-answers.blogspot.com/2007/10/java-servelet-exampel.html' title='java Servelet Exampel'/><author><name>ctsasikumar</name><uri>http://www.blogger.com/profile/09008676046546971317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4138177214764955465.post-3408712028660273233</id><published>2007-10-25T11:04:00.000-07:00</published><updated>2007-10-25T11:05:05.860-07:00</updated><title type='text'>Jsp example</title><content type='html'>Java Server Pages or JSP for short is Sun's solution for developing dynamic web sites. JSP provide excellent server side scripting support for creating database driven web applications. JSP enable the developers to directly insert java code into jsp file, this makes the development process very simple and its maintenance also becomes very easy.  JSP pages are efficient, it loads into the web servers memory  on receiving the request very first time and the subsequent calls are served within a very short period of time.  &lt;br /&gt;    In today's environment most web sites servers dynamic pages based on user request. Database is very convenient way to store the data of users and other things. JDBC provide excellent database connectivity in heterogeneous database environment. Using JSP and JDBC its very easy to develop database driven web application. &lt;br /&gt;   Java is known for its characteristic of "write once, run anywhere." JSP pages are platform independent. Your port your .jsp pages to any platform.     &lt;br /&gt;            Installing JSP&lt;br /&gt;&lt;br /&gt;            First of all download JavaServer Web Development Kit (JSWDK1.0.1) from http://java.sun.com/products/servlet/download.html. JSWDK comes with full documentation and it's very easy to install, so the installation process is not mentioned here. The JSWDK is the official reference implementation of the servlet 2.1 and JSP 1.0 specifications. It is used as a small stand-alone server for testing servlets and JSP pages before they are deployed to a full Web server that supports these technologies. It is free and reliable, but takes quite a bit of effort to install and configure. &lt;br /&gt;Other Servers that support JSP&lt;br /&gt;      Apache Tomcat.&lt;br /&gt;Tomcat is the official reference implementation of the servlet 2.2 and JSP 1.1 specifications. It can be used as a small stand-alone server for testing servlets and JSP pages, or can be integrated into the Apache Web server. &lt;br /&gt;• Allaire JRun.&lt;br /&gt;JRun is a servlet and JSP engine that can be plugged into Netscape Enterprise or FastTrack servers, IIS, Microsoft Personal Web Server, older versions of Apache, O’Reilly’s WebSite, or StarNine WebSTAR. &lt;br /&gt
