Sie sind auf Seite 1von 18

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

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

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.

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;
}

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:

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

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 algorithms 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

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

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 <= lg(n+1)
b. If all of its leaves at the same level, then the binary tree is full
c. A binary tree cannot have more than 2^d nodes at level d.
d. if every proper subtree of a binary tree is full, then the tree itself must also be full

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

Q 5: Consider the heap: 100 90 80 30 60 50 70 20 10


What is the position of the elements when dequeuing an element?
Select one:
a. 90 10 80 30 60 50 70 20
b. 90 60 80 30 10 50 70 20
c. 90 60 80 30 20 50 70 10

Q 6: Which of the following arrays is (are) heap?


Select one:
a. 82 70 51 63 55 37 10 43 27 30 34
b. 82 70 51 63 34 37 10 43 27 30 55
c. 82 70 51 43 55 37 10 43 63 30 34
d. All of the others

Q 7: Which of the following statements is false?


Select one:
a. The postorder traversal always visits the right-most node first.
b. The preorder traversals always visit the root first.
c. The top-down level order traversals always visit the root first.
d. The postorder traversal always visits the root last.

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.

Q9:The top-down method of J. Williams is used to organize the following array as a


heap
a. 17 8 14 5 4 12 13 10 3
b. 17 8 14 12 13 4 5 3 10
c. 17 14 12 13 4 8 5 3 10
d.17 14 8 13 12 4 5 3 10

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

Q 2: Consider the list of eight integers below: 6, 4, 9, 10, 8, 3, 7, 5


What is the list after is has just been partitioned by the first step of quicksort and a pivot
value is chosen as the first element of the list? (sorting from smallest to largest).
a.
b.
c.
d.

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

Q 8: Select correct statement:


Select one:

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.

Q 9: An array contains the elements shown below:


7 8 26 44 13 23 98 57
What would be the value of the elements in the array after two pass of the heap sort
algorithm.
Select one:
a. 7 8 13 23 26 44 57 98
b. 44 26 23 7 13 8 57 98
c. 26 13 23 7 8 44 57 98
d. 57 26 44 7 13 8 23 98
e. None of the others

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.

Q 2: Select incorrect statement:


Select one:
a. A hash function transforms a range of key values into a range of index values.
b. Using the next available position after an unsuccessful probe is called quadratic
probing.
c. Separate chaining involves the use if a linked list at each location.
d. The first five step sizes in quadratic probing are 1, 4, 9, 16, 25.
Q 3: Secondary clustering occurs because

13

Select one:
a.
b.
c.
d.

the sequence of step lengths is always the same.


the hash function is not perfect.
too many items with the same key are inserted.
many keys hash to the same location..

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

Q 5: The Java Collections Framework contains a Map interface. An implementation of this


interface is
Select one:
a.
b.
c.
d.

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 5: Given the character frequencies


B: 32%
C: 28%
D: 16%
E: 6%
F: 18%
Using Huffman encoding, what is the code for character D? (Suppose that when constructing
a subtree from 2 nodes we always place node with higher frequency on the left; and the left
branch of a node gets value 0, the right one gets value 1)
Select one:
a. 01
b. 001
c. 101
d. 100

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

Q 7: In run-length encoding algorithm a run is define as ... Select one:

17

a. Amount of time require to the compression algorithm


b. A sequence of identical characters
c. The size of result of encoding input data
d. Number of different character in the input

Q 8: Select incorrect statement about restrictions need to be imposed on the prospective


codes: Select one:
a. There should not be any unused short codewords either as stand-alone encodings or as
prefix for longer codewords
b. Decoding should not require any look ahead
c. Each codeword maybe corresponds to one or many symbols
d. The length of the codewords for a given symbol A should not exceed the length of the
codeword of a less probable symbol B

Q 9: Given a raw message BBBUUUUBBBUUBBBBBUU (without single quote). Run the


run-length encoding algorithms for that message, what is the output? Select one:
a. 3B4U3B2U5B
b. 3B4U3B2U5B2UU
c. 3B4U4B3U2B5UU2
d. 3B4U3B2U5B2U

18

Das könnte Ihnen auch gefallen