Docsity

Data Structures and Algorithms: A Practical Guide with Examples, High school final essays of Computer science

Toggle sidebar
bg1
Part 1:
You will need to prepare a written document which demonstrates the followings
● Create a design specification for data structures explaining the valid operations that can be
carried out on the structures and determine the operations of a memory stack and show how it is
used to implement function calls in a computer.
● Illustrates, with an example, a concrete data structure for a First In First out (FIFO) queue and
compare the performance of two sorting algorithms. Further, produce an analysis of the operation
of the two network shortest path algorithms providing an example of each.
P1 Create a design specification for data structures explaining the valid operations that can
be carried out on the structures.
Introduction
As I am one of the software engineers working in this . B2C Pvt Ltd which is a software
company that works on projects based on machine learning, artificial intelligence, IOT(internet
of Things) etc. Now I am assigned the responsibility to prepare document so as to show your
company understands on use of different ADTs, different sorting and searching algorithms, their
applications and efficiency. sorting and searching algorithms, their applications and efficiency.
Data structure:
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
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Data Structures and Algorithms: A Practical Guide with Examples and more High school final essays Computer science in PDF only on Docsity!

Part 1:

You will need to prepare a written document which demonstrates the followings ● Create a design specification for data structures explaining the valid operations that can be carried out on the structures and determine the operations of a memory stack and show how it is used to implement function calls in a computer. ● Illustrates, with an example, a concrete data structure for a First In First out (FIFO) queue and compare the performance of two sorting algorithms. Further, produce an analysis of the operation of the two network shortest path algorithms providing an example of each. P1 Create a design specification for data structures explaining the valid operations that can be carried out on the structures. Introduction As I am one of the software engineers working in this. B2C Pvt Ltd which is a software company that works on projects based on machine learning, artificial intelligence, IOT(internet of Things) etc. Now I am assigned the responsibility to prepare document so as to show your company understands on use of different ADTs, different sorting and searching algorithms, their applications and efficiency. sorting and searching algorithms, their applications and efficiency. Data structure:

“A data structure is a specialized format for organizing and storing data. General data structure types include the array, the file, the record, the table, the tree, and so on. Any data structure is designed to organize data to suit a specific purpose so that it can be accessed and worked with in appropriate ways. In computer programming, a data structure may be selected or designed to store data for the purpose of working on it with various algorithms”[ CITATION Mar19 \l 1033 ]. Data structures used in this case are Singly Linked List, Linked implementation of a Stack, Linked implementation of a Queue. Types of data structures A data type is an attribute of data which tells the compiler (or interpreter) how the programmer intends to use the data.  Types of data structures Data structures are divided into two categories, includes, Primitive Data and Non-primitive:

  1. Primitive Data Structures These are supported structures at the machine level, which can be used to create non- primitive data structures. This is indispensable and pure in form. They have

Simple data structure Simple data structure build on data types to create higher level data structures. The most common simple data structures are Array and Linked lists. a. Array The array data structure is one of the oldest and most popular data structures. An array of elements can be values or variables. The structure determines the elements using an index or key, allowing the data structure to calculate the position of each element. The memory address of the original element is called the first platform or address. Data elements are indexed and stored sequentially in adjacent memory. There are different types of array data structures. In a common example, many databases use one-dimensional linear arrays that have database records. Arrays can also be multidimensional if they access elements from more than one index. Arrays are the fundamental structure for many other data structures including hash tables, queues, stacks, and linked lists. b. Linked List Link list is the second most popular data structure type. It links elements instead of computer addresses from pointers. While an array of mathematically computes data entries, linked lists store data items in its own structure. The structure considers each element to be a single object and each object contains data and references or the address of the next element. There are three types of linked lists: singly linked where each node stores the next node’s address and the end address is null, doubly linked where each node stores the previous and next node’s addresses and the end address is null, and circular linked where each node links to the other in a circle, and there is no ending null. Compound data structure Computing systems combine simple data structures to form compound data structures. Compound structures may be linear or non-linear. a. Linear Linear data structure from sequences Stack

A stack is a basic linear data structure: a logical entity visualized as a physical stack or object stack. The data structure inserts and deletes elements at one end of the stack, called vertices. Developers develop a stack using arrays and linked lists. A stack in the order in which the computer system performs operations. The order is usually the first appearance (LIFO). The main activities for the stack include 1) Push, add an item to the stack; and 2) Pop, remove an item from the stack in reverse order to Push. Stack also returns an isEmpty value: it means true on an empty stack and deletes false if there is data. Queue Instead of the stack LIFO order, the queue data structure places elements in the queue in the order of First In First Out (FIFO). The insertion process is called Enqueue, which inserts an element into the back or tail of the queue. The delete procedure is called Dequeue, removing elements from the front or the beginning of the queue. To move the element that is inserted into the Dequeued queue, the stack data structure must remove all elements between the new element and the front of the queue. Think of this structure in line with the printer queue, where print jobs occur in order until they are printed or canceled. A queue can be built using arrays, linked lists or stacks. b. Non-linear Non-linear structures are multi-leveled and non- sequential Graph graph data structure is a tree that shows the mathematical image of an object placed with linked pairs. The object points connected together are vertices and links that are edges. Hash Table The hash converts the main value range into the index range in an array. The hash table data structure links each value in an array with a single index that records the point and insertion position of the value, which speeds up the search and search of data.

 provides a way to manage large datasets such as databases or internet indexing services.  Is there a need for efficient algorithm design?  allowing secure storage of information on your computer. This information can then be used for later use and can be used by various programs. In addition, the information is protected and should not be lost (especially if it is stored on magnetic tape).  allowing data to be used and processed on software systems.  Enables easier data processing.  Using the internet, we can access data at any time from any connected machine (computer, laptop, tablet, phone, etc.)  Disadvantages of data structure  Only sophisticated users can make changes to the data structure  Any problem involving the data structure requires the help of a specialist, which is that basic users cannot help themselves. Discussing over all the possible data sorting like linked list, array, queue, and stack I have point out their use and working principal and it is clear that the role of an array is to store a fixed-size sequential collection of data in programing. But there are 2 bounds that it has:

  1. To change the size of an array, you must create a new array with a new changed size then copying all data from the old array to it.
  2. Similar complexity, when an item wants to be inserted into the array, because data in the array are consecutively next to each other, so inserting required shifting some other data. To overcome those two limitations, linked structure is a way to solve. Unlike array, linked list is one sequential access type. Each node in the linked list that contains information about the next node, through which we can access to the node we want to find.

Instead of using array for the E-shop online Ecommerce online company. I have suggested them to use linked list and produce a short example of how we can sort the huge amount of data using linked list algorithm.

P1 Create a design specification for data structures explaining the valid

operations that can be carried out on the structures

For My company ShopNow I have used LinkedList data types because:  Linked List is Dynamic data Structure.  Linked List can grow and shrink during run time.  Insertion and Deletion Operations are Easier  Efficient Memory Utilization, i.e. no need to pre-allocate memory  Faster Access time, can be expanded in constant time without memory overhead  Linear Data Structures such as Stack, Queue can be easily implemented using Linked list Among LinkedList I would use single LinkedList because:  Dynamic Data Structure Linked list is a dynamic data structure so it can grow and shrink at runtime by allocating and deallocating memory. So, there is no need to give initial size of linked list.  Insertion and Deletion Insertion and deletion of nodes are really easier. Unlike array here we don’t have to shift elements after insertion or deletion of an element. In linked list we just have to update the address present in next pointer of a node.  No Memory Wastage As size of linked list can increase or decrease at run time so there is no memory wastage. In case of array there is lot of memory wastage, like if we declare an array of size 10 and store only 6

Create a design specification for Shop-Now online Shopping Management System

In this project, I use linked list for storing data of product. MyOrderQueueTlist MyListList NodeT MyListTlist +NodeThead,tail MyList MyListTList MyCustomerStackTList MyCustomerStack MyOrderQueue

Fig: Flow chart B2C Pvt Ltd Management System Flowchart diagram for Shop Now online shopping Management System

  • getInfo() : return data of Product
  • setInfo() : set data to Product
  • getNext() : return the next MyT
  • setNext() : set the next MyT Class MyListT Class MyLinkedListT is a list of nodes. This class is implemented as a Linked List Class from scratch in Java. In this program, a collection of Product is stored in this class, it can be identified as MyLinkedListT. It has two values:
  • head : MyT - the first product in the list.
  • tail : MyT - the last product in the list. With these operations:
  • isEmpty() : is a Boolean type, return true if the list do not have a head.
  • getHead() : return the first product in the list.
  • getTail() : return the last product in the list.
  • removeHead() : delete the first product in the list. Set the next Product of the first item in the list is the new head then remove the old one. The function works only when the list is not empty. If the list has only one node which is both head and tail, that node will be set null | if (length of list == 1) head = tail = null; Else if the list has more than one node:
  • Declare a temporary node and set as the next node of the current head

| MyT temp = head.getNext();

  • Delete the current head | head.setNext(null);
  • Set the new head as a temporary node declared at the first place | head = temp;
  • removeTail() : delete the last product in the list. Loop to the previous of the last item of the list, set it as a new tail then remove the old one.
  • The function works only when the list is not empty.
  • If the list has only one node which is both head and tail, that node will be set null | if (length of list == 1) head = tail = null;
  • Else if the list has more than one node:
    • Declare a temporary node and set as the current head. | MyT temp = head;
    • Access respectively from the head to the next element (loop the get next function) until reach the previous node of the tail. | while(temp.getNext() != tail) | {temp = temp.getNext();}
    • Delete the current tail then set the new tail as a temporary node declared as a previous node of the old tail. | temp.setNext(null); | tail = temp;
  • traverse() : print to screen all the Products from the list
  • Else if the list is empty, return i = 0.
  • add(Product info) : add a Product to list.
  • Declare a new Product node with its information but no references linked node. | MyT< Product > n = new MyT<>(info,null);
  • If the list is not empty, newest node will be set as the next node of the current tail. Finally, set the newest node as the new tail of the list, which means the old tail becomes the previous node of the new tail. | tail.setNext(n); | tail = n;
  • If the list is empty, the newest added Product is both head and tail. | if (isEmpty()) {head = tail = n;}
  • get(int index) : returns the product at the specified position in this list.
  • Declare a new Product node and set as null | MyT< Product > current = null;
  • If the list is empty, return null.
  • If the list is not empty, access respectively from the head to the next element (loop the get next function) until reach the index position node by declaring integer i = 0, then loop from i to the number of specified position to get the product which user put in. | for (i = 0index) { | | current = current.getNext();
  • If the loop finds the index position, return the information of the Product. | | return current.getInfo();
  • If the loop cannot find the index position, return null.
  • remove(int index) : is a Boolean type, delete the Product at the specified position in this list.
  • Declare a new Product node and set as head | MyT current = head;
  • If the list is empty, return false to stop the process
  • If index number that user put in is zero, which means the position of the node is the head of the list, the fuction removeHead() will be called to delete the head of the list. | if (!isEmpty()) { | if(index == 0){
  • removeAfter (int index) : is a Boolean type, delete the next Product of the Product that user chooses. It operates similar to remove() method but only change the declaration of integer i (i=0) when looping the list to get the position (but remove the removeHead() function from it)
  • Declare a new Product node and set as head | MyT current = head;
  • If the list is empty, return false to stop the process
  • Start accessing respectively from the the head to the next element (loop the get next function) until reach the tail node by declaring integer i = 0, then loop from i to the number of last position of the list. From here, the function will search for the index position node. | | for (i = 0getLength()) | | | | if(i==index)
  • If it finds the index position node, it will set the next node of the index position node as the next node of the node after the index position node, then sort sequentially to all the nodes after the deleted node. The node after the index position node is fully deleted. After all, return true. | | | | current.setNext(current.getNext().getNext()); | | | current = current.getNext();

| | return true; Judgements This program has built the implementation of Linked List from the scratch because of its advantages, but also some disadvantage matters are still visible: The size of the linked list is so flexible and almost “infinite” (depending on the computer's memory). Adding or removing from one side of the list is simple because Linked List can grow and shrink during run time. But if adding or removing the node at the middle of the list is more complex than arrays. When user want to access to elements in the linked list, the application need to browse sequentially all element. It slows down the process and takes more time than arrays (Accessing to the elements in the array is accessed directly based on index). The most important advantage of using Linked List in this program is that Linear Data Structures such as Stack, Queue can be easily implemented using Linked list. Coding