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

DSA Worksheet One-2017EC

ASTU DSA

Uploaded by

chalchisa.takala
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)
6 views

DSA Worksheet One-2017EC

ASTU DSA

Uploaded by

chalchisa.takala
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/ 2

Adama Science and Technology University

College of Electrical Engineering and Computing


Department of Computer Science and Engineering

CSEg 2101: Data Structure and Algorithms Worksheet I


1. Discuss the following with example
a. Data structures e. Discuss different ways of representing algorithms
b. Primitive/Primary Data structures f. Empirical Analysis of Algorithms
c. Abstract Data Type g. Theoretical Approach for Algorithm Analysis
d. Algorithm and its properties. h. Asymptotic Analysis of Algorithms

2. Write the definition for Big-O and using the definition show that
a. √ b.
3. Arrange the following running times in increasing order of asymptotic growth. Justify your answer!

4. For each of the following six program fragments compute T(n) and Big-O
(1) sum = 0; (4) sum = 0;
for( i = 0; i < n; ++i ) for( i = 0; i < n; ++i )
++sum; for( j = 0; j < i; ++j )
++sum;
(2) sum = 0; (5) sum = 0;
for( i = 0; i < n; ++i ) for( i = 0; i < n; ++i )
for( j = 0; j < n; ++j ) for( j = 0; j < i * i; ++j )
++sum; for( k = 0; k < j; ++k )
++sum;
(3) sum = 0; (6) sum = 0;
for( i = 0; i < n; ++i ) for( i = 1; i < n; ++i )
for( j = 0; j < n * n; ++j ) for( j = 1; j < i * i; ++j )
++sum; if( j % i == 0 )
for( k = 0; k < j; ++k )
++sum;

5. Write the algorithm, find the running time T( ) and the Big-O class for the following problems.
a. Finding the minimum in list of numbers size .
2 2 2 2
b. Finding the sum: 1 +2 +3 +…+ where is a positive integer
th
c. Finding the largest number in list of numbers size N.
d. Copy an array of integers A in to an array B of same size
e. Adding two matrices A and B of size
f. Multiplying two matrices A and B of size
g. For determining a positive number is prime or not
6. An algorithm takes 0.5 ms for input size 100. How large a problem can be solved in 1 min if the running
time is the following:

3
a. T(n)=n b. T(n)=nlgn c. T(n)=n
7. What is searching? Give the algorithm for the following known searching algorithms and their efficiency in
best and worst case.
a. Sequential/ Linear Search
b. Binary Search(provide recursive and non recursive algorithms)
8. What is sorting? Give the algorithm for the following known sorting algorithms and their efficiency in best
and worst case.
a. Insertion sort b. Selection sort c. Bubble sort
d. For the following list show the partially sorted list after each iteration of the outer loop.
8, 9, -1, 5, 0,-2
9. Array is a popular data structure for storing list of items. What is an Array? Discuss its advantage and
limitations.
th th
10. The common operations performed on array include: Accessing i element, inserting at i position,
th
deleting the i element, searching, sorting , copying elements. Using c++:
a. Provide implementation for ADT “MyArray” that supports all the operations listed above. You
can use either struct or class for the ADT definition:
Hint: define the ADT as follows and provide implementation of the above operations

#define MAX 100


struct MyArray{
int data[MAX];
int n=-1;
}

b. Using a static array like above may limit the maximum number of elements to be stored on the
array. Can you provide a dynamic array implementation that increases size when array is full?
Hint: define the ADT as follows using pointer and provide implementation for initialize,
increaseSize operation. increaseSize can be done by creating a new array of double size and
copying all elements.

struct MyDynamicArray{
int *data=NULL;
int n=-1;
}

11. Define Stack.


12. Define Queue.
13. What is the major difference of Stack and Queue
14. Implement Stack and Queue using array.
15. Evaluate the following postfix expression using stack. At each iteration show the content of the stack.
6 5 2 3 + 8 ∗ +3 + ∗
16. Convert the following infix expression to postfix expression using stack. At each iteration show the
content of the stack and the postfix output
a + b * c/d + ( e * f + g ) * h
17. Write a program to reverse a string(character array) using a stack
18. Write a code to implement circular queue (all operations i.e. enque(), display and deque() operations)
19. Given two sorted arrays of integers, L1 and L2, write a function to compute
a. the intersection between L1 and L2
b. the union of L1 and L2 as sorted list L3

You might also like