GATE CS Programming and Data Structures questions
Practise Programming and Data Structures questions for GATE CS. Explore official PYQs and original subject-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 the following program in C: #include <stdio.h> void func(int i, int j) { if(i < j) { int i = 0; while (i < 10) { j += 2; i++; } } printf("%d", i); } int main() { int i = 9, j = 10; func(i, j); return 0; } The output of the program is . (answer in integer) Note: Assume that the program compiles and runs successfully.
Consider the following code snippet in C language that computes the number of nodes in a non-empty singly linked list pointed to by the pointer variable head. struct node{ int elt; struct node *next; }; int getListSize (struct node *head) { if( E1 ) return 1; return E2; } Which one of the following options gives the correct replacements for the expressions …
The set represents various traversals over binary tree. The set represents the order of visiting nodes during a traversal. …
In C runtime environment, which one of the following is stored in heap?
Consider the following three ANSI-C programs, and . …
Consider a stack and a queue . Both of them are initially empty and have the capacity to store ten elements each. The elements , and arrive one by one, in that order. When an element arrives, it is assigned either to (pushed on ) or to (enqueued to ). Once all the five elements are stored, the output is …
Consider the following ANSI-C program. #include <stdio.h> int main(){ int *ptr, a, b, c; a=5; b=11; c=20; ptr=&a; *ptr=c; ptr=&c; a=*(&b); c=*ptr-a; printf("%d",c); return(0); } The output of this program is . (answer in integer) Note: Assume that the program compiles and runs successfully.
Consider the following ANSI-C function. int func(int start, int end){ int length=end+1-start; if((length<1)||(start<0)||(end<0)){ return(0); } if(length%3==0){ return(func(start+1, end)); }else if(length%3==1){ return(1+func(start, end-1)); }else { return(func(start+2, end)); } } The maximum possible value that can be returned from this function is …
Which of the following statement(s) is/are TRUE for any binary search tree (BST) having distinct integers?
#include <stdio.h> void foo(int *p, int x) { *p=x; } int main(){ int *z; int a = 20, b = 25; z = &a; foo(z,b); printf("%d",a); return 0; } The output of the given program is __________. (Answer in integer)
The height of any rooted tree is defined as the maximum number of edges in the path from the root node to any leaf node. Suppose a Min-Heap stores keys. The height of is ___________. (Answer in integer)
#include <stdio.h> int foo(int S[],int size) { if(size == 0) return 0; if(size == 1) return 1; if(S[0] != S[1]) return 1+foo(S+1,size-1); return foo(S+1,size-1); } int main() { int A[]={0,1,2,2,2,0,0,1,1}; printf("%d",foo(A,9)); return 0; } The value printed by the given program is ___________. (Answer in integer)
Let be a datatype for an implementation of linked list defined as follows: typedef struct list { int data; struct list *next; } LIST; Suppose a program has created two linked lists, and , whose contents are given in the figure below (code for creating and is not provided here). contains nodes, and …
Consider the following C program: #include <stdio.h> int gate (int n) { int d, t, newnum, turn; newnum = turn = 0; t=1; while (n>=t) t *= 10; t /=10; while (t>0) { d = n/t; n = n%t; t /= 10; if (turn) newnum = 10*newnum + d; turn = (turn + 1) % 2; } return newnum; } int main () { printf ("%d", gate(14362)); return 0; } The value printed by the …
Consider the following C program: #include<stdio.h> int main(){ int a; int arr[5] = {30,50,10}; int *ptr; ptr = &arr[0] + 1; a = *ptr; (*ptr)++; ptr++; printf("%d", a + (*ptr) + arr[1]); return 0; } The output of the above program is _________. (Answer in integer)
Consider the following C program: #include <stdio.h> int g(int n) { return (n+10); } int f(int n) { return g(n*2); } int main() { int sum, n; sum=0; for (n=1; n<3; n++) sum += g(f(n)); printf ("%d", sum); return 0; } The output of the given C program is ___________. (Answer in integer)
Consider a binary tree in which every node has either zero or two children. Let be the number of nodes in . Which ONE of the following is the number of nodes in that have exactly two children?
Consider the following C program: #include <stdio.h> void stringcopy (char *, char *); int main() { char a[30] = "@#Hello World!"; stringcopy(a, a+2); printf("%s\n",a); return 0; } void stringcopy(char *s, char *t) { while (*t) *s++=*t++; } Which one of the following will be the output of the program?
int x=126,y=105; do { if(x>y) x=x-y; else y=y-x; } while(x!=y); printf("%d",x); The output of the given C code segment is _________. (Answer in integer)
Suppose the values are inserted in that order into an initially empty binary search tree. Let be the resulting binary search tree. The number of edges in the path from the node containing to the root node of is _________. (Answer in integer)
