DataStruc Reviewer

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

a

Convert the following Infix expression to Postfix form using a stack. x + y * z + (p * q + r) * s, Follow usual precedence rule and assume that the expression is legal. a) xyz*+pq*r+s*+ b) xyz*+pq*r+s+* c) xyz+*pq*r+s*+ d) xyzp+**qr+s*+

T

LIFO stands for Last In First Out.(T/F)

T

Searching, inserting, and deleting require traversal of the linked list.(T/F)

c

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

infix

Which of the following notations requires the use of parenthesis? a.prefix b.infix c.postfix d.Polish

top

public DataElement operationY() throws StackUnderflowException { if(isEmptyStack()) throw new StackUnderflowException(); DataElement temp = list[stackTop - 1].getCopy(); return temp; }//end top Which stack operation is defined by operationY above? a.pop b.push c.top d.isEmptyStack

38 45 23

public class StackProgram { public static void main(String[] args) { StackClass intStack = new StackClass(50); StackClass tempStack = new StackClass(); try { intStack.push(new IntElement(23)); intStack.push(new IntElement(45)); intStack.push(new IntElement(38)); } catch(StackOverflowException sofe) { System.out.println(sofe.toString()); System.exit(0); } tempStack.copyStack(intStack); System.out.print("tempStack elements: "); while(!tempStack.isEmptyStack()) { System.out.print(tempStack.top() + " "); // output 1 tempStack.pop(); } System.out.println(); System.out.println("The top element of intStack: " + intStack.top()); // output 2 } } 9. What is output 1 above? a.38 23 45 b.23 38 45 c.23 38 43 d.38 45 23

push

public void operationX(DataElement newItem) throws StackOverflowException{ if(isFullStack()) throw new StackOverflowException(); list[stackTop] = newItem; stackTop++; } Which stack operation does operationX above define? a.pop b.push c.top d.initializeStack

node

The data type of each ____ depends on the specific application. a.address b.link c.list d.node

T

A doubly linked list can be traversed in either direction.(T/F)

a

A linear collection of data elements where the linear node is given by means of pointer is called? a) Linked list b) Node list c) Primitive list d) Unordered list ​

T

Adding an element to a full stack and removing an element from an empty stack generate errors or exceptions called stack overflow exception and stack underflow exception.(T/F)

The element at the bottom

Which element of a stack has been in the stack the longest? a.The element at the top b.The element in the middle c.All elements in a stack have been there the same amount of time d.The element at the bottom

b

Assume that the operators +,-, X are left associative and ^ is right associative. The order of precedence (from highest to lowest) is ^, X, +, -. The postfix expression for the infix expression a + b X c - d ^ e ^ f is? a) abc X+ def ^^ - b) abc X+ de^f^ - c) ab+c Xd - e ^f^ d) -+aXbc^ ^def

d

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

1)newNode 2)null, item, null 3)head 4)tail = newNode; 5)null, item, head 6)head = newNode

Fill in the missing code to add new node to the first node. public void addToHead(int item){ if(isEmpty()){ Node __1)_______ = new Node(_2)______ ); __3)______ = newNode; ____4)____; } else{ Node newNode = new Node( ___5)______ ); ____6)_______ ; head.next.previous = head; } }

c

Linked list data structure offers considerable saving in _____________ a) Computational Time b) Space Utilization c) Space Utilization and Computational Time d) Speed Utilization

a

Linked list is considered as an example of ___________ type of memory allocation. a) Dynamic b) Static c) Compile time d) Heap

d

Linked lists are not suitable for the implementation of ___________ a) Insertion sort b) Radix sort c) Polynomial manipulation d) Binary search

b

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

d

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

a

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

traversal

Searching through a linked list or inserting an item in a linked list requires a ____ of the list. a.copy b.review c.traversal d.deletion

7

StackClass s = new StackClass(50); int x, y, z; s.push(new IntElement(3)); s.push(new IntElement(7)); x = s.pop(); s.push(new IntElement(5)); y = s.pop(); z = s.pop(); Given the sequence of operations above, what is the value of x? a.7 b.0 c.3 d.5

a reference variable not in the list

Which of the following should be used to traverse a list? a.the tail of the list b.a reference variable not in the list c.the head of the list d.any node in the list

C

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 ​

d

Which of these is not an application of a linked list? a) To implement file systems b) For separate chaining in hash-tables c) To implement non-binary trees d) Random Access of elements

current=current.back;

public void reversePrint ( ) { DoublyLinkedListNode current; // variable to traverse the list current=last; //set current to point to the last node while(current!=null) { System.out.print(current.info + " "); //Missing statement }//endwhile }//endreversePrint Which of the following is the "missing statement" in the code above? a.current=head.back; b.current=current.back; c.current=last.back; d.current=first.back;

b

Consider an implementation of unsorted singly linked list. Suppose it has its representation with a head pointer only. Given the representation, which of the following operation can be implemented in O(1) time? i) Insertion at the front of the linked list ii) Insertion at the end of the linked list iii) Deletion of the front node of the linked list iv) Deletion of the last node of the linked list a) I and II b) I and III c) I, II and III d) I, II and IV

a

Consider the following definition in c programming language. struct node { int data; struct node * next; } typedef struct node NODE; NODE *ptr; Which of the following c code is used to create new node? a) ptr = (NODE*)malloc(sizeof(NODE)); b) ptr = (NODE*)malloc(NODE); c) ptr = (NODE*)malloc(sizeof(NODE*)); d) ptr = (NODE)malloc(sizeof(NODE));

a

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 is? a) 1 b) 2 c) 3 d) 4

b

Consider the usual algorithm for determining whether a sequence of parentheses is balanced. Suppose that you run the algorithm on a sequence that contains 2 left parentheses and 3 right parentheses (in some order). The maximum number of parentheses that appear on the stack AT ANY ONE TIME during the computation? a) 1 b) 2 c) 3 d) 4 or more

c

Consider the usual algorithm for determining whether a sequence of parentheses is balanced. The maximum number of parentheses that appear on the stack AT ANY ONE TIME when the algorithm analyzes: (()(())(()))? a) 1 b) 2 c) 3 d) 4 or more

a

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) (A B D E F + ⋀ / - G +)

int item null, item, null newNode tail tail, item, null tail = NewNode

Fill in the missing code to add to add to last node. public void addToTail( ________ ){ if(isEmpty()){ Node newNode = new Node(__________ ); head = ________ ; _______ = newNode; } else{ Node newNode = new Node( _________ ); _______ ; tail.previous.next = tail; } }

current Node p tail.item addToTail(item) current !=null current.next newNode q current = current.next

Fill in the missing code to complete the method in inserting a node after specific node. public void insertAfter(int item, int target) { Node ________ = head; ________ , q; if(target == ________ ){ __________; } else { while( __________ ) { p = current; q = _________ ; Node newNode = new Node(p, item, q); if(current.item == target && target != tail.item) { p.next = ________ ; p.next.previous = current; newNode.next = _______; newNode.next.previous = newNode; } ________ ; } } } ​

head == tail tail = null head head.previous

Fill in the missing code to remove the first node from the doubly linked-list. public void removeFromHead(){ if(isEmpty()){ System.out.println("You cannot remove a null value."); } else if(______ ) { head = null; ______ ; } else { _______ = head.next; _________ = null; } }

tail == head tail.previous tail.next

Fill in the missing code to remove the last node from the doubly linked-list. public void removeFromTail(){ if(isEmpty()){ System.out.println("You cannot remove a null value."); } else if( _______ ) { head = null; tail = null; } else { tail = ________ ; ______ = null; } }

F

For a doubly linked list to function properly, every node does not have to have a back and a next reference variable.(T/F)

head

The reference variable head points to the address of the first node, the first node contains the address of____. a.head b.first node c.second node d.tail

d

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

a

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

b

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

c

In Linked List implementation, a node carries information regarding ___________ a) Data b) Link c) Data and Link d) Node

last

In a doubly linked list , every node contains the address of the next node and the previous node except for the ____ node. a.second to last b.middle c.last d.first

two

In a doubly linked list, some of the operations require modification from how they were implemented for a regular linked list, because of the ____ reference variable(s) in each node. a.four b.three c.two d.null

T

In a linked list implementation of a stack you must keep track of the address of the top element of the stack.(T/F)

F

In a linked list implementation of a stack, only a fixed number of elements can be pushed onto the stack.(T/F)

T

In a linked list implementation of a stack, the reference variable to the top of the stack is set to NULL.(T/F)

c.Head points to the next node of head. The previous of head is set to null

In a non-empty doubly linked listLinks to an external site., which of the following is the correct statement in deleting the first node? a.Head points to the previous of head . The next of head is set to null. b.Head points to null. The previous of head is also null. c.Head points to the next node of head. The previous of head is set to null d.Head points to the previous of tail.

a

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

initializeStack

In an array-based stack, which of the following operations has a time-complexity of O(n)? a.deleteStack b.copyStack c.constructor d.initializeStack

c

In linked list each node contains a minimum of two fields. One field is data field to store the data second field is? a) Pointer to character b) Pointer to integer c) Pointer to node d) Node

b

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

A node somewhere in memory and stores the address of the newly created node.

The statement : newNode = new Node() creates: a.A node somewhere in memory and stores the address of the newly created node. b.An address somehere in memory and stores the node in the address. c.An address somewhere in the processor and stores the node. d.A node somewhere in the processor and stores it in the address.

b

What does the following function do for a given Linked List with first node as head? void fun1(struct node* head) { if(head == NULL) return; fun1(head->next); printf("%d ", head->data); } a) Prints all nodes of linked lists b) Prints all nodes of linked list in reverse order c) Prints alternate nodes of Linked List d) Prints alternate nodes in reverse order

(n + m) * p

What is the equivalent infix expression for the postfix expression n m + p * ? a.n + m * p b.p * n + m c.m + (p * n) d.(n + m) * p

5

StackClass s = new StackClass(50); int x, y, z; s.push(new IntElement(3)); s.push(new IntElement(7)); x = s.pop(); s.push(new IntElement(5)); y = s.pop(); z = s.pop(); Given the sequence of operations above, what is the value of y? a.3 b.7 c.5 d.0

3

StackClass s = new StackClass(50); int x, y, z; s.push(new IntElement(3)); s.push(new IntElement(7)); x = s.pop(); s.push(new IntElement(5)); y = s.pop(); z = s.pop(); Given the sequence of operations above, what is the value of z? a.3 b.5 c.7 d.0

head

Suppose the head points to the first and only node in the list, where will the tail point? a.head b.tail.next c.head.next d.tail

c

The concatenation of two lists can be performed in O(1) time. Which of the following variation of the linked list can be used? a) Singly linked list b) Doubly linked list c) Circular doubly linked list d) Array implementation of list

a

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

F

The equivalent postfix expression for the infix expression a + b is + a b.(T/F)

addToHead

The following methods require a list to be traversed except: a.search b.addToHead c.delete d.insert

T

The head always point to the first node.(T/F)

T

The insertion of a node in a doubly linked list requires the adjustment of two links in certain nodes.(T/F)

F

The postfix expression 2 3 + 1 * evaluates to 8.(T/F)

b

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

c

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 /

c

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

d

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

c

The type of expression in which operator succeeds its operands is? a) Infix Expression b) Prefix Expression c) Postfix Expression d) Both Prefix and Postfix Expressions

F

To print the list, the head is used to traverse the list.(T/F)

T

We must traverse the list using another reference variable of the same type as head.(T/F)

b

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

c

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

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

a

What is the result of the following operation? Top (Push (S, X)) a) X b) X+S c) S d) XS

a

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)

d Explanation: Depending on whether the array is full or not, the complexity in dynamic array varies. If you try to insert into an array that 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

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)

b

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) O(n2)

O(1)

What is the time-complexity to insert an item at the end of a linked list? a.O(1) b.O(n) c.O(n2) d.O(log n)

O(n)

What is the time-complexity to print a linked list? a.O(n2) b.O(1) c.O(n) d.O(log n)

15

What is the value of the postfix expression 2 3 + 4 6 3 / - * 5 + ? a.15 b.37 c.25 d.5

d

What is the value of the postfix expression 6 3 2 4 + - *? a) 1 b) 40 c) 74 d) -18

23

What is the value of the postfix expression: 5 4 * 3 +? a.23 b.27 c.17 d.35

d

What kind of linked list is best to answer questions like "What is the item at position n?" a) Singly linked list b) Doubly linked list c) Circular linked list d) Array implementation of linked list

c Explanation: In case of a linked list having n elements, we need to travel through every node of the list to add the element at the end of the list. Thus asymptotic time complexity is θ(n).

What would be the asymptotic time complexity to add a node at the end of singly linked list, if the pointer is initially pointing to the head of the list? a) O(1) b) O(n) c) θ(n) d) θ(1)

b

What would be the asymptotic time complexity to find an element in the linked list? a) O(1) b) O(n) c) O(n2) d) O(n4)

a

What would be the asymptotic time complexity to insert an element at the front of the linked list (head is known)? a) O(1) b) O(n) c) O(n2) d) O(n3)

a

What would be the asymptotic time complexity to insert an element at the second position in the linked list? a) O(1) b) O(n) c) O(n2) d) O(n3)

nodes

Which answer most accurately completes the following sentence: A linked list is made up of ____. a.classes b.addresses c.memory variables d.nodes

d

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

b

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

d

Which of the following is not a disadvantage to the usage of array? a) Fixed size b) There are chances of wastage of memory space if elements inserted in an array are lesser than the allocated size c) Insertion based on position d) Accessing elements at specified positions

d

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

d

Which of the following is not the application of stack? a) A parentheses balancing program b) Tracking of local variables at run time c) Compiler Syntax Analyzer d) Data Transfer between two asynchronous process

Head.item

Which of the following is the statement to display the first node in the linked listLinks to an external site.? a.Item.head b.Head.next.item c.Item.data d.Head.item

a

Which of the following piece of code has the functionality of counting the number of elements in the list? a) public int length(Node head) { int size = 0; Node cur = head; while(cur!=null) { size++; cur = cur.getNext(); } return size; } b) public int length(Node head) { int size = 0; Node cur = head; while(cur!=null) { cur = cur.getNext(); size++; } return size; } c) public int length(Node head) { int size = 0; Node cur = head; while(cur!=null) { size++; cur = cur.getNext(); } }

d

Which of the following points is/are not true about Linked List data structure when it is compared with an array? a) Arrays have better cache locality that can make them better in terms of performance b) It is easy to insert and delete elements in Linked List c) Random access is not allowed in a typical implementation of Linked Lists d) Access of elements in linked list takes less time than compared to arrays


Kaugnay na mga set ng pag-aaral

PN adult medical surgical online practice 2017 B

View Set

AP BIO Chapter 17 Mastering Biology

View Set

Client Assesment PrepU Chapter 15 Assesing Head and Neck

View Set

Mike Meyers Network+ N10-008 #UnderConstruction

View Set

HW 1 - Displaying Distributions with Graphs

View Set