Interview and Exam Questions and Answers
This set contains a list of commonly asked questions. They are short interview questions aimed at freshers interview, campus placement drives, and also for job interviews. You can use these to have a quick grasp and brush-up of your fundamentals. These questions can be viewed on a mobile phone also because this website is built on responsive web design.
In binary search algorithm, after every search operation, the search gets reduced by ______?
In binary search algorithm, after every search operation, the search gets reduced by 1/4.
What are steps for "in order" traversing a binary tree?
The steps for in order traversing a binary tree are as follows:
- Traverse the left subtree
- Visit the root
- Traverse the right subtree
How can we rewrite the Selection Sort algorithm so that it sorts numbers from highest to lowest?
To modify the Selection Sort Algorithm so that it sorts from highest to lowest, we need to search for the largest card rather than the smallest. The modifications to the original algorithm are marked in italics.
- Get a list of unsorted numbers
- Set a marker for the unsorted section at the front of the list
- Repeat steps 4 through 7 until one number remains in the unsorted section
- Compare all unsorted numbers
- Select the largest unsorted number
- Swap this number with the first number in the unsorted
- Advance the marker to the right one position
Is selection sort having same efficiency as bubble sort?
Yes, both have same efficiency order of growth.
How do you define binary search?
A binary search or half-interval search finds the position of a specified value (the input "key") within a sorted array. Binary search is applied only on the list which is sorted and if the list to be searched is not sorted, it needs to be sorted before binary search can be applied to it.
Write an algorithm to delete a node from a binary search tree.
The following algorithm to locate the node to be deleted and its parent:
- Make a variable/pointer currentNode point to the ROOT node.
- Make a variable/pointer parent point to NULL.
- Repeat steps a,b, and c until currentNode becomes NULL or the value of the node to be searched becomes equal to that of currentNode:
- Make parent point to currentNode.
- If the value to be deleted is less than tht of currentNode:
- Make currentNode point to its left child.
- If the value to be deleted is greater than that of currentNode:
- Make currentNode point to its right child.
What are the various applications of linear search?
Linear search is usually very simple to implement, and is practical when the list has only a few elements, or when performing a single search in an unordered list. When many values have to be searched in the same list, it often pays to pre-process the latter in order to use a faster method.
Bubble sort is used for large or small list.Bubble sort is used for small list.
Write algorithm for inserting node at end of Singly-Linked list, if list is not empty .
To insert a node at the and of the linked list algorithm is:
- Allocate memory for the new node.
- Assign value to the data field of the new node.
- If START is NULL,then:
- Make START point to the new node.
- Go to step 6.
- Locate the last node in the list, and mark it as currentNode.To locate the last node in the list,execute the following steps:
- Mark the first node as currentNode.
- Repeat step c until the successor of currentNode becomes NULL.
- Make currentNode point to the next node in sequence.
- Make the next field of currentNode point to the new node.
- Make the next field of the new node point to NULL.
Write an algorithm to convert a binary tree into heap.
The following algorithm to convert a binary tree into heap:
- Set i=(n-1)/2
- Set j=2i+1
- Let heap=False
- Compare the value at index j with the value of its sibling at index j+1:
- If A[j+1]>A[j]:
- If A[j]>A[(j-1)/2]:
- If((n>j) or(heap=False)),repeat step 4,5, and 6
- Decrement i by 1
- If(i>=),repeat steps 2 through 8
Swap A[j] with A[(j-1)/2
My C/C++ Videos on Youtube
Here is the complete playlist for video lectures and tutorials for the absolute beginners. The language has been kept simple so that anybody can easily understand them. I have avoided complex jargon in these videos.