What is the difference between linear and binary search?

1 Answer

Answer :

A: Linear search does not require the array to be sorted, whereas, binary search requires that the array be sorted.

Linear search checks for the search item in a linear fashion from the beginning cell till the end, whereas, Binary search repeatedly dividing the array into halves and the search takes place in one of the halves. The element is searched in the middle cell of every half.

The Examiner may ask you to explain in brief the logic used you to solve the program.

You know what you have written so just give a brief summary of the logic used by
you.
The Examiner may ask you to tell what is control variable in your loop.
So if your loop is for(int i = 1; i <= 5; i++) then the control variable is ‘i’.
The Examiner may ask you to tell what is the return type of a function you used.
So if your function is boolean isPrime(int n) then the return type is ‘boolean’.

Related questions

Description : In ……………, search start at the beginning of the list and check every element in the list. A) Linear search B) Binary search C) Hash Search D) Binary Tree search

Last Answer : A) Linear search

Description : Let C be a binary linear code with minimum distance 2t + 1 then it can correct upto ............bits of error. (1) t + 1 (2) t (3) t - 2 (4) t/2

Last Answer : (2) t 

Description : When does Binary search fail?

Last Answer : A: When the array is not sorted.

Description : In general, the binary search method needs no more than ……………. comparisons. A) [log2n]-1 B) [logn]+1 C) [log2n] D) [log2n]+1

Last Answer : D) [log2n]+1

Description : State True or False. i) Binary search is used for searching in a sorted array. ii) The time complexity of binary search is O(logn). A) True, False B) False, True C) False, False D) True, True

Last Answer : D) True, True

Description : A binary search tree whose left subtree and right subtree differ in hight by at most 1 unit is called A) AVL tree B) Red-black tree C) Lemma tree D) None of the above

Last Answer : A) AVL tree

Description : Consider the following statements: (a) Depth - first search is used to traverse a rooted tree. (b) Pre - order, Post-order and Inorder are used to list the vertices of an ordered rooted tree. (c) Huffman's algorithm is used to find an optimal ... (d) (C) (a) , (b) and (c) (D) (a), (b) , (c) and (d)

Last Answer : (D) (a), (b) , (c) and (d)

Description : Suppose that we have numbers between 1 and 1000 in a binary search tree and want to search for the number 364. Which of the following sequences could not be the sequence of nodes examined? (A) 925, 221, 912, 245, 899, ... 926, 203, 912, 241, 913, 246, 364 (D) 3, 253, 402, 399, 331, 345, 398, 364 

Last Answer : (C) 926, 203, 912, 241, 913, 246, 364

Description : Consider the following binary search tree: If we remove the root node, which of the node from the left subtree will be the new root? (A) 11 (B) 12 (C) 13 (D) 16

Last Answer : (D) 16

Description : The runtime for traversing all the nodes of a binary search tree with n nodes and printing them in an order is (A) O(lg n) (B) O(n lg n) (C) O(n) (D) O(n2 ) 

Last Answer : (C) O(n) 

Description : Which of the following statements is false? (A) Optimal binary search tree construction can be performed efficiently using dynamic programming. (B) Breadth-first search cannot be used to find connected components of a graph. (C) ... used to find the components of a graph. (1) A (2) B (3) C (4) D 

Last Answer : Answer: 2

Description : The average case occurs in the Linear Search Algorithm when: (A) The item to be searched is in some where middle of the Array (B) The item to be searched is not in the array (C) The item to be searched is in the last of the array (D) The item to be searched is either in the last or not in the array

Last Answer : (A) The item to be searched is in some where middle of the Array

Description : The command javac A) Converts a java program into binary code B) Converts a java program into bytecode C) Converts a java program into machine language D) None of the above.

Last Answer : B) Converts a java program into bytecode

Description : State True or False. i) While overloading operators new operator can be overloaded. ii) The binary operator such as +, -, * and must explicitly return a value. A) True, True B) True, False C) False, True D) False, False

Last Answer : C) False, True

Description : State true or false. i) An empty tree is also a binary tree. ii) In strictly binary tree, the outdegree of every node is either o or 2. A) True, False B) False, True C) True, True D) False, False

Last Answer : C) True, True

Description : ………………. Is a directed tree in which outdegree of each node is less than or equal to two. A) Unary tree B) Binary tree C) Dinary tree D) Both B and C

Last Answer : B) Binary tree

Description : The property of binary tree is A) The first subset is called left subtree B) The second subtree is called right subtree C) The root cannot contain NULL D) The right subtree can be empty

Last Answer : D) The right subtree can be empty

Description : Which of the following is not a binary operator in relational algebra? A) Join B) Semi-Join C) Assignment D) Project

Last Answer : D) Project

Description : Binary code "0" means ............ A) State of absence B) State of presence C) State of Negative D) State of Positive

Last Answer : B) State of presence

Description : What is a relationship called when it is maintained between two entities? (A) Unary (B) Binary (C) Ternary (D) Quaternary

Last Answer : (B) Binary

Description : Cartesian product in relational algebra is (A) a Unary operator. (B) a Binary operator. (C) a Ternary operator. (D) not defined.

Last Answer : (B) a Binary operator.

Description : The number of distinct binary images which can be generated from a given binary image of right M × N are (A) M + N (B) M × N (C) 2M + N (D) 2MN

Last Answer : (D) 2MN

Description : Binary symmetric channel uses (A) Half duplex protocol (B) Full duplex protocol (C) Bit oriented protocol (D) None of the above

Last Answer : (A) Half duplex protocol

Description : Which one of the following is decimal value of a signed binary number 1101010, if it is in 2's complement form? (A) -42 (B) - 22 (C) -21 (D) -106

Last Answer : (B) - 22

Description : Active X controls are Pentium binary programs that can be embedded in ............... (A) Word pages (B) URL pages (C) Script pages (D) Web pages

Last Answer : (D) Web pages

Description : A full binary tree with n leaves contains (A) n nodes (B) log2 n nodes (C) 2n –1 nodes (D) 2n nodes

Last Answer : (C) 2n –1 nodes 

Description : The Excess-3 decimal code is a self-complementing code because (A) The binary sum of a code and its 9’s complement is equal to 9. (B) It is a weighted code. (C) Complement can be generated by inverting each bit pattern. (D) The binary sum of a code and its 10’s complement is equal to 9.

Last Answer : Answer: A, C

Description : In a binary Hamming code the number of check digits is r then number of message digits is equal to: (A) 2r-1 (B) 2r-r-1 (C) 2r-r+1 (D) 2r+r-1

Last Answer : (B) 2r-r-1

Description : The inorder and preorder Traversal of binary Tree are dbeafcg and abdecfg respectively. The post-order Traversal is ............ (A) dbefacg (B) debfagc (C) dbefcga (D) debfgca

Last Answer : (D) debfgca

Description : Which one of the following array represents a binary max-heap? (A) [26, 13, 17, 14, 11, 9, 15] (B) [26, 15, 14, 17, 11, 9, 13] (C) [26, 15, 17, 14, 11, 9, 13] (D) [26, 15, 13, 14, 11, 9, 17]

Last Answer : (C) [26, 15, 17, 14, 11, 9, 13]

Description : The number of different binary trees with 6 nodes is ............. (A) 6 (B) 42 (C) 132 (D) 256

Last Answer : (C) 132

Description : Suppose you are given a binary tree with n nodes, such that each node has exactly either zero or two children. The maximum height of the tree will be (A) n/2 - 1 (B) n/2 + 1 (C) (n-1)/2 (D) (n+1)/2

Last Answer : (C) (n-1)/2

Description : If X is a binary number which is power of 2, then the value of X&(X-1) is: (1) 11....11 (2) 00.....00 (3) 100.....0 (4) 000.....1

Last Answer : Answer: 2

Description : ………………. is not an operation performed on linear list Get More Mcqs from http://www.siteforinfotech.com/p/mcqs.html a) Insertion b) Deletion c) Retrieval d) Traversal A) only a,b and c B) only a and b C) All of the above D) None of the above

Last Answer : D) None of the above

Description : An artificial neurons receives n inputs x1, x2,...,xn with weights w1,w2,...,wn attached to the input links. The weighted sum ............... is computed to be passed on to a non-linear filter ϕ called activation function to release the output. (A) Σ wi (B) Σ xi (C) Σ wi + Σ xi (D) Σ wi . Σ xi

Last Answer : (D) Σ wi . Σ xi

Description : If the primal Linear Programming problem has unbounded solution, then it’s dual problem will have (A) feasible solution (B) alternative solution (C) no feasible solution at all (D) no bounded solution at all 

Last Answer : (C) no feasible solution at all

Description : A basic feasible solution of a linear programming problem is said to be ............... if at least one of the basic variable is zero. (A) degenerate (B) non-degenerate (C) infeasible (D) unbounded

Last Answer : (A) degenerate 

Description : The region of feasible solution of a linear programming problem has a ............... property in geometry, provided the feasible solution of the problem exists. (A) concavity (B) convexity (C) quadratic (D) polyhedron

Last Answer : (B) convexity

Description : A t-error correcting q-nary linear code must satisfy:  Where M is the number of code words and X is (1) qn (2) qt (3) q-n (4) q-t

Last Answer : (1) qn 

Description : Given the following two statements: A. L = {w|na(w) = nb(w)} is deterministic context free language, but not linear B. L = {an bn} U {an b2n} is linear, but not deterministic context free language. Which of the following ... are true. (3) (A) is true, (B) is false. (4) (A) is false, (B) is true.

Last Answer : Both (A) and (B) are true. 

Description : The number of comparisons done by sequential search is ……………… A) (N/2)+1 B) (N+1)/2 C) (N-1)/2 D) (N+2)/2

Last Answer : B) (N+1)/2

Description : Match the following. a) Completeness i) How long does it take to find a solution b) Time Complexity ii) How much memory need to perform the search. c) Space Complexity iii) Is the strategy guaranteed to find the solution when there in ... , b-ii, c-iii C) a-iii, b-i, c-ii D) a-i, b-iii, c-ii

Last Answer : C) a-iii, b-i, c-ii

Description : ……………..specifies a search condition for a group or an aggregate. A) GROUP BY Clause B) HAVING Clause C) FROM Clause D) WHERE Clause

Last Answer : B) HAVING Clause

Description : The ..................... is essentially used to search for patterns in target string. A) Like Predicate B) Null Predicate C) In Predicate D) Out Predicate

Last Answer : A) Like Predicate

Description : …………….. is the complex search criteria in the where clause. A) Substring B) Drop Table C) Predict D) Predicate

Last Answer : D) Predicate

Description : The map colouring problem can be solved using which of the following technique? (A) Means-end analysis (B) Constraint satisfaction (C) AO* search (D) Breadth first search

Last Answer : (B) Constraint satisfaction

Description : Which one of the following is not an informed search technique? (A) Hill climbing search (B) Best first search (C) A* search (D) Depth first search

Last Answer : (D) Depth first search

Description : Given an open address hash table with load factor a < 1, the expected number of probes in a successful search is (A) Atmost 1/α ln (1-α/α) (B) Atmost 1/α ln (1/1-α) (C) Atleast 1/α ln (1/1-α) (D) Atleast 1/α ln (α/1-α)

Last Answer : (B) Atmost 1/α ln (1/1-α)

Description : In alpha-beta pruning, ............... is used to cut off the search at maximizing level only and ................. is used to cut off the search at minimizing level only. (A) alpha, beta (B) beta, alpha (C) alpha, alpha (D) beta, beta

Last Answer : (B) beta, alpha