wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

DSA Basics

Total questions: 67

Worksheet time: 1hrs 15mins

Name
Class
Date
1.

Example of linear data structure except

a)

array

b)

tree

c)

queue

d)

stack

2.

If you want the method to return a value, you can use a primitive data type instead of void, and use the (a)   keyword inside the method.

(use small letters and space if necessary)

3.

A data structure which is a programming technique you can use in which a method calls itself to solve a problem.

(use small letters and space if necessary)

(a)  

4.

(a)   is a collection of elements used to store the same type of data.

(use small letters and space if necessary)

5.

int num[ ] = {11, 2, 99, 4, 33, 14, 18};

How would you access the fourth element in num.

(no spacing in writing the answer)

(a)  

6.

A recursive method is ________

a)

a method that cannot be called more than once

b)

a method that will never iterate infinitely

c)

a method that invokes itself by name within the method

7.

Index values of an array ranges from ________.

a)

0 to length

b)

1 to length

c)

1 to length

d)

0 to length-1

8.

The program may run out of memory in a ___

a)

non-recursive function call

b)

condition when too many variables are declared

c)

recursive function call

d)

none of the above

9.

Which of the following problems can be solved using recursion?

a)

finding the factorial of a number

b)

finding Nth number of the Fibonacci sequence

c)

finding the length of a string

d)

all of the above

10.

(a)   act as variables inside the method.

(plural form, use small letters and space if necessary)

11.

Name the condition at which the recursive method will stop calling itself.

(use small letters and space if necessary)

(a)  

12.

float numarr[4];

What is the range of the index?

(use numerical value and write "to" in-between the range, use space if necessary)

(a)  

13.

When a parameter is passed to the method, it is called an (a)   .

(singular form, use small letters and space if necessary)

14.

int[] arr;

Write the instantiating code with the length of 5.

(use proper symbol, space before and after "=" symbol)

(a)  

15.

What is the error in the following code fragment?

float ave[20];

ave[20]=10.44;

a)

a cast is required

b)

a two-dimensional array is required

c)

data not initialized

d)

array out-of-bounds

16.

What would happen if the base case if not defined in the recursive method?

a)

stack underflow

b)

index out of bounds

c)

stack overflow

d)

none of the above

17.

What is the output?

(a)  

18.

Methods are used to perform certain actions, and they are also known as (a)   . (plural form, use small letters and space if necessary)

19.

Java code to display the size of an array name studname[ ].

a)

System.out.println("The size is " + studentname[ index ]);

b)

System.out.println("The size is " + length.length);

c)

System.out.println("The size is " + studentname);

d)

System.out.println("The size is " + studname.length);

20.

Identify the name of the array based on the code segment below:

for(int j=0; j<studnum.length; j++) {

System.out.print("Enter student number: ");

(a)  

}

21.

Insert the missing part in creating and instantiating an array.

int[] arr = { 77, 22, 44}

(a)  

22.

An algorithm should be in the right order.

Write T if the statement is TRUE otherwise F.

(a)  

23.

A mathematical-model with a collection of operations defined on that model is called _____.

a)

algorithm

b)

data structure

c)

data type

d)

abstract data type

24.

When you write an algorithm you need to include ________, step-by-step instructions.

a)

ambiguous

b)

multiple

c)

clear

d)

precise

25.

It is a property to get the size of an array.

(use small letters and spacing if necessary)

(a)  

26.

double[][] arr = {{4.2, 4.3, 4.0}, {4.1, 4.4} };

What is the element in arr[1][0] ?

(a)  

27.

How is the 2nd element in an array accessed based on pointer notation?

a)

*a + 2

b)

*(a + 2)

c)

*(*a + 2)

d)

&(a + 2)

28.

Which of the following is example of in-place algorithm?

a)

Bubble Sort

b)

Merge Sort

c)

Insertion Sort

d)

All of the above

29.

The data structure required to check whether an expression contains a balanced parenthesis is?

a)

Stack

b)

Queue

c)

Array

d)

All of the above

30.

When does the ArrayIndexOutOfBoundsException occur?

a)

Compile-time

b)

Run-time

c)

Not an error

d)

Not an exception at all

31.

What is the speciality about the inorder traversal of a binary search tree?

a)

It traverses in a non increasing order

b)

It traverses in an increasing order

c)

It traverses in a random fashion

d)

It traverses based on priority of the node

32.

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)

33.

The following formula will produce

Fn = Fn-1 + Fn-2

a)

Armstrong Number

b)

Fibonacci Series

c)

Euler Number

d)

Prime Number

34.

A priority queue can efficiently implemented using which of the following data structures? Assume that the number of insert and peek (operation to see the current highest priority item) and extraction (remove the highest priority item) operations are almost same.

a)

Linked List

b)

Array

c)

Heap Data Structures like Binary Heap, Fibonacci Heap

d)

None of the Above

35.

Which of the following is a true about Binary Trees

a)

Every binary tree is either complete or full.

b)

Every complete binary tree is also a full binary tree.

c)

Every full binary tree is also a complete binary tree.

d)

No binary tree is both complete and full.

e)

None of the Above

36.

The preorder traversal sequence of a binary search tree is 30, 20, 10, 15, 25, 23, 39, 35, 42. Which one of the following is the postorder traversal sequence of the same tree?

a)

30, 20, 15, 23, 25, 35, 42, 39, 10

b)

30, 10, 25, 23, 20, 42, 35, 39, 15

c)

30, 20, 10, 23, 25, 42, 35, 39, 15

d)

15, 10, 23, 25, 20, 35, 42, 39, 30

37.

 

Which of the following traversal outputs the data in sorted order in a BST?

a)

Preorder

b)

Inorder

c)

Postorder

d)

Level Order

38.

 

Consider a node X in a Binary Tree. Given that X has two children, let Y be Inorder successor of X. Which of the following is true about Y?

a)

Y has no right child

b)

Y has no left child

c)

Y has both children

d)

None of the above

39.

In binary tree,the maximum number of nodes at any level n is:

a)

n

b)

2^n

c)

n+1

d)

2*n

40.

.What is the best case time complexity of the binary search algorithm

a)

O(1)

b)

O(n)

c)

O(log(2*n))

d)

O(n^2)

41.

In linked list implementation of a queue, front and rear pointers are tracked. Which of these pointers will change during an insertion into EMPTY queue?

a)

Only front pointer

b)

Only rear pointer

c)

Both front and rear pointer

d)

No pointer will be changed

42.

What is the worst case complexity of selection sort?

a)

O(nlogn)

b)

O(logn)

c)

O(n)

d)

O(n^2)

43.

What is the value of the postfix expression 6 3 2 4 + - * ?

a)

1

b)

40

c)

74

d)

-18

44.

The operation of processing each element in the list is known as

a)

Sorting

b)

Merging

c)

Inserting

d)

Traversal

45.

What programming language are you most comfortable with?

a)

C

b)

Python

c)

Java

46.

On a scale of 1-10, how comfortable are you with coding?

a)

1-3 (Beginner)

b)

4-7 (Intermediate)

c)

8-10 (Expert)

47.

What is your favorite data structure?

a)

Array

b)

Stack

c)

Tree

d)

I have no favorite/I don't know any data structures.

48.

How do you usually handle a new programming problem?

a)

I jump straight into coding

b)

I take time to design the solution on paper first

c)

I discuss it with others to gather ideas

49.

What is your previous experience with computer security?

a)

No experience

b)

Some online courses

c)

A lot of self-study

d)

Professional experience

50.

Which of the following real-world scenarios do you think DSA could most impact?

a)

Speeding up a slow computer

b)

Optimizing a company's data storage

c)

Helping an artist organize their digital assets

51.

If you were tasked to design a secure system for a bank, which of the following would be your primary concern?

a)

Ensuring fast and efficient transactions

b)

Preventing unauthorized access to customer data

c)

Making sure the system is always available

52.

Which scenario is an example of a security vulnerability caused by improper implementation of a data structure?

a)

A music streaming application is unable to recommend songs based on a user's past listening history.

b)

A software application stores user passwords in plain text, instead of using a hashed data structure.

c)

An online store's search function takes too long to return results, causing users to leave the website

53.

If you could use one word to describe your feelings about data structures and algorithms course, what would it be?

4 lines
54.

What are your expectations from this course?

4 lines
55.

Which of the following is not a stable sorting algorithm?

a)

Bubble sort

b)

Selection sort

c)

Quick sort

d)

None of these

56.

Which of the following is/are in-place sorting algorithm(s)?

a)

Selection sort

b)

Bubble sort

c)

Quick sort

d)

Merge sort

57.

The worst-case time complexity of a quick sort algorithm?

a)

O(nlogn)

b)

O(logn)

c)

O(n^2)

d)

O(n^2logn)

58.

The no.of comparisons in first pass in bubble sort to sort n numbers is....?

a)

n

b)

n(n-1)/2

c)

n-1

d)

n^2

59.

The maximum no.of swappings in first pass of selection sort to sort n numbers is....?

a)

1

b)

n(n-1)/2

c)

n-1

d)

n^2

60.

In quick sort, based on key or pivot element position, the list is partitioned into how many sub-lists?

a)

1

b)

2

c)

3

d)

4

61.

If the list is almost sorted, then which of the following algorithm gives the better performance?

a)

Bubble sort

b)

Selection sort

c)

Quick sort

d)

All of these

62.

If the list is almost sorted, then which of the following algorithm is/are not suitable?

a)

Bubble sort

b)

Selection sort

c)

Quick sort

d)

All of these

63.

In bubble sort, what will be the sequence of the following elements after 7 passes?

20 15 14 45 11 18 78 95

(a)  

64.

In bubble sort, what will be the sequence of the following elements after 1st pass?

2 1 4 45 11 18 78 95

(a)  

65.

In selection sort, what will be the sequence of the following elements after 2nd pass?

8 6 3 7 63 4 10 103 61

(a)  

66.

The no.of passes in selection sort to sort n numbers is .....?

a)

n

b)

n-1

c)

n^2

d)

logn

67.

The no.of swapings in selection sort to sort n numbers is .....?

a)

n

b)

n-1

c)

n^2

d)

logn