Data Structures and Algorithms: Assignment 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

University of Engineering and Technology Peshawar

Data Structures and Algorithms


Assignment 1

Submitted by:
Muhammad Maaz Khan
19PWBCS0687
Section B
3rd semester

Submitted to:
Dr. Iftikhar Ahmad

Muhammad Maaz Khan


1) Importance of Data Structures

Data Structures:

Data structures are the different techniques and data objects that are used to manage data
efficiently in memory.

Importance of Data Structures:

As computer programs are getting more complex from time to time, we need more reliable and
efficient ways of managing the data that these programs utilize. With growing data, we need
faster processors, more storage and more time to access data properly, so we need to apply
such techniques that would allow us to manage data that would require less processing power,
less storage space and less time, so we need data structures for optimal retrieval, storage and
processing of data, to tackle with the concerns of time, storage and processing power.

Applications of Data Structures:

Well as for applications of data structures in computer science almost all programs use some
form of data structures. But here are some few examples:

 Augmented Reality
 Operating Systems
 Graphical Analysis
 Booking Systems like of hotels, flights, restaurants etc.
 Google Maps
 Video Play Lists

2) Worst Case complexity of Algorithm 1


procedure MatElementsSum (A[0 . . . n − 1, 0, . . . m − 1])

2: sum = 0 ---1

3: for i = 0 to n − 1 do ---n-1

Muhammad Maaz Khan


4: for j = 0 to m − 1 do ---m-1 * n-1

5: sum = sum + A [i, j]

6: end for

7: end for

8: return sum ---1

9: end procedure

By equating m=n we derive O(n2). So it’s time complexity is quadratic.

Worst Case:

It’s worst case is also O(n2) because it is a sum algorithm and it will sum all the input
always.

3) Output and Worst Case of Algorithm 2


1: procedure FindSum( )

2: sum = 0 ---1

3: I = 10. ---1

4: N = 100. ---1

5: while I ≤ N do ---log n ( It is log n because N is decreasing by half after each iteration.)

6: sum = sum + I.

7: N = N/2.

8: end while

9: return sum. ---1

Muhammad Maaz Khan


10: end procedure

Output:

Output of this Algorithm is 40.

Worst Case:

Worst case time complexity is O(log n).

4) Optimum size of array to marks data of students above 60 marks


I would declare an array for size 300 for storing marks of students that have obtained 60
+ marks. My answer for my solution is that the number of students that would obtain
over 60 marks in the paper are not known. There is a possibility that all of the students
obtain over 60 marks, so If I declare an array of size less than 300, or whatever the size
of my array is, and the number of students that obtain marks over 60 exceed the size of
my array, than I would have to write extra code for copying the existing array items to a
larger sized array, and that would than occupy extra memory and also consume more
time. An ideal solution would be using linked lists.

Muhammad Maaz Khan

You might also like