Rope

darlingjemimai 796 views 15 slides May 28, 2015
Slide 1
Slide 1 of 15
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15

About This Presentation

This is about the advance data structure called rope/cord.


Slide Content

Rope/Cord-Data structure By D.Darling Jemima, 14MZ31

Definition of Rope A   rope or   cord , is a data structure composed of smaller  strings. It is used for efficiently storing and manipulating a very long string . A rope is a binary tree having leaf nodes that contain a short string. Each node has a weight value equal to the length of its string plus the sum of all leaf nodes weight in its left subtree .

A simple rope built on the string of " Hello_my_name_is_Jemima ". > 9 6 22 3 6 2 2 4 1 1 6 6 Hello_ my_ na m e_i s Jemima A B C D G E F I J K L H

Contd … A node with two children divides the whole string into two parts: the left subtree stores the first part of the string. The right subtree stores the second part and its weight is the sum of the left child's weight and the length of its contained string.

Operations in rope Index Split Concatenation Insert Delete

Index operation in ropes function index( RopeNode node, integer i ) if node.weight < i then return index( node.right , i - node.weight ) else if exists( node.left ) then return index( node.left , i ) else return node.string [ i ] endif endif end

Index(To find the character i =10) > 9 6 22 3 6 2 2 4 1 1 6 6 Hello_ my_ na m e_i s jemima A B C D E F I J K L G H

Concatenation 6 3 6 2 2 4 9 6 2 6 3 2 4 Hello_ my_ na m e_i Hello_ my_ na m e_i

Split 9 6 22 3 6 2 2 4 1 1 6 6 Hello_ my_ na m e_i s jemima

Split 9 6 22 3 6 2 2 4 1 1 6 6 Hello_ my_ na m e_i s jemima

Split 9 6 22 3 6 2 2 4 1 1 6 6 Hello_ my_ na m e_i s jemima 4

Advantages of ropes Ropes enable much faster insertion and deletion of text. Ropes don't require O(n) extra memory when operated upon (arrays need that for copying operations) Ropes don't require large contiguous memory spaces.

Application of ropes in text editor Hello, World! ^------Cursor here +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | H|e|l|l|o |,| |W| <free> | o|r|l|d |!| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ^ ^ | begin cur1 cur2 end

References http://en.wikipedia.org/wiki/Rope_data_structure.

5 5 3 THANK_ YOU
Tags