P. 1
Sas

Sas

|Views: 142|Likes:
Published by b4pb4p

More info:

Published by: b4pb4p on Apr 30, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

08/22/2012

pdf

text

original

Câu hỏi Ôn Tập Quarter 4

1. What types of values are stored in a node of a doubly-linked list? a. Only dada contained in the node b. Address of the succeeding node only along with some data c. Address of the preceding node only along with some data d. Address of the preceding and succeeding node with some data 2. Which of the following is an example of a recursive function? a. f(n) = 0 where n >1; and f(1) =1 b. f(n +1) = n where n >1; and f(1) =1 c. f(n) = n where n >1; and f(1) =1 d. f(n) = f(n - 1) +n where n >1; and f(1) =1 3. In a binary tree, a node with no children is call a……….. a. Subtree b. Parent node c. Internal node d. Leaf node 4. Which of the following is NOT correct about assertion? a. Assertions are a way to test certain assumtions about the logic of a program b. Assertions occupy space in class file and increases the download time c. Assertions describe how to hanle unexpected errors d. Assertions can be enabled during program development 5. Which of the following is a condition for queue overflow? a. FRONT = 1 and REAR = last index position b. FRONT = REAR c. FRONT = 0 and REAR = last index position d. FRONT = 0 and REAR = first index position 6. Which of the following method will you call to set the size of a Frame ? a. Pack() b. setVisible() c. setSize() d. setLayout()
Good Luck Page 1

Identify the correct algorithm that would enable Henry to insert values at the end of the linked list. 1. Make the next field of LAST point to the new node 5. Make the next field of LAST point to the new node 5. a. Make LAST point to the new node c. Alloacte memory for the new node 2. Make LAST point to NULL c. According to the requirement. to keep track of the first and the last nodes in the list. then: a. Assign value to the data field of the new node 3. Henry has to write a program to store and display a list of prime numbers in a singly-linked list. 1. START and LAST. Mark the new node as START 6. Assign value to the data field of the new node 3. then: a. Therefore Hanry decides to use two variables. Alloacte memory for the new node 2. 1. 1.7. Assign value to the data field of the new node 3. Assign value to the data field of the new node 3. Alloacte memory for the new node 2. Make the next field of the new node point to NULL c. Make the next field of the new node point to NULL b. Go to step 6 Good Luck Page 2 . the insert operation always need to be done at the end of the list. Alloacte memory for the new node 2. Make LAST point to the new node c. Make START point to the new node b. If START is NULL. then: a. Make LAST point to the new node c. If START is NULL. Make START point to the new node b. then: a. If START is NULL. Make START point to the new node b. Make START point to the new node b. If START is NULL. Make the next field of START point to the new node 5. Go to step 6 4. Mark the new node as LAST 6. Mark the new node as LAST Make the next field of the new node point to NULL d. Go to step 6 4. Go to step 6 4.

i<agrs.out. Linked List c. } catch(NumberFormatException nfe){ System. Mark the new node as LAST 5. b.out. The code complies successfully and displays The total is 0 d. c. newThread = new Thread (this.parseInt(agrs[i]). 9. for(int i =0. The code complies successfully and displays an error message Incorrect argument c. The code complies successfully and displays The total is 4. a. d.i++){ total += Integer.4.two. Thread newThread = Thread (“threadName”). Make the next field of the new node point to NULL 8.println("Incorrect argument"). Thread newThread = new Thread (this. Consider the following code: public class Calculate { public static void main(String [] agrs){ try{ int total =0. Identify the correct syntax used to instantiate the Thread class. <Keyboard buffering is an application of which the following data structures? a. Queues b. } } } What will be the output of the iven code when the program is run with argument 1.length.”threadName”). The code givens a compilation error. and 3? a.”threadName”).println("Total is " + total). Stacks Good Luck Page 3 . Thread newThread = new(this). Make the next field of LAST point to the new node 6. b. } System. 8. Trees d.

A class Shape has a method draw(). release the memory for currentNode c. 1. Const c. 3.Make the right child field of parent as a thread pointing to the inorder successor of currentNode. What will you do to force the subclasses to override the draw() method? a. New d. Square.10. 3. and Circle should implement the Shape Class. Consider the following statements on threads: Good Luck Page 4 . Square.Make the left child field of parent as a thread pointing to the inorder predecessor of currentNode. the parent in this case is not the header node) a. Set the left thread field of parent as zero 2. Long b. and circle should extend the Shape Class. 1. and Circle should implement the Shape Class. d. Three classes. c. 1. 3. Specfy draw() as abstract and Rectangle. Specfy Shape as final and Rectangle. Set the left thread field of parent as zero 2. 1. Set the left thread field of parent as zero 2. Specfy draw() as an interface and Rectangle.Make the left child field of parent as a thread pointing to the inorder predecessor of currentNode. 3. Square.What is the correct algorithm to delete a leat node from a threaded birary tree if the node to be delected is the left child of its parent? (Assume that the node to be deleted is marked as currentNode and its parent is marked as parent. Release the memory for currentNode 13. 12. Square. Set the left thread field of parent as zero 2. Square. Specfy Shape as an interface and Rectangle. b. Rectangle. Release the memory for currentNode d.Which of the following is a valid java identifier? a. and circle should extend the Shape Class. Also.Make the right child field of parent as a thread pointing to the inorder successor of currentNode. and Circle will be derived from the Shape class. release the memory for currentNode b. $const 11.

println(4). Statement A is false while Statement B is true c.out. case 1: system. break. case 3: system. Both Statement A and Statement B are false b.out.println(1). 10 1 2 3 b. a. 10 1 2 d.Statement A: You can create a new thread by extending the Thread class Statement B: You can create a new thread by implementing the Runnable interface Select the correct option for the preceding staterents. 1 2 Good Luck Page 5 } . } } What is the output of given code? a.out.out.prinln(3).println(10). case 2: system.out. 10 1 2 3 4 c. if(x>15)x=1.Consider the code: public class TestSwitch{ public static void main(String args[]){ int x = 10. Statement A is true while Statement B is false 13.println(2). default: system. Both Statement A and Statement B are true d. switch(x){ case 10: system. break.

As a part of the development team. point to the new node //Front keeps track of the element that was inserted first Good Luck Page 6 . Class A has a method defined as accessMe(). Front. point to the new node //Front keeps track of the element that was inserted first • Make a variable/ pointed. if the list is empty execute the following steps: • Make a variable/pointer. Protected friend b. What is the access specifier defined to accessMe() method? a.Sam works as a techical support officer in BlueMoon Inc. Protected d. Class X is with n the sme package as Class A where as class Y is in some other package. Make the next field of REAR point to the new node 6. Allocate memory for the new node. Allocate memory for the new node. you are assigned a task to solve this problem by writing an appropriate algorithmn to store the queries in the form of a singly-linked lit. This node would represent a new query 2.related queries on daily basis. The method accessMe() is accessible to class X but not to class Y. which need to be manaced in such a way so that the query that comes firs should be solved first. Rear. point to the new node// Rear keeps track of the element that was inserted last • Exit 5. if the list is empty execute the following steps: • Make a variable/pointer. 1. Make the next field of the rew node point to Null 4. Front. Make the next field of the new node point to Null 4.14. Make FRONT point to the new node b. Private 15. Assign value to the data field of the new node 3. Assign value to the data field of the new node 3.Class X and Y are the sub classes of class A. I receives a lot of hardware. Friendly c. a. This node would represent a new query 2. 1. The algorithm should store the incoming queries in such a way so that the quer. which should be implement to accomplish this task.

io. Make FRONT point to the new node 16.read())!= -1){ out.FileInputStream. import java.txt"). public class Example { public static void main (String [] args)throws IOException{ FileInputStream in = null. while((c=in.• Make a variable/ pointed.IOException. point to the new node //Front keeps track of the element that was inserted first • Make a variable/ pointed. if the list is empty execute the following steps: • Make a variable/pointer. try{ in = new FileInputStream("OutputFile. } } finally{ if(in != null){ Good Luck Page 7 .write(c). Make the next field of the rew node point to Null 4. FileOutputStream out = null.Consider the following code: import java.txt"). import java. Allocate memory for the new node. This node would represent a new query 2. Assign value to the data field of the new node 3.io. Make the next field of FRONT point to the new node 6. Make REAR point to the new node c. Front. point to the new node// Rear keeps track of the element that was inserted last • Exit 5.FileOutputStream. Rear. Make the next field of REAR point to the new node 6.io. int c. Rear. out = new FileOutputStream("InputFile. point to the new node// Rear keeps track of the element that was inserted last • Exit 5. 1.

and display the word Hello? a. The code will copy the content of the InpuText.txt file 17. Both the Statement are False 19. Statement A is True and Statement B is False b. } if(out != null){ out. Both the Statement are True c.txt file to the OutputText.txt file d. The code will copy the content of the OutputFile. Assuming the base address to be 10 and the size of an element to be 2.Consider the following statements: Statement A: An Error class is derived from an Exception class Statement B: Error class is used for VirtualMachineError Which of the following options is true with respect to above statement? a. The code will throw a runtime exception c. 280 d. Statement A is False and Statement B is True d.txt file to the InputFile.close(). 92 c. } } What will be the output of the above? a.close(). 29 b. 28 18. Which of the following code will compile. a. Jim wants to calculate the address of an element stored at 9th position in an array. The code will execute without any output b.} } in. public class Example{ public static void main(String args[]){ Good Luck Page 8 . calculate the address of an element stored 9th position in an array. execute.

If (str1 == str2){ System. String str2 =”Hello”.equals(str2)){ System. If (str1 == str2){ String str2 = new String(“Hello”).println(“Hello”). boolean Page 9 Good Luck . String str2 =”Hello”.println(“Hello”). if(num1 == num2){ System. public class Example{ public static void main(String args[]){ String str1 =”Hello”.println(“Hello”). } } } c. } } } b.out. public class Example{ public static void main(String args[]){ int num1.String str1 =”hello”.out. int num2.println(“Hello”).out. public class Example{ public static void main(String args[]){ String str1 =”Hello”. } } } 20. If (str1. System.Which option shows the allowed data type of a variable in the swith-case construct? a. String str2 =”Hello”. } } } d.out.

FocusEvent 26. A and B. 7 c. AWTEvent c.Conisder the following statements: Statement A: A List can contain duplicate elements Statement B: A Set contains unique elements Which of the following is True. 8 d. How many edges are therer in this binary tree? a. with respect to the above Statement? a. java<filename>. ActionEvent d. Constant c.java Good Luck Page 10 b. then the algorithm has a _____ order of growth. Both. Bubble Sort c.Which of the Statement is used to run a java code? a. java<filename> c. c. if the list to be sorted is small in size and is nearly sorted? a. 6 23. javac<filename>. a. d. are True b. Logarthmic 25. Statement A is False and Statement B is True. 24. are True d. A and B. Log Linear b. Statement. Statement A is True and Statement B is False c. If an algorithm is of the order of O (log n). Statement. Both. 9 b. Selection Sort 22._______is the immediate superclass of the MouseEvent class a. Which of the following sorting techniques will use. byte double .Consider a binary tree consisting of 8 nodes. Insertion Sort b. InputEvent b. Exponential d.java b. Quick Sort d.Float 21.

f. javac<filename> 27. and moving the item to its corresposition in the list 28. comparing adjacent elements. Its works by scanning through the list iteratively.Which of the following hold true for quick sort algorithm? a. MenuBar m1 = new MenuBar(). Circular linked list is a dyamic data structure in which each node points to the next node in its sequence as well as its preceding node.What is a circular linked list? a. with respect to the above Statements? a. Circular linked list is a static data structure in which each node points to the next node in sequence and the last node points NULL Good Luck Page 11 . The code will add an action listener to the menu bar d. It works by selecting an element from the list called a pivod and then partitioning the list into parts that’s may or may not be equal c. Statement A is True and Statement B is False b. and the last node points to NULL. The code will add an action listener to only the menu bar and the File menu 30. are True d. and swapping them if they are in the wrong order. and then the two sublists are sorted separately b.Consider the following statements: Statement A: Keywords are always written in uppercase in java Statement B: Keywords cannot be used as variable names. M1.selecting one item in each scan.setMenuBar(m1).add(menu1). It works by dividing the list into two sublist of sizes as naerly equal as possible. b. Statement. A and B. Both. select the correct option regarding the preceding code. Menu1. The code will add an action listener to the frame c. d. a.Consider the following code. It works by repertedly scanning through the list.d. Both. Which of the following is true. The code will add an action listener to both the menu bar and the File menu b. are False c. Statement A is False and Statement B is True 29. Statement. where MyListener is a listener class of action events: Frame f = new Frame(“Frame”).addActionListener(new MyListener). A and B. Menu menu1 = new Menu(“File”).

the nodes are displayed in the following sequence: DFEBCA Analyze the tree by clicking the Exhibit button and identify the algorithm that Sam must have used to traverse the tree. HashSet 32.add(“Alps”).util. d. 10 33. Arraylist c. obj.c. obj.out. Order(right child of root) 4. Exit 2.After traversal. 9 c. HashSetMap b. Circular linked list is a dyamic data structure in which each node points to the next node in sequence and the last node points to NULL.Sam is assigned a task to write code for travaersing a tree. 31.Consider the following code: import java. public class Example{ public static void main(String [] args) { <Class Name> obj= new <Class Name>(). If (root = NULL) a.*. Visit(root) 3. 45 b. Algorith:order(root) 1. Circular linked list is a dyamic data structure in which each node points to the next node in sequence and the last node points to the first node in the list.add(“Alps”). System. } } Which of the following class will you use in the place of <Class Name> to execute the program with the following output:[Aplas] a. 55 d. Order(left child of root) Good Luck Page 12 . LinkedList d.println(obj). a.How many comparisons are required to sort an array of 10 element by using selection sort? a.

Consider the following code: public class CurrentThread { public static void main(String [] args){ Thread thisThread = Thread.sleep(1000). Thread. Algorith:order(root) 1.If (root = NULL) a.b. try { for (int counter =0.out.Visit(root) d.Order(left child of root) 3. } } } What will be the output of the given code? a.Order(right child of root) c.If (root = NULL) a.Exit 2. } } catch(InterruptedException e){ System.Visit(root) 3. Visit(root) 4.currentThread(). The code compiles successfully but does not display any output b.Order(left child of root) 4.println("Thread interrupted").Exit 2.counter<10.If (root = NULL) a.counter +=2) { System.Order(left child of root) 3.print(" " + counter ).Order(right child of root) 4. Algorith:order(root) 1. The code gives a compilayion error Good Luck Page 13 . Order(right child of root) 34.Exit 2. Algorith:order(root) 1.out.

If i>n: Display”Not Found” Else Display” Found” Good Luck Page 14 . Accept the value to be searched 2.John has been assign a task to write code to implement a search operation on a list of elements for locating a particular value.c. Repeat step 4 until arr[i] = value to be searched 4. Increment i by 1 5. set i= 1 3. Repeat step 4 until i =n or arr[i] > value to be searched 4. set i= 0 3. Repeat step 4 until i>n or arr[i] = value to be searched 4. 1. set i= 0 3. Increment i by 1 5. 0123456789 d. 02468 35. Increment i by 1 5. Accept the value to be searched 2. set i= 0 3. 1. He decides to implement linear search.Identify the correct algorithm that would enable John to accomplish his task. Accept the value to be searched 2.If i>n: Display”Not Found” Else Display” Found” d. a. Accept the value to be searched 2.If i>n: Display”Not Found” Else Display” Found” b. Repeat step 4 until i>n or arr[i] = value to be searched 4. 1. 1.If i>n: Display”Not Found” Else Display” Found” c. Increment i by 1 5.

If the element at index j is greater than the element at index j +1. The algorithm will provide the desired output b. To accomplish this task.Consider the following algorithm to implement Bubble sort in ascending order on an array: 1. 38. Identify the problem in the preceding algorithm. he writes a code based on the following algorithm: Good Luck Page 15 .Jim is assigned a task to develop a code to display all the contents of a singly-linked list.36. The algorithm will not provide the desired output. the code does not give the desired output. Step II is incorrect. Increment pass by 1 5.Step 5 should be “If pass <= n go to step 2” c. The correct statement should be ‘Display the information contained in the successor of the node marked as currentNode’ 37. The sequence of steps III and IV is incorrect b. The correct statement should be ‘Repeat step III until the next field of currentNode becomes NULL’ c. a. If pass < n go to step 2 Identify whether the preceding algorithm will provide the desired result or not? Also suggest the correct solution in case of error a.Jim is assigned a task to develop a code to evaluate a postfix expression. The algorithm will not provide the desired output. The correct statement should be ‘Repeat step III and step IV until the next field of currentNode becomes NULL’ d. Step IV is incorrect.Step 3 should be “If the element at index j-1 is greater than the element at index j. The algorithm will not provide the desired output. Step II is incorrect. swap the two elements 4. Set pass=1 2. He developed the code arrording to the following algorithm: Step I: Make currentNode point to the first node in the list Step II: Repeat steps III and IV until currentNode becomes NULL Step III: Make currentNode point to the next node in sequence Step IV: Display the information contained in the node marked as currentNode However. swap the two elements” d. He decides to implement a stack for the same.Step 1 should be Set pass=0. Repeat step 3 varying j from 1 through n-pass 3.

Initialize the stack to be empty 2. Steps 2(a) is incorrect. If an operand infix is encountered. it should be pushed into the stack d. Scan the entries in the infix expression from left to right until the end of the infix expression is encountered: a. POP the top two values ii.in this step. it should be discarded… c. Sequence of Steps 2(a) and 2(b) is incorrect b. POP it from the stack b. If an operator is encountered: i. Operate the two values by using the operator iii. he does not get the desired result. if an operand is encountered. The stack should not be made empty Good Luck Page 16 .1. PUSH the result to the stack 3. if an operand is encountered. Identify the problem in the algorithm a. Get result from the top of the stack However. Steps 1is incorrect.In this step. Steps 2(a) is incorrect.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->