Bit-tree a data structure for fast file processing




















Sutha Palani. Mohammed Ali Yasini. Shreya Trivedi. Abdulla Salama. Raj Mukhi. Show More. Views Total views. Actions Shares. No notes for slide. Tree - Data Structure 1. Tree Unit 6 2. So far we discussed Linear data structures like stack Ashim Lamichhane 2 3. Ashim Lamichhane 4 5. Ashim Lamichhane 6 7. Ashim Lamichhane 7 8.

If root node is at level 0, then its next child node is at level 1, its grandchild is at level 2 and so on. Ashim Lamichhane 8 9. Ashim Lamichhane 10 T has a special node called the root node II. LT and RT are binary trees. Ashim Lamichhane 14 Ashim Lamichhane 15 The following figure shows a binary tree with 9 nodes where A is the root Ashim Lamichhane 16 Ashim Lamichhane 18 Ashim Lamichhane 20 Ashim Lamichhane 22 Ashim Lamichhane 23 Ashim Lamichhane 24 Ashim Lamichhane 25 Ashim Lamichhane 35 Why Binary Search Tree?

Ashim Lamichhane 36 By making the entries of an ordered list into the nodes of a binary search tree, we find that we can search for a key in O logn Ashim Lamichhane 37 If k is found in some node of tree then return true otherwise return false.

Ashim Lamichhane 39 Ashim Lamichhane 40 Applications of DLL are: A music playlist with next song and previous song navigation options.

What is a stack? What are the applications of stack? Push, pop, and top or peek are the basic operations of a stack. Following are some of the applications of a stack: Check for balanced parentheses in an expression Evaluation of a postfix expression Problem of Infix to postfix conversion Reverse a string What is a queue?

What are the applications of queue? Dequeue from the queue, enqueue element to the queue, get front element of queue, and get rear element of queue are basic operations that can be performed. Managing an Input stream How is a stack different from a queue? In a stack, the item that is most recently added is removed first whereas in queue, the item least recently added is removed first.

Explain the process behind storing a variable in memory. A variable is stored in memory based on the amount of memory that is needed. Following are the steps followed to store a variable: The required amount of memory is assigned first. Then, it is stored based on the data structure being used. Using concepts like dynamic allocation ensures high efficiency and that the storage units can be accessed based on requirements in real time. How to implement a queue using stack? A queue can be implemented using two stacks.

Let q be the queue and stack1 and stack2 be the 2 stacks for implementing q. We know that stack supports push, pop, peek operations and using these operations, we need to emulate the operations of queue - enqueue and dequeue.

Hence, queue q can be implemented in two methods Both the methods use auxillary space complexity of O n : By making enqueue operation costly: Here, the oldest element is always at the top of stack1 which ensures dequeue operation to occur in O 1 time complexity. To place element at top of stack1, stack2 is used. Pseudocode: Enqueue: Here time complexity will be O n enqueue q, data : While stack1 is not empty : Push everything from stack1 to stack2. Push data to stack1 Push everything back to stack1.

Dequeue: Here time complexity will be O 1 deQueue q : If stack1 is empty then error else Pop an item from stack1 and return it By making dequeue operation costly: Here, for enqueue operation, the new element is pushed at the top of stack1. Here, the enqueue operation time complexity is O 1. In dequeue, if stack2 is empty, all elements from stack1 are moved to stack2 and top of stack2 is the result.

Basically, reversing the list by pushing to a stack and returning the first enqueued element. This operation of pushing all elements to new stack takes O n complexity. Pseudocode: Enqueue: Time complexity: O 1 enqueue q, data : Push data to stack1 Dequeue: Time complexity: O n dequeue q : If both stacks are empty then raise error. If stack2 is empty : While stack1 is not empty : push everything from stack1 to stack2.

Pop the element from stack2 and return it. How do you implement stack using queues? A stack can be implemented using two queues. We know that a queue supports enqueue and dequeue operations.

Using these operations, we need to develop push, pop operations. Pseudocode: Push element to stack s : Here push takes O n time complexity. Swap the names of q1 and q2 Pop element from stack s: Takes O 1 time complexity. By making pop operation costly: In push operation, the element is enqueued to q1. In pop operation, all the elements from q1 except the last remaining element, are pushed to q2 if it is empty.

That last element remaining of q1 is dequeued and returned. Pseudocode: Push element to stack s : Here push takes O 1 time complexity. Step2: Dequeue the last item of q1, the dequeued item is stored in result variable.

Step3: Swap the names of q1 and q2 for getting updated data after dequeue Step4: Return the result. What is hashmap in data structure? Hashmap is a data structure that uses implementation of hash table data structure which allows access of data in constant time O 1 complexity if you have the key. What is the requirement for an object to be used as key or value in HashMap?

The key or value object that gets used in hashmap must implement equals and hashcode method. The hash code is used when inserting the key object into the map and equals method is used when trying to retrieve a value from the map. How does HashMap handle collisions in Java? The java. HashMap class in Java uses the approach of chaining to handle collisions. In chaining, if the new values with same key are attempted to be pushed, then these values are stored in a linked list stored in bucket of the key as a chain along with the existing value.

In the worst case scenario, it can happen that all key might have the same hashcode, which will result in the hash table turning into a linked list.

In this case, searching a value will take O n complexity as opposed to O 1 time due to the nature of the linked list. Hence, care has to be taken while selecting hashing algorithm. What is the time complexity of basic operations get and put in HashMap class?

The time complexity is O 1 assuming that the hash function used in hash map distributes elements uniformly among the buckets. Which data structures are used for implementing LRU cache? In order to achieve this, two data structures are used: Queue — This is implemented using a doubly-linked list.

The maximum size of the queue is determined by the cache size, i. The least recently used pages will be near the front end of the queue whereas the most recently used pages will be towards the rear end of the queue. Hashmap — Hashmap stores the page number as the key along with the address of the corresponding queue node as the value. What is a priority queue? A priority queue is an abstract data type that is like a normal queue but has priority assigned to elements. Elements with higher priority are processed before the elements with a lower priority.

In order to implement this, a minimum of two queues are required - one for the data and the other to store the priority. Can we store a duplicate key in HashMap? No , duplicate keys cannot be inserted in HashMap. If you try to insert any entry with an existing key, then the old value would be overridden with the new value. Doing this will not change the size of HashMap. What is a tree data structure?

Tree is a recursive, non-linear data structure consisting of the set of one or more data nodes where one node is designated as the root and the remaining nodes are called as the children of the root. Tree organizes data into hierarchial manner. The most commonly used tree data structure is a binary tree and its variants. Some of the applications of trees are: Filesystems —files inside folders that are inturn inside other folders.

Comments on social media — comments, replies to comments, replies to replies etc form a tree representation. Family trees — parents, grandparents, children, and grandchildren etc that represents the family hierarchy. What are Binary trees? A binary Tree is a special type of tree where each node can have at most two children.

Binary tree is generally partitioned into three disjoint subsets, i. What is the maximum number of nodes in a binary tree of height k? Write a recursive function to calculate the height of a binary tree in Java. Write Java code to count number of nodes in a binary tree. What are tree traversals? Tree traversal is a process of visiting all the nodes of a tree. Since root head is the first node and all nodes are connected via edges or links we always start with that node.

Traverse the left subtree, i. Visit the root. Step 3. Traverse the right subtree, i. Preorder Traversal: Algorithm: Step 1. What Data Structure is best to use for file organization? Are B-Trees the best or is there another data structure which obtains faster access to files and good organization?

All file systems are different, so there are a huge number of data structures that actually get used in file systems. Many file systems use some sort of bit vector usually referred to as a bitmap to track where certain free blocks are, since they have excellent performance for querying whether a specific block of disk is in use and for disks that aren't overwhelmingly full support reasonably fast lookups of free blocks. Many older file systems ext and ext2 stored directory structures using simple linked lists.

Apparently this was actually fast enough for most applications, though some types of applications that used lots of large directories suffered noticeable performance hits. Other file systems ext3 and ext4 use a variant of the B-tree called the HTree that I'm not very familiar with.

Apparently it uses some sort of hashing scheme to keep the branching factor high so that very few disk accesses are used. I have heard anecdotally that some operating systems tried using splay trees to store their directory structures but ran into trouble with them. Specifically, it prevented multithreaded access to the same directory from multiple readers since in a splay tree, each access reshapes the tree and encountered an edge case where the tree would degenerate to a linked list if all elements of the tree were accesses sequentially.

That said, I don't know if this is just an urban legend, since these problems would have been apparent before anyone tried to code them up.

Microsoft's FAT32 system used a huge array the file allocation table that store what files were stored where and which disk sectors follow one another logically in a file.

The main drawback is that the table had to be set up in advance, so there ended up being upper limits on the sizes of files that could be stored on the disk. However, the array-based system was pretty easy to implement.

This is not an exhaustive list - I'm sure that other file systems use other data structures. However, I hope it helps give you a push in the right direction. Stack Overflow for Teams — Collaborate and share knowledge with a private group.

Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Data structures used to build file systems?



0コメント

  • 1000 / 1000