0% found this document useful (0 votes)
5 views

technical_training

Uploaded by

professortate3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

technical_training

Uploaded by

professortate3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 106

Computer Networks MCQ (Multiple Choice Questions)

1. Type field in IEEE 802.3 (wired ethernet) frame format is used for

A) Multiplexing

B) De-multiplexing

C) Both

D) None

ANSWER: C

Explanation: Layer 2 has to handle more than one protocol ans layer 3 - IPv4,IPv6.
Multiplexing required when host transmits and de-multplexing when host receives data

2. MAC address length

A) 12 hex digits

B) 8 hex digits

C) 4 hex digits

D) 32 hex digits

ANSWER: A

Explanation: 48 bits ( or 12 hex digdits)

3. Packet switching used by

A) LAN

B) WAN

C) WLAN

D) All

ANSWER: D
Explanation: All are data communication networks and use packet switching

4. CSMA/CD needed in

A) Bus topology

B) Full duplex switched ethernet - 8 port

C) Full duplex switched ethernet - 16 port

D) Full duplex switched ethernet - 24 port

ANSWER: A

Explanation: Full-duplex switched ethernet - no collision

5. The protocol used to dynamically bind an IPv4 address to a hardware (MAC) address

A) ARP

B) TCP

C) UDP

D) IPv4

ANSWER: A

Explanation: Address Resolution Protocol (Layer 3 address - Layer 2 address)

6. WLAN (WiFi) differs from Wired ethernet in

A) TCP/IP layer 2, 3

B) TCP/IP layer 1, 2

C) TCP/IP layer 1 , 3

D) All 5 layers

ANSWER: B

Explanation: Layer 1 and 2 only. Layer 1 - wireless vs wire , layer 2 frame formats differ
7. WiFi depoloyment in campus uses

A) Infrastructure mode

B) Infrastructure mode and wired LAN

C) Adhoc mode

D) Adhoc mode and wired ethernet

ANSWER: B

Explanation: Has APs and internet connectivity thru wired LAN / Router. AP- AP thru wired
LAN

8. WiFi Access Point (AP)

A) Wireless interface

B) Wired interface

C) Both

D) None

ANSWER: C

Explanation:Wireless interface for stations and wired interface to connect to wired LAN

9. WiFi frame types

A) Control

B) Data

C) Management

D) All

ANSWER: D

Explanation: All
10. WiFi provides

A) Authentication

B) Privacy using encryption

C) Deauthentication

D) All

ANSWER: D

Explanation: All three

11. Two sites of an organization have set up a VPN. This VPN uses

A) IPSec in transport mode

B)Ipsec in tunnel mode

C) Transport or tunnel

D) None

ANSWER: B

Explanation: IP-in-IP tunnelling

12. Protocol used by gmail to provide encryption

A) TLS

B) IPSec

C) SCTP

D) DNS

ANSWER: A

Explanation: TLS (Transport Layer Security)


13. IPv4 header fields used by firewall (packet filter)

A) Source address

B) destination address

C) proto

D) All of above

ANSWER: D

Explanation: All 3 plus transport layer header port numbers

14. in IPsec transport mode, the correct order for layers (top down)

A) Transport, IPSec, network

B) ipsec transport network

C) transport network ipsec

D) None

ANSWER: A

Explanation: Transport, IPSec, network

15. SSL adds the following to socket API

A) Authentication

B) encryption

C) Both

D) None

ANSWER: C

Explanation: Adds both


16. Linux command ifconfig displays

A) IP address

B) MAC address

C) Mask

D) All of above and more

ANSWER: D

Explanation:All of above and more - packet statistics for example

17. Internet standards development organization

A) ITU-T

B) IETF

C) IEEE

D) ETSI

ANSWER: B

Explanation: IETF - Internet Engineering Task Force

18. Separation of control plane and data plane in a network device

A) SDN

B) NFV

C) IOT

D) Cloud

ANSWER: A

Explanation: SDN controller external to network device

19. Which of the following displayed by wireshark tool


A) Time stamp

B) Source ip

C) destination ip

D) All

ANSWER: D

Explanation: All three and more like protocol

20. Run network functions on general-purpose server hardware

A) SDN

B) NFV

C) IOT

D) CLOUD

ANSWER: B

Explanation:Implement network functions in software running on general purpose server


hardawre

21. HTTP

A) Uses UDP and Request-response model

B) Uses TCP and Request-response model

C) Uses UDP and subscribe-publish model

D) Uses TCP and subscribe-publish model

ANSWER: B

Explanation: Uses TCP and Request-response model

22. Widely used VoIP signalling protocol

A) MGCP
B) MEGACO

C) SIP

D) H.323

ANSWER: C

Explanation: session Initiation Protocol (sip)

23. Media protocol used in VoIP

A) RTP

B) RTCP

C) BOTH

D) SDP

ANSWER: A

Explanation: Real-time transport protocol. RTCP used as companion protocol (out of band
data)

24. DNS - name server uses

A) UDP and port 53

B) SCTP and port 53

C) UDP and port 54

D) SCTP and port 54

ANSWER: A

Explanation: UDP and well-known port 53

25. TCP/IP Network Management protocol - SNMP

A) Monitor functioning of network element - router


B) Control functioning of network element - router

C) Both

D) None

ANSWER: C

Explanation: Monitor and control

26. Network byte order is

A) Little endian

B) Big endian

ANSWER: B

Explanation: Big endian

27. Real world web servers are

A) Sequential server

B) Concurrent server

ANSWER: B

Explanation: Concurrent servers

28. Socket APIs are used by

A) client application

B) server application
C) Both

ANSWER: C

Explanation: Both have to use

29. Socket API connect is used by

A) TCP server

B) UDP server

C) TCP client

D) UDP client

ANSWER: C

Explanation: TCP client only

30. Socket descriptor (integer) is returned by

A) Socket function

B) accept function

C) Both

ANSWER: C

Explanation: socket and accept (used by TCP server) return integer

31. IPv4 address length

A) 32 bits

B) 64 bits

C) 16 bits
D) 128 bits

ANSWER: A

EXPLANATION: 32 bits

32. protocol field in IPv4 header is used for

A) Multiplexing

B) De-multiplexing

C) Both

D) None

ANSWER: C

Explanation: Layer 4 has more than on protocol. Multiplexing required when host transmits
and de-multplexing when host receives data

33. IPv4 layer

A) Connectionless

B) Best effort delivery of datagrams

C) Both

D) None

ANSWER: C

Explanation: Connectionless and no error checking for datagram payload

34. Reassembly of IPv4 fragments done by

A) Destination host

B) Last router in packet path

ANSWER: A
Explanation: Fragmentation by routers along the path if required and reassembly by
Destination host

35. Subnetting allows connecting multiple physical networks (LANs) in a site to internet using
single net id

A) False

B) True

ANSWER: B

Explanation: Host id part - initial few bits used for subnet id

36. IPv4 and IPv6 can coexist in layer 3

A) True

B) False

ANSWER: A

Explanation: App can decide to use IPv4 or IPv6

37. In IPv4 127.0.0.1 is loopback address

A) False

B) True

ANSWER: B

Explanation: Used to test client and server on same host

38. IPv6 address length

A) 32 bits
B) 128 bits

C) 48 bits

D) 16 bits

ANSWER: B

Explanation: 128 bts

39. Which of the following is correct?

A) IPv6 uses colon hex notation and :: used to compress a run of 1s

B) IPv6 uses colon hex notation and :: used to compress a run of 0s

ANSWER: B

Explanation: :: used for zero compression

40. Two addresses in IPv6 but not in IPv4

A) Multi cast and anycast

B) Multi cast and link-local

C) Anycast and link-local

ANSWER: C

EXPLANATION: Link-local address formed during boot time and anycast also new in IPV6

41. Well-known (reserved) port number is used

A. Standard apllication - server side

B. Standard apllication - client side

C. Both A and B

ANSWER:A

EXPLANATION: standrad application server side only . Http - 80


42. Protocol port number length

A. 32 bits

B. 128 bits

C. 16 bits

D. 48 bits

ANSWER:16

EXPLANATION: 16 bits

43. SEQUENCE NUMBER in TCP segment header

A. sequence number for segment

B. sequence number for first byte in segment

ANSWER:B

EXPLANATION: TCP is byte oriented and seq number is for first byte in a segment

44. TCP provides

A. FLOW Control

B. CONGESTION handling

C. Ack and Retransmission

D. All of above

ANSWER:D

EXPLANATION: All three unlike UDP

45. TCP segment header field used for flow control and congestion handling

A. WINDOW
B. HLEN

C. URGENT POINTER

D. SOURCE PORT

ANSWER: A

EXPLANATION: Window size varied

46. CHECKSUM computation is not optional for UDP

A. False

B. TRUE

ANSWER:A

EXPLANATION:it is optional , mandatory for TCP

47. One application for UDP

A. VoIP media phase

B. WEB browsing

C. Email

D. FTP

ANSWER:A

EXPLANATION: VoIP media protocol RTP uses UDP

48. One application for TCP

A. WEB BROWSING

B. VoIP media phase

C. DNS

D. SNMP
ANSWER:A

EXPLANATION: http / https use TCP

49. Pseudo header used for TCP/UDP checksum computaion is transmitted on the network

A. False

B. True

ANSWER:A

EXPLANATION: Used for checksum computation by host only

50. TCP acknowledgement uses

A. Ack number

B. Ack bit

C. Both needed

ANSWER:C

EXPLANATION:Ack number valid when Ack bit = 1

DBMS MCQs

1.Which SQL command is used to get data from a table?

A) Delete

B) Update

C) Get

D) Select

ANSWER: D
2.What does SQL stand for

A) Simple Query Language

B) Structured Query Language

C) Solutions Query Language

D) None of these

ANSWER: B

3.Which command is used to add data to SQL table?

A) INSERT

B) SELECT

C) DELETE

D) None of these

ANSWER: A

4.Which command is used to modify existing data in SQL?

A) SELECT

B) UPDATE

C) DELETE

D) None of these

ANSWER: B
5.Which of the following SQL statements is used to retrieve data from a database?

A) DELETE

B) UPDATE

C) SELECT

D) INSERT

ANSWER: C

6.Which of the following SQL clauses is used to specify the conditions that must
be met to retrieve data from a database?

A) ORDER BY

B) GROUP BY

C) WHERE

D) HAVING

ANSWER: C

7.Which of the following SQL statements is used to add new data to a database?

A) DELETE

B) SELECT

C) UPDATE

D) INSERT

ANSWER: D
8.Which of the following SQL functions is used to count the number of rows in a
table?

A) COUNT

B) AVG

C) MAX

D) MIN

ANSWER: A

9.Which of the following SQL statements is used to delete data from a database?

A) INSERT

B) DELETE

C) UPDATE

D) SELECT

ANSWER: B

10.Which of the following SQL clauses is used to sort the retrieved data in
ascending or descending order?

A) GROUP BY

B) ORDER BY

C) WHERE

D) HAVING

ANSWER: B
11.Which of the following SQL functions is used to find the highest value in a
column?

A) COUNT

B) AVG

C) SUM

D) MAX

ANSWER: D

12.Which of the following SQL clauses is used to group the retrieved data by one
or more columns?

A) ORDER BY

B) GROUP BY

C) HAVING

D) WHERE

ANSWER: B

13.Which of the following SQL functions is used to calculate the average value in
a column?

A) COUNT

B) MAX

C) AVG
D) SUM

ANSWER: C

14.Which SQL keyword is used to remove duplicates from a result set?

A) SELECT DISTINCT

B) SELECT UNIQUE

C) SELECT ALL

D) SELECT DUPLICATE

ANSWER: A

15. Which SQL function is used to return the current date and time?

A) GETDATE()

B) CURRENT_TIMESTAMP()

C) NOW()

D) SYSDATE()

ANSWER: B

16.Which SQL keyword is used to sort the result set in descending order?

A) ORDER BY DESC

B) ORDER BY ASC

C) SORT BY DESC
D) SORT BY ASC

ANSWER: A

17. Which SQL keyword is used to join two or more tables?

A) UNION

B) JOIN

C) INTERSECT

D) EXCEPT

ANSWER: B

18.Which SQL keyword is used to retrieve only distinct values?

A) SELECT

B) DISTINCT

C) UNIQUE

D) GROUP BY

ANSWER: B

19.Which SQL statement is used to insert new data into a table?

A) UPDATE

B) DELETE

C) INSERT INTO
D) ALTER TABLE

ANSWER: C

20.Which SQL keyword is used to retrieve data from multiple tables?

A) GROUP BY

B) JOIN

C) UNION

D) WHERE

ANSWER: B

21.Which SQL function is used to return the current date and time?

A) NOW()

B) DATE()

C) TIME()

D) YEAR()

ANSWER: A

22.Which SQL operator is used to combine two or more conditions in a WHERE


clause?

A) NOT

B) OR

C) AND
D) LIKE

ANSWER: C

23.Which SQL keyword is used to sort the results of a SELECT statement in


ascending order?

A) DESC

B) ORDER BY

C) ASC

D) SORT

ANSWER: C

24.Which SQL operator is used to combine multiple conditions in a WHERE


clause?

A) AND

B) OR

C) NOT

D) XOR

ANSWER: A

25.Which SQL keyword is used to limit the number of rows returned by a


SELECT statement?

A) TOP
B) LIMIT

C) ROWS

D) COUNT

ANSWER: B

26.What is the command used to calculate the average value of a column in SQL?

A) SELECT MAX()

B) SELECT COUNT()

C) SELECT AVG()

D) NONE OF THESE

ANSWER: C

27.What is the command used to truncate a table in SQL?

A) TRUNCATE DATA

B) TRUNCATE TABLE

C) TRUNCATE DATABASE

D) TRUNCATE ROW

ANSWER: B

28.What is the command used to create a primary key on a column in SQL?

A) ALTER TABLE ADD DATA PRIMARY KEY


B) ALTER TABLE ADD CONSTRAINT PRIMARY KEY

C) ALTER DATA ADD CONSTRAINT PRIMARY KEY

D) NONE OF THESE

ANSWER: B

29.What is the command used to sort data in SQL?

A) DELETE

B) ORDER BY

C) INSERT

D) SORT

ANSWER: B

30.What is the command used to add a new column to a table in SQL?

A) ALTER ROW

B) ALTER COLUMN

C) ALTER TABLE

D) NONE OF THESE

ANSWER: C

31.What is the command used to delete a table in SQL?

A) DROP ROW
B) DROP COLUMN

C) DROP TABLE

D) DELETE TABLE

ANSWER: C

32.What is the command used to create a table in SQL?

A) Create data

B) Create table

C) Add table

D) Add data

ANSWER: B

33.Which SQL keyword is used to filter the results of a query based on a


condition?

A) Order By

B) Where

C) Delete

D) Insert

ANSWER: B

34.Which SQL keyword is used to group rows based on the values in a particular
column?
A) Order By

B) Delete

C) Group By

D) Insert

ANSWER: C

35.Which SQL operator is used to select rows that meet either of two conditions in
a WHERE clause?

A) AND

B) OR

C) Order By

D) Group By

ANSWER: B

36.Which SQL function is used to calculate the average value in a column?

A) Count

B) Max

C) ASC

D) Avg

ANSWER: D

37.Which SQL function is used to find the lowest value in a column?


A) Max

B) Min

C) Large

D) None of these

ANSWER: B

38.How to add a new column to a table in SQL ?

A) ADD COLUMN column_name;

B) INSERT COLUMN column_name;

C) DROP COLUMN column_name;

D) DELETE COLUMN column_name;

ANSWER: A

39.Which SQL statement is used to sort data in a table?

A) ORDER BY column_name;

B) SORT BY column_name;

C) ARRANGE BY column_name;

D) SEQUENCE BY column_name;

ANSWER: B

40.Which SQL statement is used to update data in a table?


A) MODIFY table_name SET column_name = value;

B) UPDATE table_name SET column_name = value;

C) CHANGE table_name SET column_name = value;

D) ALTER table_name SET column_name = value;

ANSWER: B

41.Which SQL statement is used to insert a new row in a table?

A) INSERT ROW INTO table_name;

B) APPEND ROW TO table_name;

C) INSERT INTO table_name VALUES ();

D) ADD NEW ROW TO table_name;

ANSWER: C

42.Which of the following is a relational database management system?

A) Oracle

B) MongoDB

C) Cassandra

D) Redis

ANSWER: A

43.Which SQL command is used to delete a table in a database?


A) Remove Table

B) Delete Table

C) Erase Table

D) Drop Table

ANSWER: D

44.Which SQL statement is used to create a new table in a database?

A) Create Table

B) Insert Table

C) Add Table

D) Make Table

ANSWER: A

45.Which SQL statement is used to sort the result set in ascending order?

A) Order ASC

B) Order by ASC

C) Order DESC

D) Order by DESC

ANSWER: B

46.Which SQL command is used to change existing data in a database?


A) Insert

B) Update

C) Delete

D) Select

ANSWER: B

47.Which SQL command is used to retrieve data from a database?

A) Add

B) Insert

C) Update

D) Select

ANSWER: D

48.Which SQL statement is used to limit the number of results returned from a
query?

A) Fetch

B) Count

C) Limit

D) Top

ANSWER: C

49.Which SQL statement is used to select only unique values from a table?
A) Select Unique

B) Select Distinct

C) Select Different

D) Select Unique Values

ANSWER: B

50.What will be the output of the below LIKE query? WHERE SALARY LIKE
'9000%'

A) It will find any value that starts with 9000

B) It will find any value that ends with 9000

C) It will find any value whose range is between 9000

D) It will find the value where salary is less than 9000

ANSWER: A

51.What will be the output of the below LIKE query? WHERE SALARY LIKE
'8_%_%.'

A) It will find any value that starts with 9000

B) It will find any value that ends with 9000

C) It will find any value whose range is between 9000

D) It will find the value where salary is less than 9000

ANSWER: A
52.Select all records from the Employees table where the Phone_number is
empty.The query is--- SELECT * FROM Employees WHERE _________

A) Phone_number IS NULL.

B) Phone_number IS EMPTY.

C) Phone_number IS NOT TRUE

D) None of the above.

ANSWER: A

53.Write a query to retrieve the employee’s first name and last name and
concatenate them in a single column?

A) SELECT CONCAT (emp_fname, ‘ ’, emp_lname) AS Fullname FROM


Employees;

B) SELECT (emp_fname, ‘ ’, emp_lname) AS Fullname FROM Employees;

C) SELECT emp_fname, emp_lname CONCAT AS Fullname FROM Employees;

D) SELECT FROM Employees CONCAT (emp_fname, emp_name) AS Fullname;

ANSWER: A

54.If we don’t specify ASC or DSC after the ORDER BY command, which of the
following is used by default?

A) ASC

B) DSC

C) Nothing will be done.

D) None of the above.


ANSWER: A

55.Write a query to retrieve the employee’s first name and last name and
concatenate them in a single column?

A) SELECT CONCAT (emp_fname, ‘ ’, emp_lname) AS Fullname FROM


Employees;

B) SELECT (emp_fname, ‘ ’, emp_lname) AS Fullname FROM Employees;

C) SELECT emp_fname, emp_lname CONCAT AS Fullname FROM Employees;

D) SELECT FROM Employees CONCAT (emp_fname, emp_name) AS Fullname;

ANSWER: A

C Programming MCQ (Multiple Choice Questions)

1. Who is the father of C language?

A) Steve Jobs

B) James Gosling

C)Dennis Ritchie

D)Rasmus Lerdorf

ANSWER: C
2. Which of the following is not a valid C variable name?

A) int number;

B) float rate;

C)int variable_count;

D)int $main;

ANSWER: D

3. All keywords in C are in ____________

A) LowerCase letters

B) UpperCase letters

C)CamelCase letters

D)None of the mentioned

ANSWER: A

4. Which of the following is true for variable names in C?

A) They can contain alphanumeric characters as well as special characters

B) It is not an error to declare a variable to be one of the keywords(like goto, static)

C)Variable names cannot start with a digit

D)Variable can be of any length

ANSWER: C

5. Which is valid C expression?

A) int my_num = 100,000;

B) int my_num = 100000;

C)int my num = 1000;


D)int $my_num = 10000;

ANSWER: B

6. Which of the following cannot be a variable name in C?

A) volatile

B) true

C)friend

D)export

ANSWER: A

ADVERTISEMENT

7. What is short int in C programming?

A) The basic data type of C

B) Qualifier

C)Short is the qualifier and int is the basic data type

D)All of the mentioned

ANSWER: C

8. Which of the following declaration is not supported by C language?

A) String str;

B) char *str;

C)float str = 3e2;

D)Both “String str;” and “float str = 3e2;”

ANSWER: A

9. Which keyword is used to prevent any changes in the variable within a C program?
A) immutable

B) mutable

C)const

D)volatile

ANSWER: C

10. What is the result of logical or relational expression in C?

A) True or False

B) 0 or 1

C)0 if an expression is false and any positive number if an expression is true

D)None of the mentioned

ANSWER: B

11. Which of the following typecasting is accepted by C language?

A) Widening conversions

B) Narrowing conversions

C)Widening & Narrowing conversions

D)None of the mentioned

ANSWER: C

12. Where in C the order of precedence of operators do not exist?

A) Within conditional statements, if, else

B) Within while, do-while

C)Within a macro definition

D)None of the mentioned


ANSWER: D

13. Which of the following is NOT possible with any 2 operators in C?

A) Different precedence, same associativity

B) Different precedence, different associativity

C)Same precedence, different associativity

D)All of the mentioned

ANSWER: C

14. What is an example of iteration in C?

A) for

B) while

C)do-while

D)all of the mentioned

ANSWER: D

15. Functions can return enumeration constants in C?

A) true

B) false

C)depends on the compiler

D)depends on the standard

ANSWER: A

16. Functions in C Language are always _________

A) Internal
B) External

C)Both Internal and External

D)External and Internal are not valid terms for functions

ANSWER: B

17. Which of following is not accepted in C?

A) static a = 10; //static as

B) static int func (int); //parameter as static

C)static static int a; //a static variable prefixed with static

D)all of the mentioned

ANSWER: C

18. Property which allows to produce different executable for different platforms in C is called?

A) File inclusion

B) Selective inclusion

C)Conditional compilation

D)Recursive macros

ANSWER: C

19. What is #include <stdio.h>?

A) Preprocessor directive

B) Inclusion directive

C)File inclusion directive

D)None of the mentioned

ANSWER: A
20. C preprocessors can have compiler specific features.

A) True

B) False

C)Depends on the standard

D)Depends on the platform

ANSWER: A

21. Which of the following are C preprocessors?

A) #ifdef

B) #define

C)#endif

D)all of the mentioned

ANSWER: D

22. The C-preprocessors are specified with _________ symbol.

A) #

B) $

C)” ”

D)&

ANSWER: A

23. How is search done in #include and #include “somelibrary.h” according to C standard?

A) When former is used, current directory is searched and when latter is used, standard
directory is searched
B) When former is used, standard directory is searched and when latter is used, current
directory is searched

C)When former is used, search is done in implementation defined manner and when latter is
used, current directory is searched

D)For both, search for ‘somelibrary’ is done in implementation-defined places

ANSWER: B

24. How many number of pointer (*) does C have against a pointer variable declaration?

A) 7

B) 127

C)255

D)No limits

ANSWER: D

25. Which of the following is not possible statically in C language?

A) Jagged Array

B) Rectangular Array

C)Cuboidal Array

D)Multidimensional Array

ANSWER: A

26. Which of the following return-type cannot be used for a function in C?

A) char *

B) struct

C)void

D)none of the mentioned


ANSWER: D

27. The standard header _______ is used for variable list arguments (…) in C.

A) <stdio.h >

B) <stdlib.h>

C)<math.h>

D)<stdarg.h>

ANSWER: D

28. When a C program is started, O.S environment is responsible for opening file and
providing pointer for that file?

A) Standard input

B) Standard output

C)Standard error

D)All of the mentioned

ANSWER: D

29. In C language, FILE is of which data type?

A) int

B) char *

C)struct

D)None of the mentioned

ANSWER: C

30. What is the sizeof(char) in a 32-bit C compiler?

A) 1 bit
B) 2 bits

C)1 Byte

D)2 Bytes

ANSWER: C

31. Which of the following is not an operator in C?

A) ,

B) sizeof()

C)~

D)None of the mentioned

ANSWER: D

32. scanf() is a predefined function in______header file.

A) stdlib. h

B) ctype. h

C)stdio. h

D)stdarg. h

ANSWER: C

33. What is meant by ‘a’ in the following C operation?

A) Attach

B) Append

C)Apprehend

D)Add

ANSWER: B
34. What will be the output of the following C code?

1. #include <stdio.h>

2. int main()

3. {

4. int y = 10000;

5. int y = 34;

6. printf("Hello World! %d\n", y);

7. return 0;

8. }

A) Compile time error

B) Hello World! 34

C)Hello World! 1000

D)Hello World! followed by a junk value

ANSWER: A

35. What will happen if the following C code is executed?

1. #include <stdio.h>

2. int main()

3. {

4. int main = 3;

5. printf("%d", main);

6. return 0;

7. }

A) It will cause a compile-time error


B) It will cause a run-time error

C)It will run without any error and prints 3

D)It will experience infinite looping

ANSWER: C

36. What will be the output of the following C code?

1. #include <stdio.h>

2. int main()

3. {

4. signed char chr;

5. chr = 128;

6. printf("%d\n", chr);

7. return 0;

8. }

A) 128

B) -128

C)Depends on the compiler

D)None of the mentioned

ANSWER: B

37. What will be the output of the following C code on a 64 bit machine?

1. #include <stdio.h>

2. union Sti

3. {

4. int nu;
5. char m;

6. };

7. int main()

8. {

9. union Sti s;

10. printf("%d", sizeof(s));

11. return 0;

12. }

A) 8

B) 5

C)9

D)4

ANSWER: D

38. What will be the output of the following C function?

1. #include <stdio.h>

2. enum birds {SPARROW, PEACOCK, PARROT};

3. enum animals {TIGER = 8, LION, RABBIT, ZEBRA};

4. int main()

5. {

6. enum birds m = TIGER;

7. int k;

8. k = m;

9. printf("%d\n", k);

10. return 0;
11. }

A) 0

B) Compile time error

C)1

D)8

ANSWER: D

39. What will be the output of the following C code?

1. #include <stdio.h>

2. int const print()

3. {

4. printf("Sanfoundry.com");

5. return 0;

6. }

7. void main()

8. {

9. print();

10. }

A) Error because function name cannot be preceded by const

B) Sanfoundry.com

C)Sanfoundry.com is printed infinite times

D)Blank screen, no output

ANSWER: B

40. Will the following C code compile without any error?


1. #include <stdio.h>

2. int main()

3. {

4. for (int k = 0; k < 10; k++);

5. return 0;

6. }

A) Yes

B) No

C)Depends on the C standard implemented by compilers

D)Error

ANSWER: C

41. What will be the final value of x in the following C code?

1. #include <stdio.h>

2. void main()

3. {

4. int x = 5 * 9 / 3 + 9;

5. }

A) 3.75

B) Depends on compiler

C)24

D)3

ANSWER: C

42. What will be the output of the following C code? (Initial values: x= 7, y = 8)
1. #include <stdio.h>

2. void main()

3. {

4. float x;

5. int y;

6. printf("enter two numbers \n");

7. scanf("%f %f", &x, &y);

8. printf("%f, %d", x, y);

9. }

A) 7.000000, 7

B) Run time error

C)7.000000, junk

D)Varies

ANSWER: C

43. What will be the output of the following C code considering the size of a short int is 2, char
is 1 and int is 4 bytes?

1. #include <stdio.h>

2. int main()

3. {

4. short int i = 20;

5. char c = 97;

6. printf("%d, %d, %d\n", sizeof(i), sizeof(c), sizeof(c + i));

7. return 0;

8. }

A) 2, 1, 2
B) 2, 1, 1

C)2, 1, 4

D)2, 2, 8

ANSWER: C

44. What is the difference between the following 2 C codes?

1. #include <stdio.h> //Program 1

2. int main()

3. {

4. int d, a = 1, b = 2;

5. d = a++ + ++b;

6. printf("%d %d %d", d, a, B);

7. }

1. #include <stdio.h> //Program 2

2. int main()

3. {

4. int d, a = 1, b = 2;

5. d = a++ +++b;

6. printf("%d %d %d", d, a, B);

7. }

A) No difference as space doesn’t make any difference, values of a, b, d are same in both the
case

B) Space does make a difference, values of a, b, d are different

C)Program 1 has syntax error, program 2 is not

D)Program 2 has syntax error, program 1 is not

ANSWER: D
45. What will be the output of the following C code snippet?

1. #include <stdio.h>

2. void main()

3. {

4. 1 < 2 ? return 1: return 2;

5. }

A) returns 1

B) returns 2

C)Varies

D)Compile time error

ANSWER: D

46. What will be the value of the following assignment expression?

(x = foo())!= 1 considering foo() returns 2

A) 2

B) True

C)1

D)0

ANSWER: A

47. What will be the output of the following C function?

1. #include <stdio.h>

2. void reverse(int i);

3. int main()
4. {

5. reverse(1);

6. }

7. void reverse(int i)

8. {

9. if (i > 5)

10. return ;

11. printf("%d ", i);

12. return reverse((i++, i));

13. }

A) 1 2 3 4 5

B) Segmentation fault

C)Compilation error

D)Undefined behaviour

ANSWER: A

48. What will be the final values of i and j in the following C code?

1. #include <stdio.h>

2. int x = 0;

3. int f()

4. {

5. if (x == 0)

6. return x + 1;

7. else

8. return x - 1;
9. }

10. int g()

11. {

12. return x++;

13. }

14. int main()

15. {

16. int i = (f() + g()) | g(); //bitwise or

17. int j = g() | (f() + g()); //bitwise or

18. }

A) i value is 1 and j value is 1

B) i value is 0 and j value is 0

C)i value is 1 and j value is undefined

D)i and j value are undefined

ANSWER: C

49. Comment on the following C statement.

n = 1;

printf("%d, %dn", 3*n, n++);

A) Output will be 3, 2

B) Output will be 3, 1

C)Output will be 6, 1

D)Output is compiler dependent

ANSWER: D
50. How many times i value is checked in the following C program?

1. #include <stdio.h>

2. int main()

3. {

4. int i = 0;

5. while (i < 3)

6. i++;

7. printf("In while loop\n");

8. }

A) 2

B) 3

C)4

D)1

ANSWER: C

51. What will be the output of the following C code?

1. #include <stdio.h>

2. int main()

3. {

4. int i = 0;

5. do

6. {

7. i++;

8. if (i == 2)

9. continue;
10. printf("In while loop ");

11. } while (i < 2);

12. printf("%d\n", i);

13. }

A) In while loop 2

B) In while loop in while loop 3

C)In while loop 3

D)Infinite loop

ANSWER: A

52. What will be the data type returned for the following C function?

1. #include <stdio.h>

2. int func()

3. {

4. return (double)(char)5.0;

5. }

A) char

B) int

C)double

D)multiple type-casting in return is illegal

ANSWER: B

53. What is the problem in the following C declarations?

int func(int);

double func(int);
int func(float);

A) A function with same name cannot have different signatures

B) A function with same name cannot have different return types

C)A function with same name cannot have different number of parameters

D)All of the mentioned

ANSWER: D

54. Which option should be selected to work the following C expression?

string p = "HELLO";

A) typedef char [] string;

B) typedef char *string;

C)typedef char [] string; and typedef char *string;

D)Such expression cannot be generated in C

ANSWER: B

55. What is the meaning of the following C statement?

printf(“%10s”, state);

A) 10 spaces before the string state is printed

B) Print empty spaces if the string state is less than 10 characters

C)Print the last 10 characters of the string

D)None of the mentioned

ANSWER: B

56. What are the elements present in the array of the following C code?

int array[5] = {5};


A) 5, 5, 5, 5, 5

B) 5, 0, 0, 0, 0

C)5, (garbage), (garbage), (garbage), (garbage)

D)(garbage), (garbage), (garbage), (garbage), 5

ANSWER: B

57. What will be the output of the following C function when EOF returns?

int fputs(char *line, FILE *fp)

A) ‘�’ character of array line is encountered

B) ‘n’ character in array line is encountered

C)‘t’ character in array line is encountered

D)When an error occurs

ANSWER: D

58. Which part of the program address space is p stored in the following C code?

1. #include <stdio.h>

2. int *p;

3. int main()

4. {

5. int i = 0;

6. p = &i;

7. return 0;

8. }

A) Code/text segment

B) Data segment
C)Bss segment

D)Stack

ANSWER: C

59. Which of the following sequences are unaccepted in C language?

A)

#if

#else

#endif

B)

#if

#elif

#endif

c)

#if

#if

#endif

d)

#if

#undef

#endif

ANSWER: C

59. Comment on the output of following C code.

1. #include <stdio.h>
2. main()

3. {

4. char *p = 0;

5. *p = 'a';

6. printf("value in pointer p is %c\n", *p);

7. }

A) It will print a

B) It will print 0

C)Compile time error

D)Run time error

ANSWER:D

60. What is the output of this C code?

1. #include <stdio.h>

2. main()

3. {

4. if (sizeof(int) > -1)

5. printf("True");

6. else

7. printf("False");

8. }

A) True

B) False

ANSWER:B
61. What is the output of this C code?

1. #include <stdio.h>

2. main()

3. {

4. char *p = "Sanfoundry C-Test";

5. p[0] = 'a';

6. p[1] = 'b';

7. printf("%s", p);

8. }

A) abnfoundry C-Test

B) Sanfoundry C-Test

C)Compile time error

D)Run time error

ANSWER:D

62. What is the output of this C code?

1. #include <stdio.h>

2. int main()

3. {

4. float f = 0.1;

5. if (f == 0.1)

6. printf("True");

7. else

8. printf("False");

9. }
A) True

B) False

ANSWER: B

63. What is the output of this C code?

1. #include <stdio.h>

2. main()

3. {

4. int n = 0, m = 0;

5. if (n > 0)

6. if (m > 0)

7. printf("True");

8. else

9. printf("False");

10. }

A) True

B) False

C)No Output will be printed

D)Run Time Error

ANSWER:C

Data Structure MCQ (Multiple Choice Questions)

1. What is a data structure?

A) A programming language
B) A collection of algorithms

C) A way to store and organize data

D) A type of computer hardware

ANSWER: C

Explanation: A data structure is a way to store and organize data efficiently, enhancing access
and manipulation, unlike programming languages, algorithms, or computer hardware.

2. What are the disadvantages of arrays?

A) Index value of an array can be negative

B) Elements are sequentially accessed

C) Data structure like queue or stack cannot be implemented

D) There are chances of wastage of memory space if elements inserted in an array are
lesser than the allocated size

ANSWER: D

Explanation: Arrays are of fixed size. If we insert elements less than the allocated size,
unoccupied positions can’t be used again. Wastage will occur in memory.

3. Which data structure is used for implementing recursion?

A) Stack

B) Queue

C) List

D) Array

ANSWER: A

Explanation: Stacks are used for the implementation of Recursion.

4. The data structure required to check whether an expression contains a balanced


parenthesis is?
A) Queue

B) Stack

C) Tree

D) Array

ANSWER: B

Explanation: The stack is a simple data structure in which elements are added and removed
based on the LIFO principle. Open parenthesis is pushed into the stack and a closed
parenthesis pops out elements till the top element of the stack is its corresponding open
parenthesis. If the stack is empty, parenthesis is balanced otherwise it is unbalanced.

5. Which of the following is not the application of stack?

A) Data Transfer between two asynchronous process

B) Compiler Syntax Analyzer

C) Tracking of local variables at run time

D) A parentheses balancing program

ANSWER: A

Explanation: Data transfer between the two asynchronous process uses the queue data
structure for synchronisation. The rest are all stack applications.

6. Which data structure is needed to convert infix notation to postfix notation?

A) Tree

B) Branch

C) Stack

D) Queue

ANSWER: C

Explanation: The Stack data structure is used to convert infix expression to postfix
expression. The purpose of stack is to reverse the order of the operators in the expression. It
also serves as a storage structure, as no operator can be printed until both of its operands
have appeared.

7. What is the value of the postfix expression 6 3 2 4 + – *?

A) 74

B) -18

C) 22

D) 40

ANSWER: B

Explanation: Postfix Expression is (6*(3-(2+4))) which results -18 as output.

8. What data structure would you mostly likely see in non recursive implementation of a
recursive algorithm?

A) Stack

B) Linked List

C) Tree

D) Queue

ANSWER: A

Explanation: In recursive algorithms, the order in which the recursive process comes back is
the reverse of the order in which it goes forward during execution. The compiler uses the
stack data structure to implement recursion. In the forwarding phase, the values of local
variables, parameters and the return address are pushed into the stack at each recursion
level. In the backing-out phase, the stacked address is popped and used to execute the rest
of the code.

9. Which of the following statement(s) about stack data structure is/are NOT correct?

A) Top of the Stack always contain the new node

B) Stack is the FIFO data structure


C) Null link is present in the last node at the bottom of the stack

D) Linked List are used for implementing Stacks

ANSWER: B

Explanation: Stack follows LIFO.

10. The data structure required for Breadth First Traversal on a graph is?

A) Array

B) Stack

C) Tree

D) Queue

ANSWER: D

Explanation: In Breadth First Search Traversal, BFS, starting vertex is first taken and adjacent
vertices which are unvisited are also taken. Again, the first vertex which was added as an
unvisited adjacent vertex list will be considered to add further unvisited vertices of the graph.
To get the first unvisited vertex we need to follows First In First Out principle. Queue uses
FIFO principle.

11. The prefix form of A-B/ (C * D ^ E) is?

A) -A/B*C^DE

B) -A/BC*^DE

C) -ABCD*^DE

D) -/*^ACBDE

ANSWER: A

Explanation: Infix Expression is (A-B)/(C*D^E)

(-A/B)(C*D^E)

-A/B*C^DE. Thus prefix expression is -A/B*C^DE.


12. Which of the following points is/are not true about Linked List data structure when it is
compared with an array?

A) Random access is not allowed in a typical implementation of Linked Lists

B) Access of elements in linked list takes less time than compared to arrays

C) Arrays have better cache locality that can make them better in terms of performance

D) It is easy to insert and delete elements in Linked List

ANSWER: B

Explanation: To access an element in a linked list, we need to traverse every element until we
reach the desired element. This will take more time than arrays as arrays provide random
access to its elements.

13. Which data structure is based on the Last In First Out (LIFO) principle?

A) Tree

B) Linked List

C) Stack

D) Queue

ANSWER: C

Explanation: The data structure that follows the Last In First Out (LIFO) principle is the Stack.
It operates like a stack of objects, making it suitable for specific-order management.

14. Which of the following application makes use of a circular linked list?

A) Recursive function calls

B) Undo operation in a text editor

C) Implement Hash Tables

D) Allocating CPU to resources

ANSWER: D
Explanation: Generally, round robin fashion is employed to allocate CPU time to resources
which makes use of the circular linked list data structure. Recursive function calls use stack
data structure. Undo Operation in text editor uses doubly linked lists. Hash tables uses singly
linked lists.

15. What is a bit array?

A) Data structure that compactly stores bits

B) Data structure for representing arrays of records

C) Array in which elements are not present in continuous locations

D) An array in which most of the elements have the same value

ANSWER: A

Explanation: It compactly stores bits and exploits bit-level parallelism.

16. Which of the following tree data structures is not a balanced binary tree?

A) Splay tree

B) B-tree

C) AVL tree

D) Red-black tree

ANSWER: B

Explanation: All the tree data structures given in options are balanced, but B-tree can have
more than two children.

17. Which of the following is not the type of queue?

A) Priority queue

B) Circular queue

C) Single ended queue

D) Ordinary queue
ANSWER: C

Explanation: Queue always has two ends. So, single ended queue is not the type of queue.

18. Which of the following data structures can be used for parentheses matching?

A) n-ary tree

B) queue

C) priority queue

D) stack

ANSWER: D

Explanation: For every opening brace, push it into the stack, and for every closing brace, pop
it off the stack. Do not take action for any other character. In the end, if the stack is empty,
then the input has balanced parentheses.

19. Which algorithm is used in the top tree data structure?

A) Backtracking

B) Divide and Conquer

C) Branch

D) Greedy

ANSWER: B

Explanation: Top tree is a type of data structure which is based on unrooted dynamic binary
tree and is used to solve path related problems. It allows an algorithm called divide and
conquer.

20. What is the need for a circular queue?

A) easier computations

B) implement LIFO principle in queues

C) effective usage of memory


D) to delete elements based on priority

ANSWER: C

Explanation: In a linear queue, dequeue operation causes the starting elements of the array to
be empty, and there is no way you can use that space, while in a circular queue, you can
effectively use that space. Priority queue is used to delete the elements based on their priority.
Higher priority elements will be deleted first whereas lower priority elements will be deleted
next. Queue data structure always follows FIFO principle.

21. Which of the following is the most widely used external memory data structure?

A) B-tree

B) Red-black tree

C) AVL tree

D) Both AVL tree and Red-black tree

ANSWER: A

Explanation: In external memory, the data is transferred in form of blocks. These blocks have
data valued and pointers. And B-tree can hold both the data values and pointers. So B-tree is
used as an external memory data structure.

22. Which of the following is also known as Rope data structure?

A) Linked List

B) Array

C) String

D) Cord

ANSWER: D

Explanation: Array is a linear data structure. Strings are a collection and sequence of codes,
alphabets or characters. Linked List is a linear data structure having a node containing data
input and the address of the next node. The cord is also known as the rope data structure.

23. What will be the output of the following program?


main()

char str[]="san foundry";

int len = strlen(str);

int i;

for(i=0;i<len;i++)

push(str[i]); // pushes an element into stack

for(i=0;i<len;i++)

pop(); //pops an element from the stack

A) yrdnuof nas

B) foundry nas

C) sanfoundry

D) san foundry

ANSWER: A

Explanation: First, the string ‘san foundry’ is pushed one by one into the stack.

When it is popped, the output will be as ‘yrdnuof nas’.

24. Which of the following data structure can provide efficient searching of the elements?

A) binary search tree

B) unordered lists

C) 2-3 tree

D) treap
ANSWER: C

Explanation: The average case time for lookup in a binary search tree, treap and 2-3 tree is
O(log n) and in unordered lists it is O(n). But in the worst case, only the 2-3 trees perform
lookup efficiently as it takes O(log n), while others take O(n).

25. What is an AVL tree?

A) a tree which is unbalanced and is a height balanced tree

B) a tree which is balanced and is a height balanced tree

C) a tree with atmost 3 children

D) a tree with three children

ANSWER: B

Explanation: It is a self balancing tree with height difference atmost 1.

26. What is the time complexity for searching a key or integer in Van Emde Boas data
structure?

A) O (M!)

B) O (log M!)

C) O (log (log M))

D) O (M2)

ANSWER: C

Explanation: In order to search a key or integer in the Van Emde Boas data structure, the
operation can be performed on an associative array. Hence, the time complexity for searching
a key or integer in Van Emde Boas data structure is O (log (log M)).

27. The optimal data structure used to solve Tower of Hanoi is _________

A) Tree

B) Heap
C) Priority queue

D) Stack

ANSWER: D

Explanation: The Tower of Hanoi involves moving of disks ‘stacked’ at one peg to another peg
with respect to the size constraint. It is conveniently done using stacks and priority queues.
Stack approach is widely used to solve Tower of Hanoi.

28. What is the use of the bin data structure?

A) to have efficient traversal

B) to have efficient region query

C) to have efficient deletion

D) to have efficient insertion

ANSWER: B

Explanation: Bin data structure allows us to have efficient region queries. A frequency of bin is
increased by one each time a data point falls into a bin.

29. Which is the most appropriate data structure for reversing a word?

A) stack

B) queue

C) graph

D) tree

ANSWER: A

Explanation: Stack is the most appropriate data structure for reversing a word because stack
follows LIFO principle.

30. What is the functionality of the following piece of code?

public void display()


{

if(size == 0)

System.out.println("underflow");

else

Node current = first;

while(current != null)

System.out.println(current.getEle());

current = current.getNext();

A) display the list

B) reverse the list

C) reverse the list excluding top-of-the-stack-element

D) display the list excluding top-of-the-stack-element

ANSWER: A

Explanation: An alias of the node ‘first’ is created which traverses through the list and displays
the elements.

31. Which of the following is the simplest data structure that supports range searching?

A) AA-trees

B) K-d trees

C) Heaps

D) binary search trees


ANSWER: C

Explanation: K-d trees are the simplest data structure that supports range searching and also
it achieves the respectable running time.

32. What is the advantage of a hash table as a data structure?

A) easy to implement

B) faster access of data

C) exhibit good locality of reference

D) very efficient for less number of entries

ANSWER: B

Explanation: Hash table is a data structure that has an advantage that it allows fast access of
elements. Hash functions are used to determine the index of any input record in a hash table.

33. Which type of data structure is a ternary heap?

A) Hash

B) Array

C) Priority Stack

D) Priority Queue

ANSWER: D

Explanation: Ternary heap is a type of data structure in the field of computer science. It is a
part of the Heap data structure family. It is a priority queue type of data structure that follows
all the property of heap.

34. What is a dequeue?

A) A queue implemented with both singly and doubly linked lists

B) A queue with insert/delete defined for front side of the queue

C) A queue with insert/delete defined for both front and rear ends of the queue
D) A queue implemented with a doubly linked list

ANSWER: C

Explanation: A dequeue or a double ended queue is a queue with insert/delete defined for
both front and rear ends of the queue.

35. A data structure in which elements can be inserted or deleted at/from both ends but not in
the middle is?

A) Priority queue

B) Dequeue

C) Circular queue

D) Queue

ANSWER: B

Explanation: In dequeuer, we can insert or delete elements from both the ends. In queue, we
will follow first in first out principle for insertion and deletion of elements. Element with least
priority will be deleted in a priority queue.

36. What is the output of the following Java code?

public class array

public static void main(String args[])

int []arr = {1,2,3,4,5};

System.out.println(arr[2]);

System.out.println(arr[4]);

A) 4 and 2
B) 2 and 4

C) 5 and 3

D) 3 and 5

ANSWER: D

Explanation: Array indexing starts from 0.

37. In simple chaining, what data structure is appropriate?

A) Doubly linked list

B) Circular linked list

C) Singly linked list

D) Binary trees

ANSWER: A

Explanation: Deletion becomes easier with doubly linked list, hence it is appropriate.

1. What is a data structure?

A) A programming language

B) A collection of algorithms

C) A way to store and organize data

D) A type of computer hardware

ANSWER: C

Explanation: A data structure is a way to store and organize data efficiently, enhancing access
and manipulation, unlike programming languages, algorithms, or computer hardware.

2. What are the disadvantages of arrays?

A) Index value of an array can be negative

B) Elements are sequentially accessed


C) Data structure like queue or stack cannot be implemented

D) There are chances of wastage of memory space if elements inserted in an array are
lesser than the allocated size

ANSWER: D

Explanation: Arrays are of fixed size. If we insert elements less than the allocated size,
unoccupied positions can’t be used again. Wastage will occur in memory.

3. Which data structure is used for implementing recursion?

A) Stack

B) Queue

C) List

D) Array

ANSWER: A

Explanation: Stacks are used for the implementation of Recursion.

4. The data structure required to check whether an expression contains a balanced


parenthesis is?

A) Queue

B) Stack

C) Tree

D) Array

ANSWER: B

Explanation: The stack is a simple data structure in which elements are added and removed
based on the LIFO principle. Open parenthesis is pushed into the stack and a closed
parenthesis pops out elements till the top element of the stack is its corresponding open
parenthesis. If the stack is empty, parenthesis is balanced otherwise it is unbalanced.

5. Which of the following is not the application of stack?


A) Data Transfer between two asynchronous process

B) Compiler Syntax Analyzer

C) Tracking of local variables at run time

D) A parentheses balancing program

ANSWER: A

Explanation: Data transfer between the two asynchronous process uses the queue data
structure for synchronisation. The rest are all stack applications.

6. Which data structure is needed to convert infix notation to postfix notation?

A) Tree

B) Branch

C) Stack

D) Queue

ANSWER: C

Explanation: The Stack data structure is used to convert infix expression to postfix
expression. The purpose of stack is to reverse the order of the operators in the expression. It
also serves as a storage structure, as no operator can be printed until both of its operands
have appeared.

7. What is the value of the postfix expression 6 3 2 4 + – *?

A) 74

B) -18

C) 22

D) 40

ANSWER: B

Explanation: Postfix Expression is (6*(3-(2+4))) which results -18 as output.


8. What data structure would you mostly likely see in non recursive implementation of a
recursive algorithm?

A) Stack

B) Linked List

C) Tree

D) Queue

ANSWER: A

Explanation: In recursive algorithms, the order in which the recursive process comes back is
the reverse of the order in which it goes forward during execution. The compiler uses the
stack data structure to implement recursion. In the forwarding phase, the values of local
variables, parameters and the return address are pushed into the stack at each recursion
level. In the backing-out phase, the stacked address is popped and used to execute the rest
of the code.

9. Which of the following statement(s) about stack data structure is/are NOT correct?

A) Top of the Stack always contain the new node

B) Stack is the FIFO data structure

C) Null link is present in the last node at the bottom of the stack

D) Linked List are used for implementing Stacks

ANSWER: B

Explanation: Stack follows LIFO.

10. The data structure required for Breadth First Traversal on a graph is?

A) Array

B) Stack

C) Tree

D) Queue

ANSWER: D
Explanation: In Breadth First Search Traversal, BFS, starting vertex is first taken and adjacent
vertices which are unvisited are also taken. Again, the first vertex which was added as an
unvisited adjacent vertex list will be considered to add further unvisited vertices of the graph.
To get the first unvisited vertex we need to follows First In First Out principle. Queue uses
FIFO principle.

11. The prefix form of A-B/ (C * D ^ E) is?

A) -A/B*C^DE

B) -A/BC*^DE

C) -ABCD*^DE

D) -/*^ACBDE

ANSWER: A

Explanation: Infix Expression is (A-B)/(C*D^E)

(-A/B)(C*D^E)

-A/B*C^DE. Thus prefix expression is -A/B*C^DE.

12. Which of the following points is/are not true about Linked List data structure when it is
compared with an array?

A) Random access is not allowed in a typical implementation of Linked Lists

B) Access of elements in linked list takes less time than compared to arrays

C) Arrays have better cache locality that can make them better in terms of performance

D) It is easy to insert and delete elements in Linked List

ANSWER: B

Explanation: To access an element in a linked list, we need to traverse every element until we
reach the desired element. This will take more time than arrays as arrays provide random
access to its elements.

13. Which data structure is based on the Last In First Out (LIFO) principle?
A) Tree

B) Linked List

C) Stack

D) Queue

ANSWER: C

Explanation: The data structure that follows the Last In First Out (LIFO) principle is the Stack.
It operates like a stack of objects, making it suitable for specific-order management.

14. Which of the following application makes use of a circular linked list?

A) Recursive function calls

B) Undo operation in a text editor

C) Implement Hash Tables

D) Allocating CPU to resources

ANSWER: D

Explanation: Generally, round robin fashion is employed to allocate CPU time to resources
which makes use of the circular linked list data structure. Recursive function calls use stack
data structure. Undo Operation in text editor uses doubly linked lists. Hash tables uses singly
linked lists.

15. What is a bit array?

A) Data structure that compactly stores bits

B) Data structure for representing arrays of records

C) Array in which elements are not present in continuous locations

D) An array in which most of the elements have the same value

ANSWER: A

Explanation: It compactly stores bits and exploits bit-level parallelism.


16. Which of the following tree data structures is not a balanced binary tree?

A) Splay tree

B) B-tree

C) AVL tree

D) Red-black tree

ANSWER: B

Explanation: All the tree data structures given in options are balanced, but B-tree can have
more than two children.

17. Which of the following is not the type of queue?

A) Priority queue

B) Circular queue

C) Single ended queue

D) Ordinary queue

ANSWER: C

Explanation: Queue always has two ends. So, single ended queue is not the type of queue.

18. Which of the following data structures can be used for parentheses matching?

A) n-ary tree

B) queue

C) priority queue

D) stack

ANSWER: D

Explanation: For every opening brace, push it into the stack, and for every closing brace, pop
it off the stack. Do not take action for any other character. In the end, if the stack is empty,
then the input has balanced parentheses.
19. Which algorithm is used in the top tree data structure?

A) Backtracking

B) Divide and Conquer

C) Branch

D) Greedy

ANSWER: B

Explanation: Top tree is a type of data structure which is based on unrooted dynamic binary
tree and is used to solve path related problems. It allows an algorithm called divide and
conquer.

20. What is the need for a circular queue?

A) easier computations

B) implement LIFO principle in queues

C) effective usage of memory

D) to delete elements based on priority

ANSWER: C

Explanation: In a linear queue, dequeue operation causes the starting elements of the array to
be empty, and there is no way you can use that space, while in a circular queue, you can
effectively use that space. Priority queue is used to delete the elements based on their priority.
Higher priority elements will be deleted first whereas lower priority elements will be deleted
next. Queue data structure always follows FIFO principle.

21. Which of the following is the most widely used external memory data structure?

A) B-tree

B) Red-black tree

C) AVL tree

D) Both AVL tree and Red-black tree

ANSWER: A
Explanation: In external memory, the data is transferred in form of blocks. These blocks have
data valued and pointers. And B-tree can hold both the data values and pointers. So B-tree is
used as an external memory data structure.

22. Which of the following is also known as Rope data structure?

A) Linked List

B) Array

C) String

D) Cord

ANSWER: D

Explanation: Array is a linear data structure. Strings are a collection and sequence of codes,
alphabets or characters. Linked List is a linear data structure having a node containing data
input and the address of the next node. The cord is also known as the rope data structure.

23. What will be the output of the following program?

main()

char str[]="san foundry";

int len = strlen(str);

int i;

for(i=0;i<len;i++)

push(str[i]); // pushes an element into stack

for(i=0;i<len;i++)

pop(); //pops an element from the stack

}
A) yrdnuof nas

B) foundry nas

C) sanfoundry

D) san foundry

ANSWER: A

Explanation: First, the string ‘san foundry’ is pushed one by one into the stack.

When it is popped, the output will be as ‘yrdnuof nas’.

24. Which of the following data structure can provide efficient searching of the elements?

A) binary search tree

B) unordered lists

C) 2-3 tree

D) treap

ANSWER: C

Explanation: The average case time for lookup in a binary search tree, treap and 2-3 tree is
O(log n) and in unordered lists it is O(n). But in the worst case, only the 2-3 trees perform
lookup efficiently as it takes O(log n), while others take O(n).

25. What is an AVL tree?

A) a tree which is unbalanced and is a height balanced tree

B) a tree which is balanced and is a height balanced tree

C) a tree with atmost 3 children

D) a tree with three children

ANSWER: B

Explanation: It is a self balancing tree with height difference atmost 1.


26. What is the time complexity for searching a key or integer in Van Emde Boas data
structure?

A) O (M!)

B) O (log M!)

C) O (log (log M))

D) O (M2)

ANSWER: C

Explanation: In order to search a key or integer in the Van Emde Boas data structure, the
operation can be performed on an associative array. Hence, the time complexity for searching
a key or integer in Van Emde Boas data structure is O (log (log M)).

27. The optimal data structure used to solve Tower of Hanoi is _________

A) Tree

B) Heap

C) Priority queue

D) Stack

ANSWER: D

Explanation: The Tower of Hanoi involves moving of disks ‘stacked’ at one peg to another peg
with respect to the size constraint. It is conveniently done using stacks and priority queues.
Stack approach is widely used to solve Tower of Hanoi.

28. What is the use of the bin data structure?

A) to have efficient traversal

B) to have efficient region query

C) to have efficient deletion

D) to have efficient insertion

ANSWER: B
Explanation: Bin data structure allows us to have efficient region queries. A frequency of bin is
increased by one each time a data point falls into a bin.

29. Which is the most appropriate data structure for reversing a word?

A) stack

B) queue

C) graph

D) tree

ANSWER: A

Explanation: Stack is the most appropriate data structure for reversing a word because stack
follows LIFO principle.

30. What is the functionality of the following piece of code?

public void display()

if(size == 0)

System.out.println("underflow");

else

Node current = first;

while(current != null)

System.out.println(current.getEle());

current = current.getNext();

}
}

A) display the list

B) reverse the list

C) reverse the list excluding top-of-the-stack-element

D) display the list excluding top-of-the-stack-element

ANSWER: A

Explanation: An alias of the node ‘first’ is created which traverses through the list and displays
the elements.

31. Which of the following is the simplest data structure that supports range searching?

A) AA-trees

B) K-d trees

C) Heaps

D) binary search trees

ANSWER: C

Explanation: K-d trees are the simplest data structure that supports range searching and also
it achieves the respectable running time.

32. What is the advantage of a hash table as a data structure?

A) easy to implement

B) faster access of data

C) exhibit good locality of reference

D) very efficient for less number of entries

ANSWER: B

Explanation: Hash table is a data structure that has an advantage that it allows fast access of
elements. Hash functions are used to determine the index of any input record in a hash table.
33. Which type of data structure is a ternary heap?

A) Hash

B) Array

C) Priority Stack

D) Priority Queue

ANSWER: D

Explanation: Ternary heap is a type of data structure in the field of computer science. It is a
part of the Heap data structure family. It is a priority queue type of data structure that follows
all the property of heap.

34. What is a dequeue?

A) A queue implemented with both singly and doubly linked lists

B) A queue with insert/delete defined for front side of the queue

C) A queue with insert/delete defined for both front and rear ends of the queue

D) A queue implemented with a doubly linked list

ANSWER: C

Explanation: A dequeue or a double ended queue is a queue with insert/delete defined for
both front and rear ends of the queue.

35. A data structure in which elements can be inserted or deleted at/from both ends but not in
the middle is?

A) Priority queue

B) Dequeue

C) Circular queue

D) Queue

ANSWER: B
Explanation: In dequeuer, we can insert or delete elements from both the ends. In queue, we
will follow first in first out principle for insertion and deletion of elements. Element with least
priority will be deleted in a priority queue.

36. What is the output of the following Java code?

public class array

public static void main(String args[])

int []arr = {1,2,3,4,5};

System.out.println(arr[2]);

System.out.println(arr[4]);

A) 4 and 2

B) 2 and 4

C) 5 and 3

D) 3 and 5

ANSWER: D

Explanation: Array indexing starts from 0.

37. In simple chaining, what data structure is appropriate?

A) Doubly linked list

B) Circular linked list

C) Singly linked list

D) Binary trees
ANSWER: A

Explanation: Deletion becomes easier with doubly linked list, hence it is appropriate.

What is a data structure?

A) A programming language

B) A collection of algorithms

C) A way to store and organize data

D) A type of computer hardware

ANSWER: C

Explanation: A data structure is a way to store and organize data efficiently, enhancing access
and manipulation, unlike programming languages, algorithms, or computer hardware.

Which of the following is not a type of data structure?

A) Array

B) Stack

C) Queue

D) Loop

ANSWER: D

Explanation: Arrays, stacks, and queues are common types of data structures, but a loop is a
control flow construct used in programming.

What is a stack?

A) A linear data structure with FIFO (First In, First Out) access

B) A linear data structure with LIFO (Last In, First Out) access

C) A tree-like data structure

D) A graph-like data structure


ANSWER: B

Explanation: A stack is a linear data structure where elements are added and removed from
the same end, called the top, using Last In, First Out (LIFO) access.

Which data structure allows access to elements in a fixed sequence and supports random
access?

A) Array

B) Linked List

C) Stack

D) Queue

ANSWER: A

Explanation: Arrays allow access to elements in a fixed sequence and support random access
to any element by index.

What is a linked list?

A) A linear data structure with FIFO access

B) A linear data structure with LIFO access

C) A collection of nodes where each node points to the next node in the sequence

D) A tree-like data structure

ANSWER: C

Explanation: A linked list is a linear data structure where elements are stored in nodes, and
each node points to the next node in the sequence.

Which of the following is true about a queue?

A) It follows Last In, First Out (LIFO) access

B) It follows First In, First Out (FIFO) access

C) It allows access to elements in a fixed sequence


D) It supports random access to elements

ANSWER: B

Explanation: A queue follows First In, First Out (FIFO) access, where elements are added at
the rear and removed from the front.

What is a tree in data structures?

A) A linear data structure

B) A non-linear data structure consisting of nodes connected by edges

C) A collection of algorithms

D) A type of computer hardware

ANSWER: B

Explanation: A tree is a non-linear data structure consisting of nodes connected by edges,


forming a hierarchical structure.

In a binary tree, each node has at most how many children?

A) 1

B) 2

C) 3

D) 4

ANSWER: B

Explanation: In a binary tree, each node has at most two children, referred to as the left child
and the right child.

Which of the following traversal methods visits the root node first, followed by the left subtree
and then the right subtree?

A) Preorder traversal

B) Inorder traversal
C) Postorder traversal

D) Level order traversal

ANSWER: A

Explanation: Preorder traversal visits the root node first, followed by the left subtree and then
the right subtree.

What is a graph in data structures?

A) A linear data structure

B) A non-linear data structure consisting of nodes and edges

C) A collection of algorithms

D) A type of computer hardware

ANSWER: B

Explanation: A graph is a non-linear data structure consisting of nodes (vertices) and edges
(connections between vertices).

Which of the following is true about a directed graph?

A) Each edge has a direction

B) Each edge has a weight

C) Each node has a parent and a child

D) Each node has a single neighbor

ANSWER: A

Explanation: In a directed graph, each edge has a direction indicating the flow from one node
to another.

What is a spanning tree in graph theory?

A) A tree that contains all the nodes of the graph

B) A tree that contains only a subset of nodes


C) A tree with a single node

D) A tree with only one edge

ANSWER: A

Explanation: A spanning tree of a graph is a tree that contains all the nodes of the graph with
the minimum possible number of edges.

Which of the following algorithms is used to find the shortest path in a weighted graph?

A) Depth-First Search (DFS)

B) Breadth-First Search (BFS)

C) Dijkstra's algorithm

D) Prim's algorithm

ANSWER: C

Explanation: Dijkstra's algorithm is used to find the shortest path in a weighted graph with
non-negative edge weights.

What is the time complexity of the binary search algorithm?

A) O(1)

B) O(log n)

C) O(n)

D) O(n log n)

ANSWER: B

Explanation: The binary search algorithm has a time complexity of O(log n), where n is the
number of elements in the sorted array.

Which sorting algorithm has the best average-case time complexity?

A) Bubble Sort

B) Merge Sort
C) Insertion Sort

D) Selection Sort

ANSWER: B

Explanation: Merge Sort has the best average-case time complexity of O(n log n) among the
given sorting algorithms.

What is dynamic programming?

A) A programming paradigm used for writing device drivers

B) A programming paradigm used for writing web applications

C) A method for solving complex problems by breaking them down into simpler subproblems

D) A method for solving mathematical equations

ANSWER: C

Explanation: Dynamic programming is a method for solving complex problems by breaking


them down into simpler subproblems and solving each subproblem only once.

Which of the following is not a property of dynamic programming?

A) Optimal Substructure

B) Overlapping Subproblems

C) Greedy Choice Property

D) Recursive Choice Property

ANSWER: C

Explanation: The Greedy Choice Property is not a property of dynamic programming. It is a


property of greedy algorithms.

What is a greedy algorithm?

A) An algorithm that makes locally optimal choices at each step with the hope of finding a
global optimum
B) An algorithm that exhaustively searches all possible solutions

C) An algorithm that divides the problem into smaller subproblems and solves each
subproblem optimally

D) An algorithm that randomly selects solutions from a solution space

ANSWER: A

Explanation: A greedy algorithm makes locally optimal choices at each step with the hope of
finding a global optimum solution.

What is an algorithm?

A) A set of instructions to perform a specific task

B) A physical device used for computation

C) A programming language

D) A type of data structure

ANSWER: A

Explanation: An algorithm is a finite set of instructions designed to perform a specific task or


solve a particular problem. It is independent of any programming language or physical device
and focuses solely on the logic and steps required to achieve the desired outcome.

Which of the following best defines a binary search algorithm?

A) An algorithm for sorting elements in ascending order

B) An algorithm for searching through a sorted array by repeatedly dividing the search interval
in half

C) An algorithm for finding the shortest path in a graph

D) An algorithm for reversing the elements of an array

ANSWER: B

Explanation: A binary search algorithm is a technique for finding a particular value within a
sorted array by repeatedly dividing the search interval in half. This approach significantly
reduces the number of comparisons needed to locate the target element, making it more
efficient than linear search algorithms.
What is the time complexity of the bubble sort algorithm for an array of length n?

A) O(n)

B) O(n log n)

C) O(n^2)

D) O(log n)

ANSWER: C

Explanation: The bubble sort algorithm has a time complexity of O(n^2) in the worst and
average case scenarios. This means that the number of comparisons and swaps grows
quadratically with the size of the input array, making it less efficient compared to other sorting
algorithms such as quicksort or mergesort.

Which data structure is typically used to implement a queue?

A) Array

B) Linked list

C) Stack

D) Tree

ANSWER: B

Explanation: A linked list is commonly used to implement a queue data structure due to its
dynamic memory allocation and efficient insertion and deletion operations at both ends. In a
linked list-based queue, elements are added at one end (rear) and removed from the other
end (front), following the First-In-First-Out (FIFO) principle.

What is a searching algorithm?

A) A method for organizing data in memory

B) A technique for sorting elements in ascending order

C) A process of locating a specific item within a collection of data

D) A type of data structure used for retrieval operations


ANSWER: C

Explanation: A searching algorithm is a process or method used to locate a specific item or


element within a collection of data. Unlike sorting algorithms, which arrange elements in a
particular order, searching algorithms focus on finding a particular value efficiently within the
given data structure.

Which of the following best describes the linear search algorithm?

A) An algorithm that divides the search interval in half repeatedly

B) An algorithm that searches through a sorted array by comparing the target value with the
middle element

C) An algorithm that sequentially checks each element in a collection until a match is found or
the end of the collection is reached

D) An algorithm that relies on recursion to search through a collection of data

ANSWER: C

Explanation: The linear search algorithm, also known as sequential search, involves
sequentially checking each element in a collection until a match is found or the end of the
collection is reached. It is a simple and straightforward searching technique applicable to both
sorted and unsorted data.

What is the time complexity of linear search in the worst-case scenario?

A) O(n)

B) O(log n)

C) O(n^2)

D) O(1)

ANSWER: A

Explanation: The time complexity of linear search in the worst-case scenario is O(n), where n
is the number of elements in the collection being searched. This is because in the worst-case
scenario, the algorithm may need to examine each element in the collection sequentially until
it finds the target element or reaches the end of the collection.
Which searching algorithm is particularly efficient for large sorted arrays?

A) Linear search

B) Binary search

C) Depth-first search

D) Breadth-first search

ANSWER: B

Explanation: Binary search is particularly efficient for large sorted arrays because it operates
by repeatedly dividing the search interval in half, significantly reducing the number of
comparisons needed to locate the target element. It has a time complexity of O(log n) in the
worst-case scenario, making it highly efficient for large datasets compared to linear search.

What is a graph algorithm?

A) An algorithm used for sorting elements in a graph data structure

B) A method for organizing data in a graph format

C) A technique for searching through a collection of data

D) A process for solving problems related to graphs, such as finding paths or cycles

ANSWER: D

Explanation: A graph algorithm is a process or set of procedures designed to solve problems


related to graphs. These problems may include finding paths between nodes, detecting
cycles, determining connectivity, or analyzing the structure of a graph. Graph algorithms are
fundamental in various fields such as computer science, networking, operations research, and
social network analysis.

Which of the following best describes Dijkstra's algorithm?

A) An algorithm for finding the shortest path between two nodes in a weighted graph

B) An algorithm for detecting cycles in a directed graph

C) An algorithm for sorting elements in a graph data structure

D) An algorithm for determining the connected components in an undirected graph


ANSWER: A

Explanation: Dijkstra's algorithm is a popular graph algorithm used to find the shortest path
between two nodes in a weighted graph. It operates by iteratively exploring nodes in the
graph based on their distance from the starting node, updating the shortest distances and
paths as it progresses. Dijkstra's algorithm is commonly employed in applications such as
routing protocols, network analysis, and transportation planning.

What is the time complexity of Dijkstra's algorithm?

A) O(V)

B) O(E)

C) O(V + E)

D) O(V^2)

ANSWER: C

Explanation: The time complexity of Dijkstra's algorithm is O(V + E), where V is the number of
vertices (nodes) and E is the number of edges in the graph. This complexity arises from the
fact that the algorithm must visit each vertex and process each edge exactly once during its
execution, leading to a linear time complexity in terms of both vertices and edges.

Which graph algorithm is commonly used to find the minimum spanning tree of a graph?

A) Dijkstra's algorithm

B) Depth-first search (DFS)

C) Breadth-first search (BFS)

D) Prim's algorithm

ANSWER: D

Explanation: Prim's algorithm is commonly used to find the minimum spanning tree (MST) of a
graph. The MST is a subset of the edges of the original graph that forms a tree and includes
all the vertices of the original graph with the minimum possible total edge weight. Prim's
algorithm greedily selects edges with the smallest weight to construct the minimum spanning
tree efficiently.
What is a tree data structure?

A) A type of computer hardware used for processing data

B) A collection of sorting algorithms

C) A hierarchical data structure consisting of nodes connected by edges, with a single root
node at the top

D) A programming language designed for handling complex data structures

ANSWER: C

Explanation: A tree data structure is a hierarchical arrangement of nodes connected by


edges, with a single root node at the top. Each node can have zero or more child nodes, and
the relationship between nodes follows a parent-child hierarchy, similar to the branches of a
tree.

What is a binary search tree (BST)?

A) A tree structure used for sorting elements in ascending order

B) A tree structure where each node has more than two children

C) A tree structure where each node has at most two children, and the left child is less than
the parent, while the right child is greater

D) A tree structure used for storing images and multimedia files

ANSWER: C

Explanation: A binary search tree (BST) is a type of binary tree where each node has at most
two children: a left child and a right child. In a BST, the value of the left child is less than the
value of its parent node, and the value of the right child is greater than the parent node. This
property allows for efficient searching, insertion, and deletion operations.

Which traversal algorithm visits the nodes of a binary tree in the order: left subtree, root, right
subtree?

A) Inorder traversal

B) Preorder traversal

C) Postorder traversal
D) Level order traversal

ANSWER: A

Explanation: Inorder traversal visits the nodes of a binary tree in the order of left subtree, root,
and right subtree. This traversal strategy is commonly used to retrieve elements from a binary
search tree in sorted order.

What is the time complexity of searching in a balanced binary search tree (BST) with n
nodes?

A) O(log n)

B) O(n)

C) O(n log n)

D) O(1)

ANSWER: A

Explanation: The time complexity of searching in a balanced binary search tree (BST) with n
nodes is O(log n). This is because a balanced BST ensures that the height of the tree remains
logarithmic with respect to the number of nodes, resulting in efficient search operations
comparable to binary search on sorted arrays.

What is a string data structure?

A) A programming language designed specifically for text processing

B) A collection of characters or symbols arranged in a sequence

C) A type of computer hardware used for storing text data

D) A sorting algorithm specialized for organizing strings in lexicographical order

ANSWER: B

Explanation: A string data structure is a sequence of characters or symbols typically used to


represent text. Strings can include letters, digits, punctuation marks, and other special
characters. They are fundamental for text processing and are often manipulated using various
string algorithms.
Which algorithm is commonly used for pattern matching within a text?

A) Bubble sort

B) Depth-first search

C) Binary search

D) Knuth-Morris-Pratt (KMP) algorithm

ANSWER: D

Explanation: The Knuth-Morris-Pratt (KMP) algorithm is commonly used for pattern matching
within a text. It efficiently finds occurrences of a given pattern within a larger text by utilizing
the concept of prefix functions to avoid unnecessary comparisons.

What is the time complexity of the naive string matching algorithm?

A) O(n log n)

B) O(n^2)

C) O(log n)

D) O(n)

ANSWER: B

Explanation: The naive string matching algorithm compares each character of the pattern with
each character of the text, resulting in a time complexity of O(n^2), where n is the length of
the text. This algorithm is straightforward but may become inefficient for large texts or
patterns.

Which string algorithm is used for efficiently finding the longest common subsequence
between two strings?

A) Rabin-Karp algorithm

B) Boyer-Moore algorithm

C) Longest Common Subsequence (LCS) algorithm

D) Aho-Corasick algorithm

ANSWER: C
Explanation: The Longest Common Subsequence (LCS) algorithm is used for efficiently
finding the longest common subsequence between two strings. It employs dynamic
programming to identify the longest sequence of characters that appears in the same order in
both strings, allowing for various applications such as sequence alignment and similarity
measurement.

You might also like