...Data Structures and Algorithms DSA Annotated Reference with Examples Granville Barne Luca Del Tongo Data Structures and Algorithms: Annotated Reference with Examples First Edition Copyright c Granville Barnett, and Luca Del Tongo 2008. This book is made exclusively available from DotNetSlackers (http://dotnetslackers.com/) the place for .NET articles, and news from some of the leading minds in the software industry. Contents 1 Introduction 1.1 What this book is, and what it isn’t . . . 1.2 Assumed knowledge . . . . . . . . . . . . 1.2.1 Big Oh notation . . . . . . . . . . 1.2.2 Imperative programming language 1.2.3 Object oriented concepts . . . . . 1.3 Pseudocode . . . . . . . . . . . . . . . . . 1.4 Tips for working through the examples . . 1.5 Book outline . . . . . . . . . . . . . . . . 1.6 Testing . . . . . . . . . . . . . . . . . . . 1.7 Where can I get the code? . . . . . . . . . 1.8 Final messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 1 1 3 4 4 6 6 7 7 7 I Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . reverse order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....
Words: 23014 - Pages: 93
...Data Structures & Algorithms Coursework Assignment 1 Q1. (a) Algorithm swap(x, y): Node n head While (n.getNext () != x ) do n n.getNext() Node v y.getNext () n.setNext(y) y.setNext(x) x.setNext(v) (b) Algorithm swap Doubly(x, y): DNode n x.getPrev() DNode v y.getPrev() n.setNext(y) y.setPrev(n) y.setNext(x) x.setPrev(y) x.setNext(v) v.setPrev(x) (c) The run time complexity for the singled linked algorithm is O (n) and for the doubly linked algorithm is O (1). Doubly linked list has the best time complexity. Time complexity in singly linked list take more time because we have to move from head to the node before x Q2. (b) RedBlueStack implements Stack{ protected Object A[]; Int capacity; int top = -1; RedBlueStack(int cap) { A = new Object [capacity]; capacity = cap; } int size() { return (top + 1); } void push(Object obj) throws FullStackException { if (size() == capacity) throws new FullStackException("Stack is full."); A[++top] = obj; } Object top() throws EmptyStackException { if (isEmpty()) throws new EmptyStackException("Stack is empty."); return A[top]; } Boolean isEmpty() { return (top < 0); } Object top() throws EmptyStackException { if (isEmpty()) throws new EmptyStackException("Stack is empty."); return A[top]; } Object pop() throws EmptyStackException { Object elem; if (isEmpty()) throws new EmptyStackException("Stack...
Words: 551 - Pages: 3
...stack. AB-CD+E*+ (where A=5, B=3, C=5, D =4, and E=2) Question 5 Evaluate the following postfix expression using a stack and show the contents of stack after execution of each operation : 50,40,+,18, 14,-, *,+ Question 6 Evaluate the following postfix expression using a stack and show the contents of stack after execution of each operation : TRUE, FALSE, TRUE, FALSE, NOT, OR, TRUE, OR, OR, AND Question 7 Write a program for creating polynomial using linked list? Question 8 Each node of a STACK contains the following information, in addition to required pointer field : i) Roll number of the student ii) Age of the student Give the structure of node for the linked stack in question TOP is a pointer which points to the topmost node of the STACK. Write the following functions. i) PUSH() - To push a node to the stack which is allocated dynamically ii) POP() - To remove a node from the stack and release the memory. Question 9 Write a function in C to perform a DELETE operation in a dynamically allocated link list considering the following description : struct Node { float...
Words: 308 - Pages: 2
...What is a non-linear datastructure? A non-linear datastrucutre is a datastructure in which the data items in the memory are not allocated contiguously i.e. the data items are dispersed in the memory. The first data item will have a link to the second data item and second data item will have a link to the third data item and so on. Pros • Uses memory efficiently that the free contiguous memory in not an requirement for allocating data items • The length of the data items is not necessary to be known prior to allocation Cons • Overhead of the link to the next data item Linked list: linked list a data structure which stores data in the form of nodes.It does not require linear memory as arrays. Each node contains a data part and a pointer part(a pointer to the next data in the list) link or node is object of a class.there are so many types of linked list 1) single linked list 2)doubly linked list 3)circular linked list. single linked list: here links contains pointer to first data and last data in the list.As said earlier a pointer to the next data. example of a linked list: class node{// all nodes will be the objects of this class public int data; public link next_node;//a pointer to next data } public node(int data){ this.data=data; }//end of constructor public void showdata(){ System.out.println("data= "+data); } }//end of class node After defining class for each node we need to define a class for link list. Link list contains a pointer to...
Words: 475 - Pages: 2
...1.2. Representation of integer has no size restriction • The important factor affecting the running time is normally size of the input. • Normally the built in data type has a fixed size, to enter and to store the larger data. • The Linked List can be used to store the integer without size restriction, which stores each digit in nodes. • The data can also be reused. Addition: A= 456 Represented by 6 → 5 → 4 in linked list B= 094 Represented by 4 → 9 → 0 in linked list The Resultant is C = 550 Represented by 0 → 5 → 5 in linked list. Multiplication: A= 123 * B= 456 A= Represented by 3 → 2 → 1 in linked list. B= Represented by 6 → 5 → 4 in linked list. STEP 1: 123 * 6 = 8 → 3 → 7 in linked list. STEP 2: 123 * 50= 0 → 5 → 1 → 6 in linked list. STEP 3: ADD STEP 1 AND STEP 2 8 → 8 → 8 → 6 in linked list. STEP 4: 123 * 400= 0 → 0 → 2 → 9 → 4 in linked list. STEP 5: ADD STEP 3 AND STEP 4 8 → 8 → 0 → 6 → 5 in linked list. Exponentiation: The initial step is to arrange in decreasing order of exponents and then perform the action. The other method is by using Θ(log n) time algorithm based on binary representation. 1.5. Representation of one’s and two’s complement 1’s complement: + 4= 0100 - 4= 1011 (taking 1’s complement of +4 is -4 (i.e.) inverting the bit). So, 1’s complement is used to represent both positive and negative integers. 2’s complement: Converting the value to 1’s complement and then adding 1 to that complement. ...
Words: 473 - Pages: 2
...DATA STRUCTURES ANALYSIS OF ALGORITHMS Definition:- The method of solving a problem is known as an algorithm.It is a sequence of instructions that act on some input data to produce some output in a finite number of steps. Properties:- a) Input:An algorithm must receive some input data supplied externally. b)Output:An algorithm must produce atleast one output as the result. c)Finiteness:The algorithm must terminate after a finite number of steps. d)Definiteness:The steps to be performed in the algorithm must be clear and unambiguous. e)Effectiveness:One must be able to perform the steps in the algorithm without applying any intelligence. All algorithms basically fall under two broad categories-Iterative and Recursive algorithms. Iterative Algorithms typically use loops and conditional statements. Recursive Algorithms use a divide and Conquer strategy. As per this,the recursive algorithm breaks down a large problem into small pieces and then applies the algorithm to each of these smal pieces. Determining which algorithm is efficient than the other involves analysis of algorithms. While analyzing,time required to execute it determined .’time’ represents the number of operations that are carried out while executing the algorithm. While analyzing iterative algorithms we need to determine how many times the loop is executed. To analyze a recursive algorithm one needs to determine amount of work done for three things: ...
Words: 2466 - Pages: 10
...Chapter 1 Basic Networking Chapter 1 Basic Networking: Data communication is the transfer of data from one device to another via some form of transmission medium. A data communications system must transmit data to the correct destination in an accurate and timely manner. The five components that make up a data communications system are the message, sender, receiver, medium, and protocol. Text, numbers, images, audio, and video are different forms of information. Data flow between two devices can occur in one of three ways: simplex, halfduplex, or full-duplex. A network is a set of communication devices connected by media links. In a point-to-point connection, two and only two devices are connected by a dedicated link. In a multipoint connection, three or more devices share a link. Topology refers to the physical or logical arrangement of a network. Devices may be arranged in a mesh, star, bus, or ring topology. A network can be categorized as a local area network (LAN), a metropolitan-area network (MAN), or a wide area network (WAN). A LAN is a data communication system within a building, plant, or campus, or between nearby buildings. A MAN is a data communication system covering an area the size of a town or city. A WAN is a data communication system spanning states, countries, or the whole world. An internet is a network of networks. The Internet is a collection of many separate networks. TCP/IP is the protocol suite for the Internet...
Words: 2538 - Pages: 11
...1. Data dependence Data illustration incorporates with the requisition function. If there is alteration in the Data, then also there is a difference in the application function. Data independence Data depiction incorporates with operation function. If there is a transition in the Data, it won’t cause a shift in the application program. 2. Structured data It is established data which could efficiently be reclaimed and reserved in the databases as well as warehouses. It assign to the substantial case of the user's situation such as phenomenon and development. Unstructured data It consists of combined use of several media data like pictures, sounds, and video clips. Then, it is reserved as the element of the user's field situation 3. Data It is the illustration of articles and episode which are reserved and acknowledged in the system. It persists in a array of form such as numeric, symbols, 3RQ variables, and so on. For example, database in dr's clinic will have information such as patient name, address, diagnosis, symptoms, and phone number. Information These are the refined data which elevates the information of the specific using it. Data are worthless in their current prospective from so it is pre-refined and illustrated as the information to the user 4. Repository It is the rationalised reserved area for data meaning, table, data relationships and other parts of data system. It encloses...
Words: 689 - Pages: 3
...Analytical Processing is a powerful framework for the analysis of organizational data. OLAP is often supported by a logical structure known as a data cube, a multidimen- sional data model that offers an intuitive array-based per- spective of the underlying data. Supporting efficient index- ing facilities for multi-dimensional cube queries is an issue of some complexity. In practice, the difficulty of the in- dexing problem is exacerbated by the existence of attribute hierarchies that sub-divide attributes into aggregation layers of varying granularity. In this paper, we present a hierar- chy and caching framework that supports the efficient and transparent manipulation of attribute hierarchies within a parallel ROLAP environment. Experimental results verify that, when compared to the non-hierarchical case, very little overhead is required to handle streams of arbitrary hierar- chical queries. Categories and Subject Descriptors H.2.7.b [Database Management]: Data Warehouse and Repository; H.2.2.a [DatabaseManagement]: AccessMeth- ods General Terms Algorithms Design Performance Keywords Hierarchies, Caching, Data Cubes, Aggregation, Indexing, OLAP, Granularity, Materialization, Parallelization 1. INTRODUCTION Online Analytical Processing (OLAP) has become an im- portant component of contemporary Decision Support Sys- tems (DSS). Central to OLAP is the data cube, a multidi- mensional data model that presents an intuitive cube-like Permission to make digital or...
Words: 760 - Pages: 4
...processors and supports up to 2GB of system memory. Insights gained from working with the database after installed are also shared. Installation Process for DB2 Express-C Downloading and installing DB2 Express-C is easily accomplished over an Internet connection. The version installed is 389MB and took approximately 10 minutes to download over a cable modem running at fractional T1 speeds. Installation screens from the steps completed to get DB2 Express-C up and running are shown in the Appendix of this document. After installing the Control Center was invoked at the command line using the command db2cc which is specifically defined in the chapter assigned on DB2 Express-C. Using the command db2sampl -xml –sql to create the sample data worked, and there is the secondary option of using graphical interface commands to accomplish the same. The use of the DB2 Command Line tools show how quickly a multidimensional table can be viewed, edited and batch programming tasks completed using shell scripts in this interface. IBM has done an excellent job of making this free version of DB2 as fully featured and full of navigational and command options as possible. What is most significant amount the design of DB2 relative to other databases worked with is the multiple approaches to getting commands invoked the flexibility on creating fully automated responses to queries, or the option of...
Words: 728 - Pages: 3
...This general problem is known as the vehicle routing problem.Solving the vehicle routing problem involves determining how many vehicles are required to service the destinations, and developing a route and schedule for each one. Because there are many variations of the problem, it can be very dillicult to solve. TransCAD provides a rich set of vehicle routing tools that solve various types of routing problerns,These tools are used to prepare input data, solve the routing problem, and provide tabular and graphical output of the resulting routes and vehicle schedules. The starting points for each route (such as the warehouse in the above example) are known as depots, and the points to be visited are known as stops. A vehicle route starts at a depot, visits one ormore stops, and may or may not return to the depot. The goal of the procedure is to obtain a set of routes that minimizes the total time or discance traveled by the entire fleet of vehicles. The travel times or distances are stored in the vehicle routing matrix.You can use a network to calculate the network driving time or distance, or you can use straight line distances to create your vehicle routing matrix. You must use a network-based vehicle routing matrix if you want to display the routes on a map as a route system layer.Time window- There are time restrictions on when deliveries can be made to some or all of the stores Each stop requires a certain amount of time to service. The service time can have a fixed component...
Words: 3610 - Pages: 15
...as shown in figure 1, is a binary tree data structure which is used to hold key-value pairs and satisfies following properties; • The left subtree of any node contains only those nodes with keys less than the node’s key. • The right subtree of any node contains only those nodes with keys greater than the node’s key. key=10 val="AU" key=8 val="BN" key=15 val="TN" key=12 val="NZ" key=17 val="DL" key=19 val="IN" Figure 1: An example Binary Search Tree These ordering constraints help to find out a node with a given key in O(log n) average time. Insertion and deletion operations in BST (Binary search tree) must maintain these ordering constraints. prio: 8 val: "IN" prio: 15 val: "NZ" prio: 18 val: "AU" prio: 25 val: "TN" prio: 30 val: "BN" prio: 20 val: "AP" prio: 22 val: "RS" Figure 2: An example min-heap Heap is an another binary tree data structure, as shown in figure 2, which is useful in sorting (heapsort) and implementing a priority queue. A heap can be a min-heap or a max-heap based on the priority of a node with respect to the 1 priority of its left and right children. In case of min-heap each node has lesser priority than its children. In case of max-heap each node has higher priority than its children. In this assignment we are going to implement a binary tree data structure which is a combination of BST and heap. This data structure is called Treap. Treap Treap is a binary tree data structure where each node contains 3 attributes;...
Words: 1803 - Pages: 8
...Omar Khairy El -Morsy ABSTRACT The literature on the skyline algorithms so far mainly deal with queries for static query points over static datasets. With the increasing number of mobile service applications and users, the need for continuous skyline query processing has become more pressing. The continuous skyline operator involves not only static but also dynamic dimensions. In this paper, we examine the spatio-temporal coherence of the problem and propose a continuous skyline query processing strategy for moving query points. First, we distinguish the data points that are permanently in the skyline and use them to derive a search bound. Second, we investigate into the connection between data points’ spatial positions and their dominance relationship, which provides an indication on where to find changes of skyline and how to update the skyline continuously. Based on the analysis, we propose a kinetic-based data structure and an efficient skyline query processing algorithm. We analyze the space and time costs of the proposed method and conduct an extensive experiment to evaluate the proposal. To the best of our knowledge, this is the first work on continuous skyline query processing. shown in Figure 1, there are a set of hotels and for each hotel, we have its distance from the beach (x axis) and its price (y axis). The interesting hotels are all the points not worse than any other point in both distance from the beach and the price. Hotels 2, 4 and 6 are interesting and can...
Words: 11922 - Pages: 48
...James Mueller Data Structures and Implementation Unit 5 Individual Project ITCO321 – 1103A - 02 August 21, 2011 Does the word matching exist in the phrase. In the phrase “There exists just a single example”, the word exam is indeed in this phrase. Exam is matched to the word Example as seen here. In order to for the word to be matched, using just plain vision was possible, however, in a computer sense; one must use a pattern matching string so that the program would be able to find the match. When using coding to determine if there is a match in the pattern, you would use the RegularExpression namespace. This will allow for easy parsing and matching of strings to a specific patter (miscrosoft.com, 2011). Regex myRegEx = new Regex("exam"); string s1 = "There exists just a single example."; if (myRegEx.IsMatch(s1)) Console.WriteLine("Match found!"); Explain how you could 'teach' a computer to match the word 'exam' in the given phrase above. In order to do this in C#, you could write 4 separate search commands, or you can be more efficient and you can do it in a single phrase. By using pattern = ‘e ?x ?a ?m?’; . now you can locate one or more of the strings with just a single command: Text = [‘There exists just a single example’]; Regexp (text, pattern, ‘match’) Ans = ‘exam’. This is just one of many ways that you could teach a computer to find the word exam in the phrase. You are also able to use different MATLAB...
Words: 730 - Pages: 3
...C++ Data Structures Chapter 1 10) What is the difference between an object and an object class? An object class provides the blue print for an object. It will define everything and all the variables and methods available to an object (at least in non-dynamic languages). An object is an instance of an object class, which provides a living breathing representation of that blue print. Example #1 A Toyota Camry or another particular make might be an instance of the class car. Example #2 A house might be an instance of the class Building 17) The following program has three separate errors, each of which would cause an infinite loop. As a member of the inspection team, you could save the programmer a lot of testing time by finding the errors during the inspection. Can you help? Error 1: The while clause is missing the {} brackets around the next 3 lines. Error 2: The Increment function is getting passed the variable nextNumber by value rather than reference, which will not increment count in the main() function. Error 3: The program is not referencing stdlib 18) Is there any way a single programmer (for example, a student working alone on a programming assignment) can benefit from some of the ideas behind the inspection process? Yes, I believe anyone could benefit from the inspection process, regardless of the size of the team. The whole philosophy behind the inspection process is to review a program to ensure that each piece is working...
Words: 347 - Pages: 2