Free Essay

Data Structures and Algorithms

In:

Submitted By nats14
Words 269
Pages 2
Q1. The above represents a random looking undirected graph where the circles represent nodes and the boundary circumscribes all the nodes of the graph. The length of the segment joining two nodes represents the length of the shortest path from one node to another. Let’s assume nodes A and B are the farthest pair of nodes according to the definition in the question. Thus A and B have to be on the circumscribing boundary. Thus AB represents the diameter of the graph. Let C be any random node in the graph. Let D be a point which is farthest away from C. So if a BFS is launched on node C, the depth(in terms of the summation of the edges) of the BFS tree rooted at C will be equal to CD. As a result CD >= CA and CD>=CB.
Now let AB = d.
So from triangle inequality CA+CB>=d. Thus d/2 <= max(CA,CB)<=d. Now since CD is greater than or equals to both CA and CB, it has to be greater than or equals to d/2 as well. CD has to be less than d as well because if not then CD would have been the diameter. But that is not the case.

Hence d/2<=CD<=d thus if we can find the length of CD we are done with approximating the value of the diameter within a factor of 2 and that we can do by creating BFS tree from C and calculating depth of the tree which is nothing but CD.

Similar Documents

Free Essay

Analysis Algorithm and Data Structure

...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

Free Essay

Repitation

...Search Trees • Implementing Binary Trees • Searching a Binary Search Tree • Tree Traversal • Insertion • Deletion Data Structures and Algorithms in C++, Fourth Edition 2 Objectives (continued) • • • • • • Balancing a Tree Self-Adjusting Trees Heaps Treaps k-d Trees Polish Notation and Expression Trees Data Structures and Algorithms in C++, Fourth Edition 3 Trees, Binary Trees, and Binary Search Trees • While linked lists, stacks, and queues are useful data structures, they do have limitations – Linked lists are linear in form and cannot reflect hierarchically organized data – Stacks and queues are one-dimensional structures and have limited expressiveness • To overcome these limitations, we’ll consider a new data structure, the tree • Trees consist of two components, nodes and arcs (or edges) • Trees are drawn with the root at the top, and “grow” down – The leaves of the tree (also called terminal nodes) are at the bottom of the tree Data Structures and Algorithms in C++, Fourth Edition 4 Trees, Binary Trees, and Binary Search Trees (continued) • Trees can be defined recursively as follows: 1. 2. 3. A tree with no nodes or arcs (an empty structure) is an empty tree If we have a set t1… tk of disjoint trees, the tree whose root has the roots of t1… tk as its children is a tree Only structures generated by rules 1 and 2 are trees • Every node in the tree must be accessible from the root through a unique sequence...

Words: 11443 - Pages: 46

Free Essay

Ds Java

...A Practical Introduction to Data Structures and Algorithm Analysis Third Edition (Java) Clifford A. Shaffer Department of Computer Science Virginia Tech Blacksburg, VA 24061 April 16, 2009 Copyright c 2008 by Clifford A. Shaffer. This document is the draft of a book to be published by Prentice Hall and may not be duplicated without the express written consent of either the author or a representative of the publisher. Contents Preface xiii I Preliminaries 1 1 Data Structures and Algorithms 1.1 A Philosophy of Data Structures 1.1.1 The Need for Data Structures 1.1.2 Costs and Benefits 1.2 Abstract Data Types and Data Structures 1.3 Design Patterns 1.3.1 Flyweight 1.3.2 Visitor 1.3.3 Composite 1.3.4 Strategy 1.4 Problems, Algorithms, and Programs 1.5 Further Reading 1.6 Exercises 3 4 4 6 8 12 13 14 15 16 17 19 21 2 Mathematical Preliminaries 2.1 Sets and Relations 2.2 Miscellaneous Notation 2.3 Logarithms 2.4 Summations and Recurrences 25 25 29 31 33 iii iv Contents 2.5 2.6 2.7 2.8 2.9 3 II 4 Recursion Mathematical Proof Techniques 2.6.1 Direct Proof 2.6.2 Proof by Contradiction 2.6.3 Proof by Mathematical Induction Estimating Further Reading Exercises Algorithm Analysis 3.1 Introduction 3.2 Best, Worst, and Average Cases 3.3 A Faster Computer, or a Faster Algorithm? 3.4 Asymptotic Analysis 3.4.1 Upper Bounds 3.4.2 Lower Bounds 3.4.3 Θ Notation 3.4.4 Simplifying...

Words: 30587 - Pages: 123

Free Essay

Programming

...TeamLRN Robert Lafore Teach Yourself Data Structures and Algorithms in 24 Hours 201 West 103rd St., Indianapolis, Indiana, 46290 USA Sams Teach Yourself Data Structures and Algorithms in 24 Hours Copyright © 1999 by Sams Publishing All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Neither is any liability assumed for damages resulting from the use of the information contained herein. International Standard Book Number: 0-672-31633-1 Library of Congress Catalog Card Number: 98-83221 Printed in the United States of America First Printing: May 1999 01 00 99 4 3 2 1 EXECUTIVE EDITOR Brian Gill DEVELOPMENT EDITOR Jeff Durham MANAGING EDITOR Jodi Jensen PROJECT EDITOR Tonya Simpson COPY EDITOR Mike Henry INDEXER Larry Sweazy PROOFREADERS Mona Brown Jill Mazurczyk TECHNICAL EDITOR Richard Wright Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term in this...

Words: 10065 - Pages: 41

Free Essay

Grid Computing

...replication the replicas have to be manually created, deleted and managed and it becomes tedious with the increase in files and user jobs. So it has the drawback that can not adapt to changes in user behavior. In real scenario, where the data amounts to peta bytes, and the user community is in the order of thousands around the world; static replication does not sound to be feasible. Dynamic replication strategies overcome the problem, where replica creation, deletion and management are done automatically. Dynamic replication strategies have the ability to adapt to changes in user behavior. Dynamic strategies are explained in section-2. In replication consistency is an important issue that needs to be considered. To overcome this problem as in other papers, it is assumed that: access pattern is read only for all replicas in data grid. The remainder of paper is organized as follows. Related work on replication and scheduling is given in section 3. A 3-layerd hierarchical structure is proposed for replication in data grid based on classification of networks, along with a novel algorithm for this structure is given in section 4. Section 5, covers the simulation result with optorsim and section 6 concludes the paper. Summary In data grids huge amount of data are generated and processed by users around the world. Objective of dynamic replica...

Words: 3673 - Pages: 15

Free Essay

Case Study

...Computer Networks Computer Graphics and Multimedia Lab Advanced Operating System Internet programming and Web Design Data Mining and Warehousing Internet programming and Web Design Lab Project Work and Viva Voce Total University Examinations Durations Max in Hrs Marks 3 100 3 100 3 100 3 100 3 100 3 3 3 3 100 100 100 100 100 1000 II For project work and viva voce (External) Breakup: Project Evaluation : 75 Viva Voce : 25 1 Anx.31 J - M Sc CS (SDE) 2007-08 with MQP Page 2 of 16 YEAR – I PAPER I: ADVANCED COMPUTER ARCHITECTURE Subject Description: This paper presents the concept of parallel processing, solving problem in parallel processing, Parallel algorithms and different types of processors. Goal: To enable the students to learn the Architecture of the Computer. Objectives: On successful completion of the course the students should have: Understand the concept of Parallel Processing. Learnt the different types of Processors. Learnt the Parallel algorithms. Content: Unit I Introduction to parallel processing – Trends towards parallel processing – parallelism in uniprocessor Systems – Parallel Computer structures – architectural classification schemes – Flynn’ Classification – Feng’s Classification – Handler’s Classification – Parallel Processing Applications. Unit II Solving problems in Parallel: Utilizing Temporal Parallelism – Utilizing Data Parallelism –...

Words: 3613 - Pages: 15

Free Essay

Software

...Data Structure and Algorithms UNIT – I PART- A Questions & Answers 1. What is an algorithm? An algorithm is a finite set of instructions that , if followed, accomplishes a particular task. 2. What are the characteristics of an algorithm?  Input – Zero or more quantities  Output – At least one quantity  Definiteness – each instruction is clear and unambiguous  Finiteness – terminate after a finite number of steps  Efficiency – easily understandable 3. Define Space Complexity The Space complexity of an algorithm is the amount of memory it needs to run to completion 4. Define Time Complexity Time complexity of an algorithm is the amount of computer time it needs to run to completion 5. What are asymptotic notations? The notations that enables us to make meaningful statements about the time and space complexity of a program is called asymptotic notations. 6. What are the various asymptotic notations used to define the efficiency of an algorithm?  Big ‘Oh’ (O)  Omega (Ω)  Theta (θ)  Little ‘oh’ (o)  Little Omega 7. What is information? Information is a recorded or communicated material that has some meaning associated with symbolic representation. 8. What are the aspects to be considered to ensure information transfer between source and destination?  Syntactic – Physical form of information  Semantic – Meaning  Pragmatic – Action taken as a result of interpretation of information 9. State the Markov algorithm It takes the input string X and through a number...

Words: 425 - Pages: 2

Free Essay

Data Structures

...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

Free Essay

Systems

...Component 01 - Computing Principles | AS-Level (H046) | A-Level (H446) | 1 The characteristics of contemporary processors, input, output and storage devices | Structure and function of the processor | The Arithmetic and Logic Unit (ALU), Control Unit and registers: Program Counter (PC), Accumulator (ACC), Memory Address Register (MAR), Memory Data Register (MDR), Current Instruction Register (CIR).Buses: data, address and control: How this relates to assembly language programs.The fetch-decode-execute cycle, including its effect on registers.The factors affecting the performance of the CPU, clock speed, number of cores, cache.Von Neumann, Harvard and contemporary processor architecture. | The use of pipelining in a processor to improve efficiency. | Types of processor | The differences between, and uses of, CISC and RISC processors.Multicore and parallel systems. | GPUs and their uses (including those not related to graphics). | Input, output and storage | How different input output and storage devices can be applied as a solution of different problems.The uses of magnetic, flash and optical storage devices.RAM and ROM.Virtual storage. | | 2 Software and software development | Operating systems | The need for, function and purpose of operating systems.Memory management (paging, segmentation and virtual memory).Interrupts, the role of interrupts and Interrupt Service Routines (ISR), role within the fetch decode execute cycle.Scheduling: round robin, first come...

Words: 1302 - Pages: 6

Free Essay

Info Tech

...2. ALGORITHMS, FLOWCHARTS, DATA TYPES AND PSEUDOCODE 2.1 ALGORITHMS The term algorithm originally referred to any computation performed via a set of rules applied to numbers written in decimal form. The word is derived from the phonetic pronunciation of the last name of Abu Ja'far Mohammed ibn Musa al-Khowarizmi, who was an Arabic mathematician who invented a set of rules for performing the four basic arithmetic operations (addition, subtraction, multiplication and division) on decimal numbers. An algorithm is a representation of a solution to a problem. If a problem can be defined as a difference between a desired situation and the current situation in which one is, then a problem solution is a procedure, or method, for transforming the current situation to the desired one. We solve many such trivial problems every day without even thinking about it, for example making breakfast, travelling to the workplace etc. But the solution to such problems requires little intellectual effort and is relatively unimportant. However, the solution of a more interesting problem of more importance usually involves stating the problem in an understandable form and communicating the solution to others. In the case where a computer is part of the means of solving the problem, a procedure, explicitly stating the steps leading to the solution, must be transmitted to the computer. This concept of problem solution and communication makes the study of algorithms important to...

Words: 4924 - Pages: 20

Premium Essay

Analysis Of Lempel-Zless Compression

...Comparing the Lempel-Ziv Family of Algorithms Dr. Bhupendra Verma1 and A. B. Bavani Sankar 1* 1Technocrats Institute of Technology, Bhopal , Madhya Pradesh - 462021 India Abstract- When storage space falls short, or when time required to transfer is to be reduced, compression is the method used to manipulate the data and reduce its overall size. Compression can also be used to simply package a set of files for ease of distribution. Lossless compression of data is used extensively to avoid degradation of data and to retrieve data as was before packaging. In this paper, one of the pioneering algorithms, “LZ” (by Lempel and Ziv), and its popular variants are compared and discussed to make clear its places of application and viability. 1. Introduction...

Words: 2050 - Pages: 9

Premium Essay

Fuzzy Inference System Case Study

...CHAPTER 2 LITERATURE SURVEY CHAPTER 2 : LITRETURE SURVEY 2.1 SURVEY IN MEDICAL DIAGNOSIS USING ARTIFICIAL INTELLIGENCE TECHNIQUES : - Many intelligent systems have been developed for the purpose of enhancing health-care and provide better health care facilities, reduce cost and etc. 2.2 OVERALL ARCHITECTURE OF MEDICAL DIAGNOSIS USING ARTIFICIAL INTELLIGENCE TECHNIQUES:- The Centralized databases and www (World Wide Web) shares the patient data among the different cities used by doctor /practitioners for diagnosis. Single database system was only accessible to that city but the centralized database is accessed by all the cities. Fig2 shows the sharing knowledge between different cities where...

Words: 2581 - Pages: 11

Premium Essay

The Importance Of Cluster Analysis

...under the category of supervised learning. K-means is the most simple and popular algorithm in clustering and was published in 1955, 50 years ago. The advancement in technology has led to many high-volume, high-dimensional data sets. These huge data sets provide opportunity for automatic data analysis, classification...

Words: 2367 - Pages: 10

Premium Essay

It- 3rd Year

...E-COMMERCE (TIT-501) UNIT I Introduction What is E-Commerce, Forces behind E-Commerce Industry Framework, Brief history of ECommerce, Inter Organizational E-Commerce Intra Organizational E-Commerce, and Consumer to Business Electronic Commerce, Architectural framework Network Infrastructure for E-Commerce Network Infrastructure for E-Commerce, Market forces behind I Way, Component of I way Access Equipment, Global Information Distribution Network, Broad band Telecommunication. UNIT-II Mobile Commerce Introduction to Mobile Commerce, Mobile Computing Application, Wireless Application Protocols, WAP Technology, Mobile Information Devices, Web Security Introduction to Web security, Firewalls & Transaction Security, Client Server Network, Emerging Client Server Security Threats, firewalls & Network Security. UNIT-III Encryption World Wide Web & Security, Encryption, Transaction security, Secret Key Encryption, Public Key Encryption, Virtual Private Network (VPM), Implementation Management Issues. UNIT - IV Electronic Payments Overview of Electronics payments, Digital Token based Electronics payment System, Smart Cards, Credit Card I Debit Card based EPS, Emerging financial Instruments, Home Banking, Online Banking. UNIT-V Net Commerce EDA, EDI Application in Business, Legal requirement in E -Commerce, Introduction to supply Chain Management, CRM, issues in Customer Relationship Management. References: 1. Greenstein and Feinman, “E-Commerce”, TMH 2. Ravi Kalakota, Andrew Whinston...

Words: 2913 - Pages: 12

Free Essay

Reserch Paper on Sorting and Dictionaries

...info Abstract-Arrays and linked lists are two basic data structures used to store information. We may wish to search, insert or delete records in a database based on a key value. This section examines the performance of these operations on arrays and linked lists. In this research paper we studied about the sorting and types of sorting. This is followed by techniques for implementing dictionaries, structures that allow efficient search, insert, and delete operations. We have also illustrated algorithms that sort data and implement dictionaries for very large files Keywords-insertion sort, quick sort, sort ,binary search tree, skip list. 1. Introduction Arrays and linked lists are two basic data structures used to store information. We may wish to search, insert or delete records in a database based on a key value. This section examines the performance of these operations on arrays and linked lists. 1.1 Arrays Figure 1-1 shows an array, seven elements long, containing numeric values. To search the array sequentially, we may use the algorithm in Figure 1-2. The maximum number of comparisons is 7, and occurs when the key we are searching for is in A[6]. Figure 1-1: An Array int function SequentialSearch(Array A , int Lb, int Ub, int Key ); begin for i= Lbto Ub do if A [ i ]= Key then return i ; return –1; end; | Figure 1-2: Sequential Search If the data is sorted,...

Words: 2248 - Pages: 9