Advanced Data Structures and Algorithms: Quiz 1
What is an AVL tree?
a tree which is balanced and is a height balanced tree
Which of the following applications may use a stack?
A parentheses balancing program, Tracking of local variables at run time, Compiler Syntax Analyzer.
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?
ABCD , ABCD
Which of the following is not a disadvantage to the usage of array?
Accessing elements at specified positions
A data structure in which elements can be inserted or deleted at/from both the ends but not in the middle is?
Dequeue
What is the time complexity of inserting at the end in dynamic arrays?
Either O(1) or O(n)
A queue is a?
FIFO (First In First Out) list
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; }
Find and return the position of the given element in the list
Consider a small circular linked list. How to detect the presence of cycles in this list effectively?
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
Consider the below left-left rotation pseudo code where the node contains value pointers to left, right child nodes and a height value and Height() function returns height value stored at a particular node. avltree leftrotation(avltreenode z): avltreenode w =x-left x-left=w-right w-right=x x-height=max(Height(x-left),Height(x-right))+1 w-height=max(missing)+1 return w What is missing?
Height(w-left), x-height
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++; }
Inserting a node at the end of the list
True statements about AVL tree are
It is a binary search tree Left node and right node differs in height by at most 1 unit Worst case time complexity is O(log2n)
What is the space complexity for deleting a linked list?
O(1)
What is the time complexity to count the number of elements in the linked list?
O(n)
Pushing an element into stack already having five elements and stack size of 5, then stack becomes
Overflow
Process of inserting an element in stack is called
Push
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?
Queue
In Breadth First Search of Graph, which of the following data structure is used?
Queue
The data structure required for Breadth First Traversal on a graph is?
Queue
Queues serve major role in
Simulation of limited resource allocation
Entries in a stack are "ordered". What is the meaning of this statement?
There is a Sequential entry that is one by one.
Which of the following is false about a circular linked list?
Time complexity of inserting a new node at the head of the list is O(1)
Which of these is an application of linked lists?
To implement file systems , For separate chaining in hash-tables, To implement non-binary trees
In a stack, if a user tries to remove an element from empty stack it is called
Underflow
What differentiates a circular linked list from a normal linked list?
You cannot have the 'next' pointer point to null in a circular linked list
Given an empty AVL tree, how would you construct AVL tree when a set of numbers are given without performing any rotations?
find the median of the set of elements given, make it as root and construct the tree
What is the maximum height of an AVL tree with p nodes?
log(p)
Why we need to a binary tree which is height balanced?
to avoid formation of skew trees
Process of removing an element from stack is called
Pop
A normal queue, if implemented using an array of size MAX_SIZE, gets full when
Rear = MAX_SIZE - 1
Which of the following performs deletion of the last element in the list? Given below is the Node class. class Node { protected Node next; protected Object ele; Node(Object e,Node n) { ele = e; next = n; } public void setNext(Node n) { next = n; } public void setEle(Object e) { ele = e; } public Node getNext() { return next; } public Object getEle() { return ele; } } class SLL { Node head; int size; SLL() { size = 0; } }
public Node removeLast() { if(size == 0) return null; Node cur; Node temp; cur = head; while(cur.getNext() != null) { temp = cur; cur = cur.getNext(); } temp.setNext(null); size--; return cur; }
Which of the following piece of code has the functionality of counting the number of elements in the list?
public int length(Node head) { int size = 0; Node cur = head; while(cur!=null) { size++; cur = cur.getNext(); } return size; }
How would you delete a node in the singly linked list? The position to be deleted is given.
public void delete(int pos) { if(pos < 0) pos = 0; if(pos > size) pos = size; if( size == 0) return; if(pos == 0) head = head.getNext(); else { Node temp = head; for(int i=1; i<pos; i++) { temp = temp.getNext(); } temp.setNext(temp.getNext().getNext()); } size--; }
How do you insert an element at the beginning of the list?
public void insertBegin(Node node) { node.setNext(head); head = node; size++; }
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?
true
What maximum difference in heights between the leaves of an AVL tree is possible?
log(n) where n is the number of nodes
Consider the pseudo code: int avl(binarysearchtree root): if(not root) return 0 left_tree_height = avl(left_of_root) if(left_tree_height== -1) return left_tree_height right_tree_height= avl(right_of_root) if(right_tree_height==-1) return right_tree_height Does the above code can check if a binary search tree is an AVL tree?
no