Quiz 1

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

A normal queue, if implemented using an array of size MAX_SIZE, gets full when a) Rear = MAX_SIZE - 1 b) Front = (rear + 1)mod MAX_SIZE c) Front = rear + 1 d) Rear = front

a) Rear = MAX_SIZE - 1 Explanation: Condition for size of queue.

In a stack, if a user tries to remove an element from empty stack it is called _________ a) Underflow b) Empty collection c) Overflow d) Garbage Collection

a) Underflow

True statements about AVL tree are A. It is a binary search tree. B. Left node and right node differs in height by at most 1 unit C. Worst case time complexity is O(log2n) D. Worst case time complexity is O(n)

A. It is a binary search tree. B. Left node and right node differs in height by at most 1 unit C. Worst case time complexity is O(log2n)

If the elements "A", "B", "C" and "D" are placed in a queue and are deleted one at a time, in what order will they be removed? a) ABCD b) DCBA c) DCAB d) ABCD

a) ABCD or d) ABCD Explanation: Queue follows FIFO approach.

A queue is a? a) FIFO (First In First Out) list b) LIFO (Last In First Out) list c) Ordered array d) Linear tree

a) FIFO (First In First Out) list

What is the space complexity for deleting a linked list? a) O(1) b) O(n) c) Either O(1) or O(n) d) O(logn)

a) O(1) Explanation: You need a temp variable to keep track of current node, hence the space complexity is O(1).

Pushing an element into stack already having five elements and stack size of 5, then stack becomes a) Overflow b) Crash c) Underflow d) User flow

a) Overflow

A linear list of elements in which deletion can be done from one end (front) and insertion can take place only at the other end (rear) is known as a? a) Queue b) Stack c) Tree d) Linked list

a) Queue

What differentiates a circular linked list from a normal linked list? a) You cannot have the 'next' pointer point to null in a circular linked list b) It is faster to traverse the circular linked list c) You may or may not have the 'next' pointer point to null in a circular linked list d) All of the mentioned

a) You cannot have the 'next' pointer point to null in a circular linked list Explanation: The 'next' pointer points to null only when the list is empty, otherwise it points to the head of the list.

What is an AVL tree? a) a tree which is balanced and is a height balanced tree b) a tree which is unbalanced and is a height balanced tree c) a tree with three children d) a tree with at most 3 children

a) a tree which is balanced and is a height balanced tree Explanation: It is a self-balancing tree with height difference at most 1.

What maximum difference in heights between the leaves of an AVL tree is possible? a) log(n) where n is the number of nodes b) n where n is the number of nodes c) 0 or 1 d) at most 1

a) log(n) where n is the number of nodes Explanation: At every level we can form a tree with difference in height between subtrees to be at most 1 and so there can be log(n) such levels since height of AVL tree is log(n).

Why we need to a binary tree which is height balanced? a) to avoid formation of skew trees b) to save memory c) to attain faster memory access d) to simplify storing

a) to avoid formation of skew trees Explanation: In real world dealing with random values is often not possible, the probability that you are dealing with non-random values (like sequential) leads to mostly skew trees, which leads to worst case. hence, we make height balance by rotations.

To restore the AVL property after inserting a element, we start at the insertion point and move towards root of that tree. is this statement true? a) true b) false

a) true Explanation: It is interesting to note that after insertion, only the path from that point to node or only that subtrees are imbalanced in terms of height.

Consider a small circular linked list. How to detect the presence of cycles in this list effectively? a) Keep one node as head and traverse another temp node till the end to check if its 'next points to head b) Have fast and slow pointers with the fast pointer advancing two nodes at a time and slow pointer advancing by one node at a time c) Cannot determine, you have to pre-define if the list contains cycles d) None of the mentioned

b) Have fast and slow pointers with the fast pointer advancing two nodes at a time Explanation: Advance the pointers as mentioned in 'b', check to see if at any given instant of time if the fast pointer points to slow pointer or if the fast pointer's 'next' points to the slow pointer. Note that this trick is useful only if the list is small.

What is the time complexity to count the number of elements in the linked list? a) O(1) b) O(n) c) O(logn) d) None of the mentioned

b) O(n) Explanation: To count the number of elements, you have to traverse through the entire list, hence complexity is O(n).

Process of inserting an element in stack is called ____________ a) Create b) Push c) Evaluation d) Pop

b) Push

In Breadth First Search of Graph, which of the following data structure is used? a) Stack b) Queue c) Linked list d) None of the mentioned

b) Queue

Which of the following is false about a circular linked list? a) Every node has a successor b) Time complexity of inserting a new node at the head of the list is O(1) c) Time complexity for deleting the last node is O(n) d) None of the mentioned

b) Time complexity of inserting a new node at the head of the list is O(1) Explanation: Time complexity of inserting a new node at the head of the list is O(n) because you must traverse through the list to find the tail node.

Given an empty AVL tree, how would you construct AVL tree when a set of numbers are given without performing any rotations? a) just build the tree with the given input b) find the median of the set of elements given, make it as root and construct the tree c) use trial and error d) use dynamic programming to build the tree

b) find the median of the set of elements given, make it as root and construct the tree Explanation: Sort the given input, find the median element among them, make it as root and construct left and right subtrees with elements lesser and greater than the median element recursively. this ensures the subtrees differ only by height 1.

What is the maximum height of an AVL tree with p nodes? a) p b) log(p) c) log(p)/2 d) p⁄2

b) log(p) Explanation: Consider height of tree to be 'he', then number of nodes which totals to p can be written in terms of height as N(he)=N(he-1)+1+N(he-2). since N(he) which is p can be written in terms of height as the beside recurrence relation which on solving gives N(he)= O(logp) as worst-case height.

A data structure in which elements can be inserted or deleted at/from both the ends but not in the middle is? a) Queue b) Circular queue c) Dequeue d) Priority queue

c) Dequeue

What is the functionality of the following piece of code? public int function(int data) { Node temp = head; int var = 0; while(temp != null) { if(temp.getData() == data) { return var; } var = var+1; temp = temp.getNext(); } return Integer.MIN_VALUE; } a) Find and delete a given element in the list b) Find and return the given element in the list c) Find and return the position of the given element in the list d) Find and insert a new element in the list

c) Find and return the position of the given element in the list Explanation: When temp is equal to data, the position of data is returned.

What is the functionality of the following code? public void function(Node node) { if(size == 0) head = node; else { Node temp,cur; for(cur = head; (temp = cur.getNext())!=null; cur = temp); cur.setNext(node); } size++; } a) Inserting a node at the beginning of the list b) Deleting a node at the beginning of the list c) Inserting a node at the end of the list d) Deleting a node at the end of the list

c) Inserting a node at the end of the list Explanation: The for loop traverses through the list and then inserts a new node as cur.setNext(node);

The data structure required for Breadth First Traversal on a graph is? a) Stack b) Array c) Queue d) Tree

c) Queue

Queues serve major role in a) Simulation of recursion b) Simulation of arbitrary linked list c) Simulation of limited resource allocation d) All of the mentioned

c) Simulation of limited resource allocation Explanation: Rest all are implemented using other data structures.

Which of the below diagram is following AVL tree property? i. ii. a) only i b) only i and ii c) only ii d) none of the mentioned

c) only ii Explanation: The property of AVL tree is it is height balanced tree with difference of at most 1 between left and right subtrees.

Which of the following is not a disadvantage to the usage of array? a) Fixed size b) You know the size of the array prior to allocation c) Insertion based on position d) Accessing elements at specified positions

d) Accessing elements at specified positions

Which of the following applications may use a stack? a) A parentheses balancing program. b) Tracking of local variables at run time. c) Compiler Syntax Analyzer. d) All of the mentioned

d) All of the mentioned

Which of these is an application of linked lists? a) To implement file systems b) For separate chaining in hash-tables c) To implement non-binary trees d) All of the mentioned

d) All of the mentioned Explanation: Linked lists can be used to implement all of the above-mentioned applications.

What is the time complexity of inserting at the end in dynamic arrays? a) O(1) b) O(n) c) O(logn) d) Either O(1) or O(n)

d) Either O(1) or O(n) Explanation: Depending on whether the array is full or not, the complexity in dynamic array varies. If you try to insert into an array which is not full, then the element is simply stored at the end, this takes O(1) time. If you try to insert into an array which is full, first you will have to allocate an array with double the size of the current array and then copy all the elements into it and finally insert the new element, this takes O(n) time.

Process of removing an element from stack is called __________ a) Create b) Push c) Evaluation d) Pop

d) Pop

Entries in a stack are "ordered". What is the meaning of this statement? a) A collection of stacks is sortable. b) Stack entries may be compared with the '<' operation. c) The entries are stored in a linked list. d) There is a Sequential entry that is one by one.

d) There is a Sequential entry that is one by one.


Kaugnay na mga set ng pag-aaral

Chapter 52 - Assessment of the GI System

View Set

Anatomy and Physiology multiple choice 1

View Set

chapter 7a constraint and capacity

View Set

CPTR.5772.61.Info Security Tech EXAM1

View Set

Wk 1 - Practice: Week 1 Knowledge Check

View Set

opma chap 4 ls, opma ch6 l.s., ch8 learnsmart

View Set