Quiz Dsa

Share Embed Donate


Short Description

Dsa...

Description

LINKED LIST Q 1: Which of sentences about singly linked list are true: a. On the average, delete operation executes O(n) steps. b. There is no immediate access to the predecessor of any node in list. c. Deleting a node at the beginning of the list takes constant time O(1). d. Search operation takes O(n) time in the best case. e. Deleting last node of the list always takes O(lgn) time.

Q 2: Which of the following operation in the doubly linked circular list can be done in O(1) time? (option) a. Deletion of the tail node b. Insertion of the tail node c. Insertion of a node to any position d. Deletion of any node

Q 3: Select correct statement(s) about Doubly Linked List: a. The node which is deleted from the list will be claimed by the garbage collector b. Inserting a new node at the end of the list requires O(n) steps c. Deleting a node at the end of the list takes constant time O(1) d. Methods for processing doubly linked list are simpler than those of singly linked list

Q 4: Suppose temp refers to a node in a linked list (using the SLLNode class with instance variables called info and next). What boolean expression will be true when temp refers to the tail node of the list? a. (temp == null) b. (temp.next == null) c. (temp.info == null) d. (temp.next != null)

Q 5: Consider the following statements: a. Every node of a singly linked list has two reference fields, one to the predecessor and one to the successor

1

b. Every node of a doubly linked list has two reference fields, one to the predecessor and one to the first node of the list Select one: a. a and b are true b. a is true and b is false c. a and b are false d. a is false and b is true

Q 6: Select the best choice about a linked structure Select one: a. Inserting a new element to it is efficiently b. Deleting an element from it is efficiently c. It needs more memory spaces for linking elements d. All of the others

Q 7: Consider the statements related to delete From Tail operation in the singly linked list: a. There is a only one special cases to consider: the list is empty b. Most time-consuming part of the operation is finding the next to last node Select one: a. a is true and b is false b. a is false and b is true c. a and b are true d. a and b are false

Q 8: Linked lists allow easy insertion and deletion of information because such operations have a local impact on the list. Select one: a. False b. True

2

Q 9: Which of the following operations always take O(1) time: Select one or more: a. Deleting one node from the begin of the doubly linked list b. Searching one node in singly linked list without tail in the best case. c. Deleting one any node in a doubly linked list. d. Inserting one node to the end of the singly linked list that has no tail.

STACK & QUEUE Q1: Specify the correct implementation of dequeue() method of a queue. This queue uses java.util.LinkedList, here is pool, for storing data and the head of the list is treated as the head of the queue. (Choose the most suitable one) Select one: a. Object dequeue () { if (isEmpty()) return; return (pool.remove(pool.size()-1)); } b. void dequeue (Object x) { if (isEmpty()) return(null); pool.remove(pool.size()-1); } c. Object dequeue () { if (isEmpty()) return(null); return (pool.removeLast()); } d. Object dequeue () { if (isEmpty()) return(null); return (pool.removeFirst()); }

Q 2: We implement the stack as a singly linked list and use AddtoHead() method of the linked list to implement push() method. A top pointer of the stack is… Select one: a. b. c. d.

Nothing. We need a doubly linked list. Any one reference. Depending on the node that is accessed. The tail reference of the singly linked list. The head reference of the singly linked list.

3

Q 3: Priority queues can be implemented by using unordered linked list. Which of the following operations is (are) used to dequeue? a. b. c. d.

Searching and Deleting. Searching. Deleting. Inserting and Searching.

Q 4: Assume that in an array list implementation of a stack, pushing an element onto a full stack requires allocating more memory. What is the complexity of pushing operation in this case? a. b. c. d. e.

O(n) O(n2) None of the others. O(1) O(lg n)

Q 5: Select the best choice: A stack can be implemented using… Select one: a. b. c. d. e.

A singly linked list. A circular linked list. An array. All of the others. A double linked list.

Q 6: What is the complexity of reversing the order of the elements on a stack using two additional stacks? Select one: a. O(n) b. O(lg n) c. O(n2) d. O(1) Q 7: Suppose we are implementing a stack using a singly linked list where the head of the list is treated as the top of the stack. Specify the correct implementation of push() method of the stack. (Choose the most suitable one) Select one: a. void push(Object x) { Node p = new Node(x); p.next = head; } b. void push(Object x) { Node p = new Node(x); p.next = head; head = p.next; }

4

c. void push(Object x) { Node p = new Node(x); p.next = null; head = p; } d. void push(Object x) { Node p = new Node(x); p.next = head; head = p; }

Q 8: If the value of A, B, C and D are 2, 3, 4 and 5, respectively. Using stack, manually calculate the value of the following postfix expression A B C + * D – ( 2+3*4-5) Select one: a. b. c. d.

9 7 6 11

Q 9: Consider the following pseudocode: declare a stack of characters while (there are more characters in the word to read) { read a character if a character is ‘*’ then pop and write the popped character to the screen else push the character into the stack } What is written to the screen for the input “Go**odMorn**in***g” ? Select one: a. b. c. d.

oGnrniM oGnrndo oGnrnid oGnrnio

Q 10: Priority queues can be implemented by using unordered linked list. In this case, which of the following operations of the linked list is (are) used to enqueue an element? Select one:

5

a. b. c. d.

Searching. All of the others. Deleting. Inserting.

RECURSION Q 1: Recursion requires much memory because: Select one: a. Previous function calls are still open when the function calls itself and the activation records of these previous calls still occupy space on the call stack. b. It requires large data values. c. Recursive functions tend to declare many local variables. d. Many copies of the function code are created. Q 2: Which of the following is not correct about a recursive function? Select one: a. b. c. d.

A recursive function may call itself indirectly. A recursive function may call itself directly. A recursive function is based on the recursion principle. A recursive function is based on the diversion principle.

Q 3: Consider the following chain of method calls: f() → f1() → f2() → f(3) → f() What is this kind of recursion? a. b. c. d.

Indirect recursion. Tail recursion. Non-tail recursion. None of the others.

Q 4: How many activation records are allocated when calculating Fibonacci(5) by calling recursion method? a. b. c. d.

25 41 9 15

6

Q 5: Select an incorrect statement. What is this kind of recursion? a. Recursion, gone wrong, can lead to an overflow stack error. b. Recursion is always more efficient than loops. c. Recursion can made the conceptual design of an algorithm’s implementation easier.

// Q 6: Consider the following statements about recursion: a) A recursive approach may be inefficient in many cases. If so, it can be replaced with a simple loop or a stack-based approach. b) Some value of its arguments causes a recursive method to return without calling itself. This is called the ground case. Select one: a. a and b are false b. a is true, b is false c. a and b are true d. a is false, b is true

Q 7: Which of the following problems may use the recursion technique? Select one: a. Perform symbolic differentiation b. All of the others c. The eight queens problem d. The Maze problem

Q 8: The recursion statement indicates... Select one: a. the ending of the recursion statement b. the rule of the recursion c. the starting value d. the beginning of the recursion statement

7

Q 9: Precondition for both methods: n >= 0 public boolean even(int n){ if(n==0) return true; return odd(n-1); } public boolean odd(int n){ if(n==0) return false; return even(n-1); } Which assertions are correct? a. odd always stops, but even may loop indefinitely b. both odd and even may loop indefinitely c. even always stops, but odd may loop indefinitely d. both odd and even always stops

// Q 10: When the compiler compiles your program, how is a recursive call treated differently than a non-recursive method call? a. There is no duplication of local variables b. None of the others c. Primitive values are all treated as reference variables d. Reference variables are all treated as primitive values

BINARY TREE Q 1: To implement an AVL tree, a concept balance factor is introduced (bal = height(right) height(left)). Suppose an AVL tree is created by inserting to the tree the following keys sequentially: 6, 4, 7, 3, 5, 2. What is the balance factor of the node 4? (please note that the tree is still AVL) Select one: a. 1 b. 0 c. 2

8

d. -1 Q 2: What is the result of the breadth first traverse of the the binary search tree T, after inserting the following keys into the tree sequentially (suppose T is empty before insertion): 6, 7, 3, 1, 2, 5, 8 Select one: a. 6, 3, 1, 2, 5, 7, 8 b. 6, 3, 7, 1, 5, 2, 8 c. 6, 3, 7, 1, 5, 8, 2 d. 6, 3, 7, 1, 2, 5, 8

Q 3: Which of the following statements is true? Select one: a. If the binary tree has n nodes and height h, then h
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF