Python Test 2
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 on stack are
1
Convert the following infix expression to postfix 10 + 3 * 5 / (16 - 4) .
10 3 5 * 16 4 - / +
In a doubly linked list, the number of pointers affected for an insertion operation at the beginning or end of a doubly linked list will be
2
The minimum number of fields or instance variables with each node of a doubly linked list is
3
What is the output of the following code? def some_func(n): if n <= 1: return n else: return(some_func(n-1) + some_func(n-2)) print(some_func(4))
3
In a doubly linked list, the number of pointers affected for an insertion operation in the middle of the doubly linked list will be
4
What is the result of evaluating the following: 17 10 + 3 * 9 / == ?
9
Three Rules of Recursion
A recursive algorithm must have a base case. A recursive algorithm must change its state and move toward the base case. A recursive algorithm must call itself, recursively.
What are the time complexities of finding the 8th element from the beginning and the 8th element from the end in a singly linked list? Let n be the number of nodes in the linked list, you may assume that n >8.
O(1) and O(n)
The time required to search an element in a linked list of length n is
O(n)
Which of the following uses the FIFO method?
Queue
A data item entered into a linear data structure stays in that position relative to the other elements that came before and after it.
True
a problem solved with recursion can also be solved using iteration
True
The last node in a singly linked list points to
a None pointer
If new data needs to be added to a linked list, the program simply_________________ and inserts it into the series.
allocates/creates another node
The _____________ of a linked list points to the first node in the list
head
You are given pointers to the first and last nodes of a singly linked list, which of the following operations are dependent on the length of the linked list?
delete the last element of the list
Consider an implementation of an unsorted singly linked list. Suppose it has its representation with a head and a tail pointer (i.e. pointers to the first and last nodes of the linked list). (Reminder: single linked list does not have a built in previous pointer). Given the representation, which of the following operation can not be implemented in O(1) time ?
deletion of the last node of the linked list
In the worst case, the number of comparisons needed to search a singly linked list of length n for a given element is
n
A linked list is a series of connected
nodes
What method is used to view the next element to be removed from a stack?
peek()
A node in the doubly linked list keeps track of the next node in the list as well as
the previous node
If the head pointer points to None, this indicates
there are no nodes in the list
