0% found this document useful (0 votes)
99 views11 pages

DSA ASSIGNMENT 1 and 2

The document describes Abdul Wasay's assignments for data structures and algorithms. It includes questions about how efficient data structures and algorithms can help in modeling and simulation, and applying concepts to modeling/simulations and computer graphics. Abdul provides examples like using queues to model customer service, and using pointers and lists to represent geometric shapes. The document also includes algorithms to sort arrays, count comparisons in finding the largest element, and insert a pattern into a string using stacks to implement queues.

Uploaded by

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

DSA ASSIGNMENT 1 and 2

The document describes Abdul Wasay's assignments for data structures and algorithms. It includes questions about how efficient data structures and algorithms can help in modeling and simulation, and applying concepts to modeling/simulations and computer graphics. Abdul provides examples like using queues to model customer service, and using pointers and lists to represent geometric shapes. The document also includes algorithms to sort arrays, count comparisons in finding the largest element, and insert a pattern into a string using stacks to implement queues.

Uploaded by

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

ABDUL WASAY

DR.PROF.Ghazenfer khan 19B-009-TE

ASSIGNMENT NO # 01
Q1) Describe how the use of efficient data structures & algorithms can be helpful in the selected
field. The description should not be less than 150 words and more than 200 words.
ANSWER: In order to be able to store and retrieve information, a data structure is an
arrangement of data. A data structure is typically some sort of physical representation of an
ADT. Through data structure and algorithm we do everything like automation, modeling,
computer system etc. Programming is all about structures and algorithms for knowledge. Data
structures and algorithms go through comprehensive solutions to standard issues and provide you
with an insight into how easy it is to use each of them. It also teaches us the science of measuring
an algorithm's effectiveness. This helps you to select the best of several options. We sort a lot of
complex problem of real world and in modeling and simulation there is so much use of it. It is
possible to use various modelling algorithms in modelling and simulation. For example, in order
to analyze the data, the analyst may use unsupervised approaches. If an interesting group or
relationship is established, then it is possible to establish and use a supervised learning method to
find new cases. In fraud detection, an instance of this method can be seen.
Q2) Discuss, with concrete reasoning, at least two cases where concepts of data structures &
algorithms can be specifically applied in this field. Each case should not be less than 250 words
and not more than 300 words.

CASE 1: MODELING AND SIMULATIONS:


In modeling and simulation there is vast use of data structure and algorithm. We use modeling
and simulation to sort out our complex daily life problem very efficiently and effectively. For
example we use modeling simulation through data structure for customer service. Finding the
optimal number of workers to provide customers entering a bank with a predefined level of
service. The service level was described as the mean size of the queue. In order to set the
specifications of the simulation model, appropriate system measurements were then chosen , the
number and duration of customer visits, the time teller takes to addresses the customer, and the
natural variations that may take place. In this example we realize that queues which are the part
of data structure can be used through modeling simulation of customer services. Another
example is modeling and simulation communications networks in which links and nodes are
used as network nodes which is source and links are connected all individual data from source to
receiver through routing. The algorithm for routing used in a network found one of its
neighbours is selected by an intermediate node as the next node the message should be sent to.
Routing algorithm determine the route Oriented by a message, The state of the system is the
compilation of all Individual states of the node and connection. A centralized, full and up-to-date
knowledge of the network cannot be preserved for broad network models. Modeling assumes
that network nodes independently receive global network state data through suitable update
procedures. We can see that how efficiently data structure used in modeling and simulation and
resolve and sort out complex problem.
ABDUL WASAY
DR.PROF.Ghazenfer khan 19B-009-TE

CASE 2: COMPUTER GRAPHICS:


Many sophisticated data structures have been developed for preserving geometric artefacts in
computational geometry. Many of these structures can be very helpful in solving a variety of
computer graphics difficulties. It has so much use of data structure like image processing, pattern
recognition algorithm, image segmentation etc all are comes in the field of computer graphics
and thereby can be done through data structure. Can we think how any size of image is visible on
our computer this is also resolve through computer graphics by implementation of different
Algorithm data structure techniques. Many geometric data structures are static, i.e., they do not
allow objects to be inserted and deleted. Some general dynamic techniques that can be used to
transform static data structures into dynamic structures will be addressed. Now we take example
of geometric data of computer graphics. In geometric data we use structure pointers, array and
link list to generate algorithm of different geometric shapes like polyhedral objects, triangles and
diamond and other different curves. Another example is the quad-tree in computer graphics is
perhaps the most well-known data structure. Quad-trees can be used, both in image space and in
object space, for storing planar objects. They use little storage and often allow geometric
information to be quickly retrieved. One more example is for so-called multi-dimensional data
structures, range trees are a simple example. For example, they allow very quick searches to
locate the points in a set lying in a given rectangle. In an effective way, segment trees store
intervals, For example line segments. We can see the some application of computer graphics
where whole procedure is effectively depended and based on data structure algorithm.
Q3) Any ideas from your side than can further be used to improve the system you have
discussed in ii.
Answer)In my opinion using data structure we can further modify in network communication
doubly link list or through quad-tree structure through this we can elapse less time and more
speed on transfer data to the right receiver. In second case computer graphics visualization,
Animation And 3D modeling can also be more efficiently and effectively through different
technique algorithms. These are my some ideas about my cases according to my knowledge and
from articles.

REFRENCES:
1. https://www.anylogic.com/use-of-simulation/
2. https://lib.dr.iastate.edu/cgi/viewcontent.cgi?article=1136&context=cs_techreports
3. http://vr.me.ncku.edu.tw/courses/cg95/download/CG7.pdf
4. https://link.springer.com/chapter/10.1007/978-3-642-83539-1_1

ASSIGNMENT NO # 02
Question 1 Following is an algorithm for Sorting an array:
ABDUL WASAY
DR.PROF.Ghazenfer khan 19B-009-TE

Procedure: SORT(A, N)Where A is the array with N elements. This procedure sorts the array A having N
elements.

1. Repeat steps 2 to 4 for J = 1 to N –1.


2. Set MIN := J.
3. Repeat for K = J + 1 to N.
a. If A[K] < A[MIN], then:
Set MIN : = J.
[end inner for-loop]
4. Swap A[J], A[MIN].
[end outer for-loop]
5. return
Understand the algorithm and describe its working by specifying every single pass using the
following array of integers:
12, 23, 56, 38, 19, 45

IMPLEMENTATION:
PASS 1:
12 23 56 38 19 45

12 23 56 38 19 45

12 23 38 56 19 45

12 23 38 19 56 45

12 23 38 19 45 56

PASS 2:
12 23 38 19 45 56

12 23 38 19 45 56
ABDUL WASAY
DR.PROF.Ghazenfer khan 19B-009-TE

12 23 19 38 45 56

12 23 19 38 45 56

12 23 19 38 45 56

PASS 3:
12 23 19 38 45 56

12 19 23 38 45 56

12 19 23 38 45 56

PASS 4:
12 19 23 38 45 56

12 19 23 38 45 56
PASS 5:
12 19 23 38 45 56
Question 2) Let C denotes the number of times LOC is updated to find the largest element
in array A with N elements. Write a procedure COUNT(A, N, C)which finds C.
ANSWER:
ALGORITHM:
STEP 1: START [Initialize] Set LOC=1 LARGEST=A[1]
STEP 2: Repeat STEP 3 and 4 for C=1 to C<=N, then:
STEP 3: If LARGEST< A[C] then :
LOC = C , LARGEST = A[C]
[ end of if structure ]
STEP 4: Set C++
[ end of Step 2 ]
STEP 5: Write C , LARGEST
ABDUL WASAY
DR.PROF.Ghazenfer khan 19B-009-TE

STEP 6: END
Question 3) Write a procedure INSERT (P, T, LOC, R, S)that inserts pattern P in string T
having lengths R and S respectively, at location LOC.
ANSWER:
ALGORITHM:
STEP 1: [Initialize] Set T: =text, LOC: =position and P: =pattern
STEP 2: Set R:= SUBSTRING (T, 1, LOC-1)
STEP 3: Set S:= SUBSTRING (T, K, LENGTH (T)-LOC+1)
STEP 4: [Concatenate] Set P2:=R||P||S
STEP 5: Write: P2
STEP 6: Exit

Question 4) Can stacks be used to implement queues? If yes, show how to implement a
queue using stacks and describe the working of your algorithms (enqueue and dequeue)
using appropriate diagrams.
ANSWER: Yes, stack can be used to implement queues. We uses two stacks to implement
queues first we added element in first stack (stack_1) then then pop (removing) the element and
pushed (added) in second stack (stack_2) thus in result it reverses the arrangement (order) of
element and forms a Queue. We will discuss and describe with the help of diagram to understand
enqueue and dequeue method.
ALGORITHM [ENQUEUE(ITEM)]:
STEP 1: START [initialize S1 and S2]
STEP 2: Repeat STEP 3 While S1 != empty
STEP 3: push S1 to S2.TOP and pop S1
[end of loop]
STEP 4: push ITEM to S1
STEP 5: Repeat STEP 6 While S2 != empty
STEP 6: push S2 to S1.TOP and pop S2
[end of loop]
STEP 7: EXIT
ABDUL WASAY
DR.PROF.Ghazenfer khan 19B-009-TE

4
Rear Front
3

Stack_1 Stack_2
ENQUEUE
ALGORITHM [DEQUEUE]:
STEP 1: START [initialize S1 and S2]
STEP 2: [Check] if S1 = empty
Write “queue is empty” and return
STEP 3: Then;
ITEM= S1 TOP
STEP 4: pop S1 and Return ITEM
STEP 5: END

Push pop
pop
1
Rear Front
2

Stack_1 Stack_2
DEQUEUE
ABDUL WASAY
DR.PROF.Ghazenfer khan 19B-009-TE

Question 5) Consider the following Tower of Hanoi with 4 discs:


Describe the working of the recursive method of moving the entire stack of discs from
SOURCE to DEST using appropriate diagram.
n
ANSWER) Hanoi{2 – 1 if n > 1}= 24 – 1 = 16-1 = 15

SOURCE DEST AUX

1)

SOURCE DEST AUX

2)

SOURCE DEST AUX

3)
ABDUL WASAY
DR.PROF.Ghazenfer khan 19B-009-TE

SOURCE DEST AUX

4)

SOURCE DEST AUX

5)

SOURCE DEST AUX

6)

SOURCE DEST AUX

7)

SOURCE DEST AUX

8)
ABDUL WASAY
DR.PROF.Ghazenfer khan 19B-009-TE

SOURCE DEST AUX

9)

SOURCE DEST AUX

10)

SOURCE DEST AUX

11)

SOURCE DEST AUX

12)

SOURCE DEST AUX

13)
ABDUL WASAY
DR.PROF.Ghazenfer khan 19B-009-TE

SOURCE DEST AUX

14)

SOURCE DEST AUX

15)

SOURCE DEST AUX


ABDUL WASAY
DR.PROF.Ghazenfer khan 19B-009-TE

TREE DIAGRAM:

You might also like