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

Assignment 1.

Uploaded by

shaikrehan4908
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Assignment 1.

Uploaded by

shaikrehan4908
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Shaik Sana Tabasum

20023002361

Assignment 1

1Q) What is ADT? Give full form.

ADT stands for Abstract Data Type. It defines a data type by its values and operations, without
specifying its implementation.

(it means that adt tells you what kind of data it can hold(numbers, letters) and what you can
do with the data (add, remove, search)

________________________________________________________________________________________________________

2Q) Give the names of linear types of data structures and nonlinear data structures

Linear:

Array
Linked List
Stack
Queue

Non-Linear:

Tree (Binary Tree, Binary Search Tree)


Graph

________________________________________________________________________________________________________

3Q) What is an array?

An array is a collection of items of the same data type stored in contiguous memory locations

________________________________________________________________________________________________________

4Q) What is low level / static and dynamic arrays ?

Static Arrays: Static arrays are data structures with a fixed size that is determined at compile
time(size of the array is decided when the code is compiled). Once defined, the size of a
static array cannot be altered
Dynamic Arrays: Dynamic arrays allow for variable sizes that can be determined at runtime
(size of the array can be adjusted while the program is executing, you can remove or add
elements). This flexibility makes them suitable for applications where the number of elements
may change frequently.

________________________________________________________________________________________________________

5Q) What is overflow and underflow conditions in data structures ?

Overflow

Overflow occurs when you try to insert an element into a data structure that is already
full. There is no more space available to accommodate the new element.
Stacks: If you try to push an element onto a stack that has reached its maximum
capacity, an overflow occurs.
Queues: If you try to enqueue an element into a full queue, an overflow occurs.
Arrays: If you try to insert an element beyond the declared size of an array, it can lead
to an overflow (writing to memory outside the array's bounds).

Underflow

Underflow occurs when you try to remove an element from a data structure that is
already empty. There are no elements to remove.
Stacks: If you try to pop an element from an empty stack, an underflow occurs.
Queues: If you try to dequeue an element from an empty queue, an underflow occurs.

________________________________________________________________________________________________________

6Q) What are the asymptotic symbols? Which symbol is used to show worst case, best case
and average case complexity?

Asymptotic Symbols

These symbols are used to describe the growth rate of functions (like the time or space an
algorithm takes) as the input size approaches infinity. The main ones are:

Big O notation (O): Describes the upper bound or worst-case complexity. It represents
the maximum amount of time or space an algorithm will take.
Omega notation (Ω): Describes the lower bound or best-case complexity. It represents
the minimum amount of time or space an algorithm will take.
Theta notation (Θ): Describes the tight bound or average-case complexity (in some
situations). It represents both the upper and lower bounds, meaning the algorithm's
performance is within a specific range.

________________________________________________________________________________________________________

7Q) What is tightly bound complexity ?


Tightly bound complexity means the algorithm's performance is both upper and lower
bounded by the same function (growth rate), giving a precise characterization of its resource
usage. Theta notation (Θ) expresses this.

________________________________________________________________________________________________________

8Q) What is worst case, best case and average case complexity of linear search ?

Worst Case Complexity

In the worst-case scenario, the element being searched for is either not present in the list
or located at the last position. This means that every element must be checked, resulting
in a time complexity of O(n)O(n), where n is the number of elements in the list

Best Case Complexity

The best-case scenario occurs when the target element is found at the first position of
the list. In this case, only one comparison is needed, leading to a time complexity of
O(1)O(1)

Average Case Complexity

The average case assumes that the target element could be located anywhere in the list.
On average, it would take about half of the elements to be checked, which results in a
time complexity of O(n)O(n), similar to the worst case

Worst Case: O(n)O(n)


Best Case: O(1)O(1)
Average Case: O(n)O(n)

________________________________________________________________________________________________________

9Q) Give worst case complexity or binary search

The worst-case time complexity of binary search is O(log⁡n)O(logn)

________________________________________________________________________________________________________

10Q) What is the minimum condition to go for binary search?

Sorted Data Structure: The array or list must be sorted in either ascending or descending
order
Random Access Capability: The data structure should allow for constant-time access to
its elements, which is characteristic of arrays. This means you can directly access any
element using its index.

________________________________________________________________________________________________________
11Q) Which search is also called as sequential search?

The search method that is also called sequential search is known as linear search.

________________________________________________________________________________________________________

12Q) What is double ended queue ? whats its condition of full and empty?

A double-ended queue (deque) is a data structure that allows insertion and deletion of
elements from both the front and rear ends.

Full Condition: A deque is full when (rear + 1) % size == front.


Empty Condition: A deque is empty when front == rear.

________________________________________________________________________________________________________

13Q) What are conditions of full and empty for two stacks in one array ?

Full Condition: top1+1==top2top1+1==top2


Empty Condition for Stack 1: top1==−1top1==−1
Empty Condition for Stack 2: top2==sizetop2==size

________________________________________________________________________________________________________

14Q) List the data structure operations

1. Insertion
2. Deletion
3. Search
4. Traversal
5. Sorting
6. Merging
7. Reversal
8. Indexing

________________________________________________________________________________________________________

15Q) What is amortized analysis ?

Amortized Analysis is a technique used to evaluate the average performance of an algorithm


over a sequence of operations, rather than focusing on the worst-case time complexity of
individual operations.

________________________________________________________________________________________________________

16Q) What is pointer ? give example

A pointer is a variable that stores the memory address of another variable. It allows direct
access to memory locations, enabling efficient manipulation of data structures and dynamic
memory management.

________________________________________________________________________________________________________

17Q) What is priority queue ? give its applications

A priority queue is a specialized type of queue in which each element is associated with a
priority value. In a priority queue, elements with higher priority are served before those with
lower priority. If two elements have the same priority, they are served according to their
order in the queue

Applications of Priority Queues:

1. Task Scheduling: Operating systems use priority queues to manage processes by


scheduling tasks based on their priorities.
2. Graph Algorithms: Algorithms like Dijkstra’s and Prim’s use priority queues to efficiently
find the shortest paths or minimum spanning trees.

________________________________________________________________________________________________________

18Q)Can we can use heaps to implement the priority queue ?

Yes, heaps are an excellent and common way to implement priority queues. In fact, they are
often the preferred implementation due to their efficiency.

________________________________________________________________________________________________________

19Q) How the array is initialized in c

int a[4]={7,8,22,4};

int a={7,8,22,4}

int a()={7,8,22,4}

int a[n]={7,8,22,4}

int a = {7,8,22,4}; is invalid because it does not specify an array size or use square
brackets.
int a() = {7,8,22,4}; is invalid as it attempts to declare a function instead of an array.
int a[n] = {7,8,22,4}; is valid only if n is defined as a constant expression at compile time.

________________________________________________________________________________________________________

20Q) . What is the output of the following program

void display() {

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


int sum = 0;

for(int i = 0; i < 5; i++) {

if(i % 2 == 0) {

sum += a[i]; }

printf(“%d”,sum);

A) 9 is the output of the program

________________________________________________________________________________________________________

21Q) What is the time complexity of the following code

void showstring() {

char s[] = "scaler";

int n = s.size();

for(int i = 0; i < n; i++) { s = s + s[i]; }

} printf(“%s”,s)

A) O(n)

________________________________________________________________________________________________________

22Q) Which searching algorithm uses Divide and Conquer method?

Binary search, Merge sort, Quick sort

You might also like