Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Cocoa Touch have a search tree data structure?

I've been looking into this on Google and read the Collections entry in the SDK documentation, and turned up nothing. Is there a BST (any of its variants) implementation available out of the box with the iOS SDK?

It seems odd that something so basic would be missing from a major development platform. Is their hash implementation just that magical? Or do the devs assume no one is going to do inserts/deletes on things that have an order?

I can use NSSet for now, as I know most of us (myself included) aren't really writing anything with tons of computation on iOS that need a guaranteed access time, but it's still gnawing at me.

like image 441
schematic Avatar asked Oct 08 '11 00:10

schematic


People also ask

What is the difference between Cocoa and Cocoa Touch?

Cocoa, which includes the Foundation and AppKit frameworks, is used for developing applications that run on OS X. Cocoa Touch, which includes Foundation and UIKit frameworks, is used for developing applications that run on iOS.

What is binary search tree in data structure?

In computer science, a binary search tree (BST), also called an ordered or sorted binary tree, is a rooted binary tree data structure with the key of each internal node being greater than all the keys in the respective node's left subtree and less than the ones in its right subtree.

Which data structure is used for implementing binary tree?

A binary search tree in a data structure is typically used to represent or store hierarchical data. A “binary tree” is a tree data structure where every node has two child nodes (at the most) that form the tree branches. These child nodes are called left and right child nodes.


1 Answers

CFBinaryHeap looks pretty promising and useful, but it might not be exactly what you want, as it's not really a binary search tree but a heap. They are similar, but not the same, so I feel like Core Foundation's CFTree class might be a little better. Here's a description from the CFTree class reference:

You use CFTree to create tree structures that represent hierarchical organizations of information. In such structures, each tree node has exactly one parent tree (except for the root tree, which has no parent) and can have multiple children.

If you're not comfortable with C (Core Foundation is C, not Objective-C), you can use the JKPTree library which is an Objective-C wrapper of CFTree. You can download it here.

UPDATE:

I just found another library called CHDataStructures that simplifies the creation of a wide variety of data structures. It supports the following data structures (and many other unlisted ones):

  • AVL Tree
  • Abstract Binary Search Tree
  • Andersson Tree
  • Linked List
  • Search Tree
  • Red Black Tree
  • Unbalanced Tree
  • Queue
  • Heap

    You can download CHDataStructures here.

like image 55
pasawaya Avatar answered Sep 19 '22 14:09

pasawaya