Data Structures Midterm

Ace your homework & exams now with Quizwiz!

Traversal

The operation of processing each element in the list is known as A. Sorting B. Merging C. Inserting D. Traversal

AB + CD× E - ×F ×G /

The postfix form of the expression (A+ B)×(C×D- E)×F / G is? a) AB+ CD × E - FG /×× b) AB + CD × E - F ××G / c) AB + CD × E - ×F ×G / d) AB + CDE × - × F ×G /

None of above

Which of the following data structure is not linear data structure? A. Arrays B. Linked lists C. Both of above D. None of above

A binary tree, which is completely filled, with the possible exception of the bottom level, which is filled from left to right

What is a complete binary tree? a) Each node has exactly zero or two children b) A binary tree, which is completely filled, with the possible exception of the bottom level, which is filled from right to left c) A binary tree, which is completely filled, with the possible exception of the bottom level, which is filled from left to right d) None of the mentioned

S[N-1] (Array indexing start from 0, hence N-1 is the last index.)

Which of the following array element will return the top-of-the-stack-element for a stack of size N elements(capacity of stack > N). a) S[N-1]. b) S[N]. c) S[N-2]. d) S[N+1].

Arrays

Which of the following data structure is linear data structure? A. Trees B. Graphs C. Arrays D. None of above

First In First Out

Which of the following properties is associated with a queue? a) First In Last Out b) First In First Out c) Last In First Out d) None of the mentioned

piling up of chairs one above the other

Which of the following real-world scenarios would you associate with a stack data structure? a) piling up of chairs one above the other b) people standing in a line to be serviced at a counter c) offer services based on the priority of the customer d) all of the mentioned

None of the mentioned

Which of the following is false about a binary search tree? a) The left child is always lesser than its parent b) The right child is always greater than its parent c) The left and right sub-trees should also be binary search trees d) None of the mentioned

Push

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

350

The result of evaluating the postfix expression 5, 4, 6, +, ×, 4, 9, 3, /, +, × is? a) 600 b) 350 c) 650 d) 588

Pre-order traversal (As the name itself suggests, PRE-order traversal can be used.)

To obtain a prefix expression, which of the tree traversals is used? a) Level-order traversal b) Pre-order traversal c) Post-order traversal d) In-order traversal

b) (In-order traversal follows LNR(Left-Node-Right))

Select the code snippet which performs in-order traversal. a) public void inorder(Tree root) { System.out.println(root.data); inorder(root.left); inorder(root.right); } b) public void inorder(Tree root) { inorder(root.left); System.out.println(root.data); inorder(root.right); } c) public void inorder(Tree root) { System.out.println(root.data); inorder(root.right); inorder(root.left); } d) None of the mentioned

root node

Special node in tree structure which has many child nodes and one parent node is called a. descendant nodes b. root node c. leaf node d. search node

Each node has exactly zero or two children

.What is a full binary tree? a) Each node has exactly zero or two children b) Each node has exactly two children c) All the leaves are at the same level d) Each node has exactly one or two children

head-6-1-2-3-4-tail (A new node is added to the head of the list and a node is deleted from the tail end of the list.)

Consider the following doubly linked list: head-1-2-3-4-5-tail What will be the list after performing the given sequence of operations? Node temp = new Node(6,head,head.getNext()); head.setNext(temp); temp.getNext().setPrev(temp); Node temp1 = tail.getPrev(); tail.setPrev(temp1.getPrev()); temp1.getPrev().setNext(tail); a) head-6-1-2-3-4-5-tail b) head-6-1-2-3-4-tail c) head-1-2-3-4-5-6-tail d) head-1-2-3-4-5-tail

space allocation for array is fixed and cannot be changed during run-time (You cannot modify the size of an array once the memory has been allocated, adding fewer elements than the array size would cause wastage of space, and adding more elements than the array size at run time would cause Stack Overflow.)

'Array implementation of Stack is not dynamic', which of the following statements supports this argument? a) space allocation for array is fixed and cannot be changed during run-time b) user unable to give the input for stack operations c) a runtime exception halts execution d) all of the mentioned

Dequeue

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

Queue

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

FIFO (First In First Out) list

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

Priority queue (The property of heap that the value of root must be either greater or less than both of its children makes it work like a priority queue.)

Heap can be used as... a) Priority queue b) Stack c) A decreasing order arrays d) None of the mentioned

True (Because the leaf nodes are present at height h or h-1, which is a property of complete binary tree.)

Heap exhibits the property of a binary tree? a) True b) False

4

Here is an infix expression: 4+3×(6×3-12). Suppose that we are using the usual stack algorithm to convert the expression from infix to postfix notation. The maximum number of symbols that will appear on the stack AT ONE TIME during the conversion of this expression? a) 1 b) 2 c) 3 d) 4

ABCD

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

*Insert at Beginning:* public void insertAtStart(int val) { Node nptr = new Node(val, null); size++ ; if(start == null) { start = nptr; end = start; } else { nptr.setLink(start); start = nptr; } } *Insert at End:* public void insertAtEnd(int val) { Node nptr = new Node(val,null); size++ ; if(start == null) { start = nptr; end = start; } else { end.setLink(nptr); end = nptr; } }

Implement the java code for Inserting and deleting an element at the head and tail of the singly linked list using Linked List approach. Illustrate by diagrams.

N = 2L - 1 (Trace with respect to the diagram.)

In a full binary tree if there are L leaves, then total number of nodes N are? a) N = 2L b) N = L + 1 c) N = L - 1 d) N = 2L - 1

for the size of the structure and the data in the structure are constantly changing

Linked lists are best suited A. For relatively permanent collections of data B. for the size of the structure and the data in the structure are constantly changing C. For both of above situation D. For none of above situation

Overflow

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

Simulation of limited resource allocation

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

Stack

The data structure required to check whether an expression contains balanced parenthesis is? a) Stack b) Queue c) Array d) Tree

b) (Post order traversal follows LRN(Left-Right-Node).)

Select the code snippet which performs post-order traversal. a) public void postorder(Tree root) { System.out.println(root.data); postorder(root.left); postorder(root.right); } b) public void postorder(Tree root) { postorder(root.left); postorder(root.right); System.out.println(root.data); } c) public void postorder(Tree root) { System.out.println(root.data); postorder(root.right); postorder(root.left); } d) None of the mentioned

Height

The number of edges from the node to the deepest leaf is called _________ of the tree. a) Height b) Depth c) Length d) None of the mentioned

Depth

The number of edges from the root to the node is called __________ of the tree. a) Height b) Depth c) Length d) None of the mentioned

-A/B×C^DE

The prefix form of A-B/ (C × D ^ E) is? a) -/×^ACBDE b) -ABCD×^DE c) -A/B×C^DE d) -A/BC×^DE

- +pq × rt

The prefix form of an infix expression p + q - r × t is? a) + pq - ×rt b) - +pqr × t c) - +pq × rt d) - + × pqrt

Stack

The process of accessing data stored in a serial access memory is similar to manipulating data on a ________ a) Heap b) Binary Tree c) Array d) Stack

Postfix Expression

The type of expression in which operator succeeds its operands is? a) Infix Expression b) Prefix Expression c) Postfix Expression d) None of the mentioned

All of the mentioned (All of these properties of priority queue help in achieving its applications like Huffman coding, priority scheduling and the like.)

What are the advantages of priority queues? a) Easy to implement b) Processes with different priority can be efficiently handled c) Applications with differing requirements d) All of the mentioned

removing items from an empty stack

What does 'stack underflow' refer to? a) accessing item from an undefined stack b) adding items to a full stack c) removing items from an empty stack d) index out of bounds exception

Return the front element

What does the following piece of code do? public Object function() { if(isEmpty()) return -999; else { Object high; high = q[front]; return high; } } a) Dequeue b) Enqueue c) Return the front element d) None of the mentioned

Postorder traversal (In a postorder traversal, first the left child is visited, then the right child and finally the parent.)

What does the following piece of code do? public void func(Tree root) { func(root.left()); func(root.right()); System.out.println(root.data()); } a) Preorder traversal b) Inorder traversal c) Postorder traversal d) Level order traversal

EmptyStackException is thrown

What happens when you pop from an empty stack while implementing using the Stack ADT in Java? a) Undefined error b) Compiler displays a warning c) EmptyStackException is thrown d) NoStackException is thrown

Interrupt handling (It is in fact an advantage, interrupts should be given more priority than the task at hand so that the interrupt can be serviced.)

What is not a disadvantage of priority scheduling in operating systems? a) A low priority process might have to wait indefinitely for the CPU b) If the system crashes, the low priority systems may be lost permanently c) Interrupt handling d) None of the mentioned

15 and 1 (As 15 is less than 25 so there would be no violation and the node will remain at that position. So, leaf nodes with value 15 and 1 will be at the position in right sub tree.)

f we implement heap as maximum heap, adding a new node of value 15 to the left most node of right subtree. What value will be at leaf nodes of the right subtree of the heap. a) 15 and 1 b) 25 and 1 c) 3 and 1 d) 2 and 3

Stack

What data structure would you mostly likely see in a non-recursive implementation of a recursive algorithm? a) Linked List b) Stack c) Queue d) Tree

Single ended queue

Which of the following is not the type of queue? a) Ordinary queue b) Single ended queue c) Circular queue d) Priority queue

*Insert Element at Position:* public void insertAtPos(int val , int pos) { Node nptr = new Node(val, null, null); if (pos == 1) { insertAtStart(val); return; } Node ptr = start; for (int i = 2; i <= size; i++) { if (i == pos) { Node tmp = ptr.getLinkNext(); ptr.setLinkNext(nptr); nptr.setLinkPrev(ptr); nptr.setLinkNext(tmp); tmp.setLinkPrev(nptr); } ptr = ptr.getLinkNext(); } size++ ; } *Delete Element at a Position:* public void deleteAtPos(int pos) { if (pos == 1) { if (size == 1) { start = null; end = null; size = 0; return; } start = start.getLinkNext(); start.setLinkPrev(null); size--; return ; } if (pos == size) { end = end.getLinkPrev(); end.setLinkNext(null); size-- ; } Node ptr = start.getLinkNext(); for (int i = 2; i <= size; i++) { if (i == pos) { Node p = ptr.getLinkPrev(); Node n = ptr.getLinkNext(); p.setLinkNext(n); n.setLinkPrev(p); size-- ; return; } ptr = ptr.getLinkNext(); } }

Implement the java code for Insertion and deletion operations in Doubly Linked List. (any 1 asked). Illustrate by diagrams.

*Push:* public void push(int i) { if(top+1>=size) throw new IndexOutOfBoundsException("Overflow Exception"); if (top+1<size) arr[++top]=i; len++; } *Pop:* public int pop() { if(isEmpty()) throw new NoSuchElementException("Underflow Exception"); len--; return arr[--top]; }

Implement the java code for the basic operations (Push, Pop) of stack data structure.

In-order traversal (In a binary search tree, a node's left child is always lesser than the node and right child is greater than the node, hence an in-order traversal would print them in a non-decreasing fashion.)

In a binary search tree, which of the following traversals would print the numbers in the ascending order? a) Level-order traversal b) Pre-order traversal c) Post-order traversal d) In-order traversal

N = 2I + 1 (Trace with respect to the diagram.)

In a full binary tree if number of internal nodes is I, then number of nodes N are? a) N = 2I b) N = I + 1 c) N = I - 1 d) N = 2I + 1

Root node (This is one of the property of max-heap that root node must have key greater than its children.)

In a max-heap, element with the greatest key is always in the which node? a) Leaf node b) First node of left sub tree c) Root node d) First node of right sub tree

Underflow

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

internal node

In tree structure diagrams, non-leaf node is called a. search node b. descendant nodes c. external node d. internal node

c) (Add the root to the stack first, then continuously check for the right and left children of the top-of-the-stack.)

Select the code snippet that performs pre-order traversal iteratively. a) public void preOrder(Tree root) { if (root == null) return; Stack<Tree> stk = new Stack<Tree>(); st.add(root); while (!stk.empty()) { Tree node = stk.pop(); System.out.print(node.data + " "); if (node.left != null) stk.push(node.left); if (node.right != null) stk.push(node.right); } } b) public void preOrder(Tree root) { if (root == null) return; Stack<Tree> stk = new Stack<Tree>(); while (!stk.empty()) { Tree node = stk.pop(); System.out.print(node.data + " "); if (node.right != null) stk.push(node.right); if (node.left != null) stk.push(node.left); } } c) public void preOrder(Tree root) { if (root == null) return; Stack<Tree> stk = new Stack<Tree>(); st.add(root); while (!stk.empty()) { Tree node = stk.pop(); System.out.print(node.data + " "); if (node.right != null) stk.push(node.right); if (node.left != null) stk.push(node.left); } } d) None of the mentioned

a) (Pre-order traversal follows NLR(Node-Left-Right).)

Select the code snippet which performs pre-order traversal. a) public void preorder(Tree root) { System.out.println(root.data); preorder(root.left); preorder(root.right); } b) public void preorder(Tree root) { preorder(root.left); System.out.println(root.data); preorder(root.right); } c) public void preorder(Tree root) { System.out.println(root.data); preorder(root.right); preorder(root.left); } d) None of the mentioned

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

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

Return the element at the tail of the list and remove it from the list (The previous and next pointers of the tail and the last but one element are manipulated, this suggests that the last node is being removed from the list.)

What is the functionality of the following piece of code? public int function() { Node temp = tail.getPrev(); tail.setPrev(temp.getPrev()); temp.getPrev().setNext(tail); size--; return temp.getItem(); } a) Return the element at the tail of the list but do not remove it b) Return the element at the tail of the list and remove it from the list c) Return the last but one element from the list but do not remove it d) Return the last but one element at the tail of the list and remove it from the list

It traverses in an increasing order (As a binary search tree consists of elements lesser than the node to the left and the ones greater than the node to the right, an inorder traversal will give the elements in an increasing order.)

What is the specialty about the in-order traversal of a binary search tree? a) It traverses in a non increasing order b) It traverses in an increasing order c) It traverses in a random fashion d) None of the mentioned

O(1) (Enqueue operation is at the rear end, it takes O(1) time to insert a new item into the queue.)

What is the time complexity of enqueue operation? a) O(logn) b) O(nlogn) c) O(n) d) O(1)

O(1) (pop() accesses only one end of the structure, and hence constant time.)

What is the time complexity of pop() operation when the stack is implemented using an array? a) O(1) b) O(n) c) O(logn) d) O(nlogn)

None of the mentioned (A doubly linked list has two pointers 'left' and 'right' which enable it to traverse in either direction. Compared to singly liked list which has only a 'next' pointer, doubly linked list requires extra space to store this extra pointer. Every insertion and deletion requires manipulation of two pointers, hence it takes a bit longer time.)

Which of the following is false about a doubly linked list? a) We can navigate in both the directions b) It requires more space than a singly linked list c) The insertion and deletion of a node take a bit longer d) None of the mentioned

Undo/Redo operations in a notepad (This is an application of stack.)

Which of the following is not an advantage of trees? a) Hierarchical structure b) Faster search c) Router algorithms d) Undo/Redo operations in a notepad

Undo operation in text editors (Undo operation is achieved using a stack.)

Which of the following is not an application of priority queue? a) Huffman codes b) Interrupt handling in operating system c) Undo operation in text editors d) Bayesian spam filter

Job scheduling

Which of the following is not an inherent application of stack? a) Reversing a string b) Evaluation of postfix expression c) Implementation of recursion d) Job scheduling

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

All of the mentioned (Priority queue can be implemented using an array, a list, a binary search tree or a heap, although the most efficient one being the heap.)

With what data structure can a priority queue be implemented? a) Array b) List c) Heap d) All of the mentioned

Something between 15 and 100

What is the value of the postfix expression 6 3 2 4 + - *: a) Something between -5 and -15 b) Something between 5 and -5 c) Something between 5 and 15 d) Something between 15 and 100

Stack

Which data structure is needed to convert infix notation to postfix notation? a) Branch b) Tree c) Queue d) Stack

Stack

Which data structure is used for implementing recursion? a) Queue b) Stack c) Array d) List

Rear = MAX_SIZE - 1

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

All of the mentioned

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

1

Consider the following operation performed on a stack of size 5. Push(1); Pop(); Push(2); Push(3); Pop(); Push(4); Pop(); Pop(); Push(5); After the completion of all operation, the number of elements present in stack are a) 1 b) 2 c) 3 d) 4

(A B D ⋀ + E F - / G +)

Convert the following infix expressions into its equivalent postfix expressions (A + B ⋀D)/(E - F)+G a) (A B D ⋀ + E F - / G +) b) (A B D +⋀ E F - / G +) c) (A B D ⋀ + E F/- G +) d) None of the mentioned

There is a Sequential entry that is one by one.

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.

a (First create a new node whose 'prev' points to the node pointed to by the 'prev' of tail. The 'next' of the new node should point to tail. Set the 'prev' of tail to point to new node and the 'prev' of new node to point to the new node.)

Given the Node class implementation, select one of the following that correctly inserts a node at the tail of the list. public class Node { protected int data; protected Node prev; protected Node next; public Node(int data) { this.data = data; prev = null; next = null; } public Node(int data, Node prev, Node next) { this.data = data; this.prev = prev; this.next = next; } public int getData() { return data; } public void setData(int data) { this.data = data; } public Node getPrev() { return prev; } public void setPrev(Node prev) { this.prev = prev; } public Node getNext { return next; } public void setNext(Node next) { this.next = next; } } public class DLL { protected Node head; protected Node tail; int length; public DLL() { head = new Node(Integer.MIN_VALUE,null,null); tail = new Node(Integer.MIN_VALUE,null,null); head.setNext(tail); length = 0; } } a) public void insertRear(int data) { Node node = new Node(data,tail.getPrev(),tail); node.getPrev().setNext(node); tail.setPrev(node); length++; } b) public void insertRear(int data) { Node node = new Node(data,tail.getPrev(),tail); node.getPrev().getPrev().setNext(node); tail.setPrev(node); length++; } c) public void insertRear(int data) { Node node = new Node(data,tail.getPrev(),tail); node.getPrev().setNext(tail); tail.setPrev(node); length++; } d) public void insertRear(int data) { Node node = new Node(data,head,tail); node.getPrev().setNext(node); tail.setPrev(node); length++; }

a (Set the 'next' pointer point to the head of the list and then make this new node as the head.)

How do you insert an element at the beginning of the list? a) public void insertBegin(Node node) { node.setNext(head); head = node; size++; } b) public void insertBegin(Node node) { head = node; node.setNext(head); size++; } c) public void insertBegin(Node node) { Node temp = head.getNext() node.setNext(temp); head = node; size++; } d) None of the mentioned

a (As we know that the left child is lesser than the parent, if the root's key is greater than the given key, we look only into the left sub-tree, similarly for right sub-tree.)

How to search for a key in a binary search tree? a) public Tree search(Tree root, int key) { if( root == null || root.key == key ) { return root; } if( root.key < key ) { return search(root.right,key); } else return search(root.left,key); } b) public Tree search(Tree root, int key) { if( root == null || root.key == key ) { return root; } if( root.key < key ) { return search(root.left,key); } else return search(root.right,key); } c) public Tree search(Tree root, int key) { if( root == null) { return root; } if( root.key < key ) { return search(root.right,key); } else return search(root.left,key); } d) None of the mentioned

a (Since all the elements lesser than a given node will be towards the left, iterating to the leftmost leaf of the root will give the minimum element in a binary search tree.)

How will you find the minimum element in a binary search tree? a) public void min(Tree root) { while(root.left() != null) { root = root.left(); } System.out.println(root.data()); } b) public void min(Tree root) { while(root != null) { root = root.left(); } System.out.println(root.data()); } c) public void min(Tree root) { while(root.right() != null) { root = root.right(); } System.out.println(root.data()); } d) public void min(Tree root) { while(root != null) { root = root.right(); } System.out.println(root.data()); }

DCBA

If the elements "A", "B", "C" and "D" are placed in a stack and are deleted one at a time, what is the order of removal? a) ABCD b) DCBA c) DCAB d) ABDC

a (As the root is deleted and node with value 100 is used as replaced one. There is a violation of property that root node must have value less than its children. So, there will be shuffling of node with value 100 with node of value 2. And thus 2 becomes root. And it will remain to be at root after all the possible operations. So, the value at root will be 2.)

If we implement heap as min-heap, deleting root node (value 1) from the heap. What would be the value of root node after second iteration if leaf node (value 100) is chosen to replace the root at start. a) 2 b) 100 c) 17 d) 3

*EnQueue:* public void insert(int i) { if (rear==-1) { front = 0; rear = 0; Queue[rear] = i; } else if(rear+1 >= size) throw new IndexOutOfBoundsException("Overflow Exception"); else if(rear+1 < size) Queue[++rear] = i; len++; } *DeQueue:* public int remove() { if (isEmpty()) throw new NoSuchElementException("Underflow Error"); else { len--; int ele = Queue[front]; if (front == rear) { front = -1; rear = -1; } else front++; return ele; } }

Implement the java code for the basic operations (EnQueue, DeQueue) of Queue data structure.

Pop

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

b) (The left and right children are added first to the stack, followed by the node, which is then popped. Post-order follows L-R-N policy.)

Select the code snippet that performs post-order traversal iteratively. a) public void postorder(Tree root) { if (root == null) return; Stack<Tree> stk = new Stack<Tree>(); Tree node = root; while (!stk.isEmpty() || node != null) { while (node != null) { if (node.right != null) stk.add(node.left); stk.add(node); node = node.right; } node = stk.pop(); if (node.right != null && !stk.isEmpty() && node.right == stk.peek()) { Trees nodeRight = stk.pop(); stk.push(node); node = nodeRight; } else { System.out.print(node.data + " "); node = null; } } } b) public void postorder(Tree root) { if (root == null) return; Stack<Tree> stk = new Stack<Tree>(); Tree node = root; while (!stk.isEmpty() || node != null) { while (node != null) { if (node.right != null) stk.add(node.right); stk.add(node); node = node.left; } node = stk.pop(); if (node.right != null && !stk.isEmpty() && node.right == stk.peek()) { Trees nodeRight = stk.pop(); stk.push(node); node = nodeRight; } else { System.out.print(node.data + " "); node = null; } } } c) public void postorder(Tree root) { if (root == null) return; Stack<Tree> stk = new Stack<Tree>(); Tree node = root; while (!stk.isEmpty() || node != null) { while (node != null) { if (node.right != null) stk.add(node.right); stk.add(node); node = node.left; } node = stk.pop(); if (node.right != null) { Trees nodeRight = stk.pop(); stk.push(node); node = nodeRight; } else { System.out.print(node.data + " "); node = null; } } } d) None of the mentioned

AB×CD/+

The postfix form of A×B+C/D is? a) ×AB/CD+ b) AB×CD/+ c) A×BC+/D d) ABCD+/×

Time and space

Two main measures for the efficiency of an algorithm are A. Processor and memory B. Complexity and capacity C. Time and space D. Data and space

Each node has only one pointer to traverse the list back and forth (Memory efficient doubly linked list has been proposed recently which has only one pointer to traverse the list back and forth. The implementation is based on pointer difference.)

What is a memory efficient double linked list? a) Each node has only one pointer to traverse the list back and forth b) The list has breakpoints for faster traversal c) An auxiliary singly linked list acts as a helper list to traverse through the doubly linked list d) None of the mentioned

c (A pointer is made to point at the first element in the list and one more to point to the second element, pointer manipulations are done such that the first element is no longer being pointed by any other pointer, its value is returned.)

What is the functionality of the following piece of code? public Object delete_key() { if(count == 0) { System.out.println("Q is empty"); System.exit(0); } else { Node cur = head.getNext(); Node dup = cur.getNext(); Object e = cur.getEle(); head.setNext(dup); count--; return e; } } a) Delete the second element in the list b) Return but not delete the second element in the list c) Delete the first element in the list d) Return but not delete the first element in the list

X

What is the result of the following operation Top (Push (S, X)) a) X b) Null c) S d) None

Overflow

What is the term for inserting into a full queue known as? a) overflow b) underflow c) null pointer exception d) all of the mentioned

a) (Dequeue removes the first element from the queue, and 'front' points to the front end of the queue. Note that even though option d is performing the dequeue operation, it is returning from the function before decrementing the count value.)

Which of the following represents a dequeue operation? (count is the number of elements in the queue) a) public Object dequeue() { if(count == 0) { System.out.println("Queue underflow"); return 0; } else { Object ele = q[front]; q[front] = null; front = (front+1)%CAPACITY; count--; return ele; } } b) public Object dequeue() { if(count == 0) { System.out.println("Queue underflow"); return 0; } else { Object ele = q[front]; front = (front+1)%CAPACITY; q[front] = null; count--; return ele; } } c) public Object dequeue() { if(count == 0) { System.out.println("Queue underflow"); return 0; } else { front = (front+1)%CAPACITY; Object ele = q[front]; q[front] = null; count--; return ele; } } d) public Object dequeue() { if(count == 0) { System.out.println("Queue underflow"); return 0; } else { Object ele = q[front]; q[front] = null; front = (front+1)%CAPACITY; return ele; count--; } }

Stack is the FIFO data structure

Which of the following statement(s) about stack data structure is/are NOT correct? a) Linked List are used for implementing Stacks b) Top of the Stack always contain the new node c) Stack is the FIFO data structure d) Null link is present in the last node at the bottom of the stack

*Stack ADT* A Stack contains elements of same type arranged in sequential order. All operations takes place at a single end that is top of the stack and following operations can be performed: *push()* - Insert an element at one end of the stack called top. *pop()* - Remove and return the element at the top of the stack, if it is not empty. *peek()* - Return the element at the top of the stack without removing it, if the stack is not empty. *size()* - Return the number of elements in the stack. *isEmpty()* - Return true if the stack is empty, otherwise return false. *isFull()* - Return true if the stack is full, otherwise return false. *Queue ADT* A Queue contains elements of same type arranged in sequential order. Operations takes place at both ends, insertion is done at end and deletion is done at front. Following operations can be performed: *enqueue()* - Insert an element at the end of the queue. *dequeue()* - Remove and return the first element of queue, if the queue is not empty. *peek()* - Return the element of the queue without removing it, if the queue is not empty. *size()* - Return the number of elements in the queue. *isEmpty()* - Return true if the queue is empty, otherwise return false. *isFull()* - Return true if the queue is full, otherwise return false.

Explain all the ADT's for Stack and Queue Data structure


Related study sets

Human Resource Management Chapter 13

View Set

NCLEX Questions ~ End of Life Care

View Set

accounting software applications

View Set