Quiz Dsa
Quiz Dsa
Quiz Dsa
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 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)
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 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
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.
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.
O(n)
O(n2)
None of the others.
O(1)
O(lg n)
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;
}
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;
}
9
7
6
11
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:
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.
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
//
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 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
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 4: What is the complexity of inserting a node in a perfectly balanced tree for worst case?
a. O(n)
b. O(lgn)
c. O(nlgn)
d. None of the others
Q8: Which of the following is an appropriate description concerning a binary search tree
whose node values are 17, 6, 19, 3, 22, 32?
a. No matter which values is placed at the root node, 3 cannot have a left child.
b. The root node values cannot be 32.
c. Any binary tree containing these values has a maximum depth of three (3).
d. No matter which values is placed at the root node, 3 is always at the deepest
level.
10
Q10: In a binary search tree, certain null entries are replaced by pointers which point
to node higher in the tree for traversal. These special pointers are called
a. Root
b. Arc
c. Thread
d. Non-terminal
e. Leaf
SORTING
Q 1: After two passes of a sort algorithm, the following array:
47 3 21 32 56 92
has been rearranged as shown below:
3 21 47 32 56 92
Which sorting algorithm is being used?
a.
b.
c.
d.
all of them
bubble sort
selection sort
insertion sort
3, 4, 5, 6, 8, 7, 9, 10
3, 4, 5, 6, 8, 10, 7, 9
3, 4, 5, 6, 7, 8, 10, 9
3, 4, 6, 5, 8, 10, 7, 9
Q 3: Which of the following Sorting algorithms use Divide and Conquer strategy?
Select one:
a.
b.
c.
d.
Quick sort
Radix sort
Heap sort
Bubble sort.
11
Q 4: When a list of 7 elements shown below is rearranged in ascending order, which of the
following sorting algorithms is completed with the minimum number of elements exchanges?
3 5 12 9 10 7 15
Select one:
a.
b.
c.
d.
Shell sort
Merge sort
Insertion sort
Bubble sort
Q 5: An array contains the elements shown. Show the contents of the array after it has gone
through a one-increment pass of the shell sort. The increment factor is h = 3.
23 3 7 13 89 7 66 18 90 98 57
Select one:
a.
b.
c.
d.
13 2 6 23 3 7 44 18 7 66 57 90 98 89
2 3 6 13 89 7 66 23 7 44 18 90 98 57
2 98 66 3 89 44 6 23 7 7 18 90 13 57
2 3 6 7 23 13 89 7 66 44 18 90 98 57
Q 6: Which of the following Sorting algorithms have complexity of O(n) in best case?
Select one:
a. Bubble sort
b. All of the others
c. Selection sort
d. Insertion sort
Q 7: Which the sorting technique always makes recursive calls to sort pieces that are about
half the size of the original array?
Select one:
a. Quick sort
b. Heap sort
c. Merge sort
d. Shell sort
12
a. In particular sorting situation, if swaps take much longer than comparisons, the selection
sort is about twice as fast as the bubble sort.
b. A copy is three times as fast as a swap.
c. If there are N items, the bubble sort makes exactly N*N comparisons.
d. The bubble sort always ends up comparing every item with every other item.
HASING
Q 1: What is the best definition of a collision situation in hash table?
Select one:
a.
b.
c.
d.
Two entries with the exact same key have different values.
Two entries are identical except for their keys.
Two entries with different data have the exact same key.
Two entries with different keys have the same exact hash value.
13
Select one:
a.
b.
c.
d.
Q 4: You want to place 1000 elements in a hash table using linear probing, and you would
like an average numbers of trials for successful search two elements. How big does the array
of hash table need to be? Select one:
a.
b.
c.
d.
1000
125
50
1500
HashTable
Singly Linked List.
Priority Queue.
Connected Graph
Q 6: In a simple hash function, the division method is used for page-based address
translation: a pair of new logical page number "101000" and its corresponding physical page
number "0010" is stored into the page table shown below. Which of the following indexes is
used to place them in the table? Here, the given logical page number is divided by 7, and its
remainder is used as the index of the page table. If the slot specified by the index value is
already taken, the table is searched forward from that slot to find the next empty slot.
a. 000
b. 010
c. 110
d. 111
14
Q 7: Suppose that you place 180 elements in a hash table with an array size of 200. What is
the load factor?
Select one:
a. 0.9
b. 0.75
c. 0.5
d. 1.45
Q 8: Using the coalesced hashing to put the following values in a table with 10 elements:
A5, A2, A3, B5, A9, B2, B9, C2
Using the extraction method to extract the number as the key.
What is the chain to begin with A5?
Select one:
a. A5-B5-A9-B9
c. A5-B5
c. A5-A2-A3
d. A5-B2-C2
Q 9: The best technique when the amount of data is not well known is ...
Select one:
a. separate chaining
b. linear probing
c. quadratic probing
d. double hashing
Q 10: A chained hash table has an array size of 512. What is the maximum number of entries
that can be placed in the table?
Select one:
a. 512
b. 511
c. 256
15
d. 1024
e. None of the others
DATA COMPRESSION
Q 1: Select incorrect statement about Adaptive Huffman Coding:
Select one:
a. If the sibling property is violated, Huffman tree has to be restructured to restore this
property.
b. The sibling property is described as each node has a sibling (except for the root) and
the breadth-first right-to-left tree traversal generates a list of nodes with nonincreasing
frequency counters.
c. Adaptive Huffman coding can be applied to any kind of file.
d. If Adaptive Huffman coding is used to compress executive file, output file is much smaller
than the original.
Q 2: What is output of using LZW algorithm with the table initialized with the letters x, y, z
encode the string "xyxyzxxy"?
Select one:
a. 1 2 4 3 5 2
b. 1 2 4 3 1 4
c. 4 4 3 1 1 2
d. 1 2 1 2 3 1 1 2
Q 3: Find the average length L Huf for the letters X, Y, and Z and their probabilities .05, .05
and .9 respectively.
Select one:
a. 2.3
b. 1.75
c. None of the others.
d. 0.8
e. 1.1
16
Q 4: Encoding the string "aaabbccddddddeee" with Huffman. Please indicate the size of the
output string?
Select one:
a. 128 bits
b. 24 bits
c. 16 bits
d. 36 bits
Q 6: What is output of using LZW algorithm with the table initialized with the letters a, b, c
encode the string "ababcaab"?
Select one:
a. 1 2 4 3 5 2
b. 1 2 4 3 1 4
c. 4 4 3 1 1 2
d. 1 2 1 2 3 1 1 2
17
18