GATE CS Arrays, Stacks and Queues questions
Practise Arrays, Stacks and Queues questions for GATE CS. Explore official PYQs and original topic-wise quizzes, check answers and view available solutions. Free, no sign-in.
Subject, topic, year and type filter the full library. Match any choice within a filter, and all selected filter categories. Search, source and sort apply to this page.
20 on this page
Consider a hash table with slots. The hash function is . The collisions are resolved by chaining. The following keys are inserted in the order: . The maximum, minimum, and average chain lengths in the hash table, respectively, are
Suppose a stack implementation supports an instruction , which reverses the order of elements on the stack, in addition to the and instructions. Which one of the following statements is (with respect to this modified stack)?
Consider the C function given below. Assume that the array contains elements, sorted in ascending order. int ProcessArray(int *listA, int x, int n) { int i, j, k; i = 0; j = n-1; do { k = (i+j)/2; if (x <= listA[k]) j = k-1; if (listA[k] <= x) i = k+1; } while (i <= j); if (listA[k] == x) return(k); else return -1; } Which …
Consider a hash table with slots. Collisions are resolved using chaining. Assuming simple uniform hashing, what is the probability that the first slots are unfilled after the first insertions?
The procedure given below is required to find and replace certain characters inside an input character string supplied in array . The characters to be replaced are supplied in array , while their respective replacement characters are supplied in array . Array has a fixed length of five characters, while arrays and …
The procedure given below is required to find and replace certain characters inside an input character string supplied in array . The characters to be replaced are supplied in array , while their respective replacement characters are supplied in array . Array has a fixed length of five characters, while arrays and …
Consider the following operation along with Enqueue and Dequeue operations on queues, where is a global parameter. MultiDequeue(Q){ m = k while (Q is not empty) and (m > 0) { Dequeue(Q) m = m – 1 } } What is the worst case time complexity of a sequence of queue operations on an initially empty queue?
Suppose a circular queue of capacity elements is implemented with an array of elements. Assume that the insertion and deletion operations are carried out using and as array index variables, respectively. Initially, . The conditions to detect queue full and queue empty …
A hash table of length uses open addressing with hash function , and linear probing. After inserting values into an empty hash table, the table is shown as below …
A hash table of length uses open addressing with hash function , and linear probing. After inserting values into an empty hash table, the table is shown as below …
The keys and are inserted into an initially empty hash table of length using open addressing with hash function and linear probing. What is the resultant hash table?
Consider a hash table of size seven, with starting index zero, and a hash function . Assuming the hash table is initially empty, which of the following is the contents of the table when the sequence is inserted into the table using closed hashing? Note that − denotes an empty location in the table.
An implementation of a queue , using two stacks and , is given below: void insert (Q, x) { push (S1, x); } void delete (Q) { if (stack-empty(S2)) then if (stack-empty(S1)) then { print(“Q is empty”); return; } else while (!(stack-empty(S1))){ x=pop(S1); push(S2,x); } x=pop(S2); } Let insert and delete operations be …
A program reads in integers in the range representing the scores of students. It then prints the frequency of each score above . What would be the best way for to store the frequencies?
Given the following input and the hash function mod , which of the following statements are true? hash to the same value hash to the same value All elements hash to the same value Each element hashes to a different value
The best data structure to check whether an arithmetic expression has balanced parentheses is a
A single array is used to implement two stacks. The two stacks grow from opposite ends of the array. Variables and point to the location of the topmost element in each of the stacks. If the space is to be used efficiently, the condition for is
Let S be a stack of size . Starting with the empty stack, suppose we push the first n natural numbers in sequence, and then perform pop operations. Assume that Push and Pop operations take seconds each, and seconds elapse between the end of one such stack operation and the start of the next operation. For , define the …
What is the minimum number of stacks of size required to implement a queue of size ?
An array is defined as follows: for all The sum of the elements of the array is
