final for data structure, Assignments of Data Structures and Algorithms

THis is the final assignment for data structures and algorithms course

Typology: Assignments

2021/2022

Uploaded on 05/18/2022

kawaii-unicorn
kawaii-unicorn 🇯🇴

5

(3)

6 documents

1 / 59

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
EVENT MANAGEMENT
SYSTEM
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b

Partial preview of the text

Download final for data structure and more Assignments Data Structures and Algorithms in PDF only on Docsity!

EVENT MANAGEMENT

SYSTEM

Contents

  • Task 1:.......................................................................................................................................................... - Task 1-A:................................................................................................................................................. - Task 1-B:.................................................................................................................................................
  • Task 2:........................................................................................................................................................ - Task 2-A:...............................................................................................................................................
    • Task 2-B:................................................................................................................................................
      • Task 2-C:................................................................................................................................................
  • Task 3:........................................................................................................................................................
  • Task 5:........................................................................................................................................................ - Task 5-A:...............................................................................................................................................
    • Task 5-B:................................................................................................................................................
    • Task 5-C:................................................................................................................................................
    • Task 5-D:................................................................................................................................................
  • Task 6:........................................................................................................................................................ - Task 6-A:...............................................................................................................................................
  • Task 7:........................................................................................................................................................ - Task 7-A:............................................................................................................................................... - Task 7-B:............................................................................................................................................... - Task 7-C.................................................................................................................................................
  • References:................................................................................................................................................

Task 1:

Task 1-A:

For this task I will use the linked list to implement Queue data structure, it is a

linear data structure which follows First in – First out (FIFO) order. I will use the

Queue because it has two ends, Cars will be inserted from one end (Rear), and it

will be deleted from the other end (Front).

First, I need nodes to create a linked list, each node has a two fields one for the

data and the other is a reference for the previous node. Each node represents a

car. Then, I need two reference variables (Rear & Front), Rear will point on the

first node of the linked list, and the Front will point on the last node of it.

There are four valid operations with The Queue data structure:

1) Enqueue: Is adding a node (Car) to the linked list from the Rear.

The reference field of the node will store a null. Another car arrived and it has the number 20. ( Enqueue(20) ). First, the reference variable (previous) of the node which Rear is pointing on will store the address of the new Node.

Then, the Rear will point on the new Node and the reference variable of the new Node will store a null. Another car arrived and it has the number 30. ( Enqueue(30) ). First, the reference variable (previous) of the node which Rear is pointing on will store the address of the new Node.

Now, the employee wants to remove a car from this Queue ( Dequeue() ). Here, we need a new temporary reference variable to Point on the node which Front is pointing at. Then, Front will point on its previous node by using the previous reference variable and assign a null value to previous

reference variable in the old (removed) node. Finally, the Queue will be like this. Special case: where there is one node in the Queue, we need to assign Null to the rear too.

Task 2:

Task 2-A:

I am using Stack data

structure to implement this

function because the last

unclosed bracket will be

closed first and that is what

makes the Stack useful here.

And here I used an array to implement the Stack just for example.

  1. Pop: is deleting an element from the top of the Stack.
  2. Top: returns the value which is at the top of the Stack.
  3. IsEmpty: Checks if the Stack is empty or not and returns a Boolean value for the result. All of these operations are performed in a constant time O(1) because there is no consideration for the amount of data.

Task 2-C:

The Stack data structure operations have a restriction that the time complexity should be constant O(1), therefore insertion and deletion should be performed from one end, and we can’t insert an item or delete it in specific position because we need to traverse to find this specific position and that depends on the number of items in the Stack in a linear manner, so the time complexity will be O(N) which is against the restriction. So, if we want to keep the time complexity constant O(1) the Stack should not have the insert, modify, and delete in specific position operations.

Task 3:

This is a code which converts any cryptocurrency to Bitcoin. And I will use it to explain how stack is used in function calls.

  1. The Main function is the first function which will be pushed with its local variables into the Stack.
  2. We can find that there is a call for the currencyToBitcion(CTB) function so it will be pushed with its local variables into the Stack, and the Main function will be paused. Push(); Pause
  1. There is no function calls left in currencyToBitcion(CTB) function, it will return a value then its execution will end and it will be popped from the Stack. Then Main function will resume its execution
  2. Finally, the Main function is out of function calls, so it will continue its statements execution, at the end it will be popped from the Stack, and the execution of the code will end hence the Stack will be empty. Resume Pop(); Resume Pop();

If we track what happens in the Stack it will be like this: End of the

When we want to calculate the space complexity we ignore the instruction space and consider data space and call Stack. Also, we ignore the function arguments (inputs). 2) Time Complexity : The space complexity of this code is O(n), because Each call function is added to call stack and takes up actual memory. The space complexity of this code is O(1), because it has a constant space complexity and it is 3 × 4 Bytes

It is the amount of time which a function may take to be executed and that is by showing how the runtime of the function increases along with the increasing of the size of inputs. Here are two codes to calculate the square of a number:

  • Modern day computers are fast, but they are not infinitely fast, and memory is inexpensive, but it is not available for free, therefore the space in the memory and the CPU time are limited and we should make optimal use of them by choosing a good The time complexity of this code is O(1), because it takes a constant time to be executed with no consideration to (n). The time complexity of this code is O(n), because runtime will change with the change of (n). (s += n) will be executed approximately (n) times.