Allocation Procedure: Analyzing Time Complexity

  • Context: MHB 
  • Thread starter Thread starter evinda
  • Start date Start date
  • Tags Tags
    Procedure
Click For Summary

Discussion Overview

The discussion revolves around the exercise of using a Divide-and-Conquer procedure to compute the i greatest element in a row of integers, with a focus on analyzing the asymptotic time complexity of the proposed algorithms. Participants explore the concept of an allocation procedure and its implications for implementing the solution.

Discussion Character

  • Exploratory, Technical explanation, Debate/contested, Mathematical reasoning

Main Points Raised

  • Some participants suggest using Merge sort, which has a time complexity of O(n log n), but express the need for a more efficient solution.
  • One participant proposes creating a binary tree as a potential method to implement the solution, indicating that the allocation procedure may involve using malloc() for tree construction.
  • A code snippet is shared to illustrate how to create and insert nodes into a binary tree, raising questions about how this structure can facilitate the Divide-and-Conquer approach.
  • Another participant presents an algorithm for finding the i-th greatest element using a partition method, questioning whether partitioning qualifies as a Divide-and-Conquer procedure.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach to solve the problem. There are multiple competing views regarding the use of Merge sort versus a binary tree structure, and the classification of the partition method as a Divide-and-Conquer procedure remains unresolved.

Contextual Notes

Participants express uncertainty about the allocation procedure and how it integrates with the proposed algorithms. The discussion includes various assumptions about the efficiency and correctness of the methods suggested, but these remain unverified.

evinda
Gold Member
MHB
Messages
3,741
Reaction score
0
Hello! (Wave)

I am looking at the following exercise.
Use a [m]Divide-and-Conquer[/m] procedure for the computation of the [m] i [/m] greatest element at a row of integers.
Analyze the asymptotic time complexity of your algorithm.

Hint : Use the allocation procedure.I thought to sort the integers using the algorithm [m]Merge sort[/m].
But how could we use the hint? What is the [m] allocation procedure [/m] about? :confused:
 
Technology news on Phys.org
evinda said:
Hello! (Wave)

I am looking at the following exercise.
Use a [m]Divide-and-Conquer[/m] procedure for the computation of the [m] i [/m] greatest element at a row of integers.
Analyze the asymptotic time complexity of your algorithm.

Hint : Use the allocation procedure.I thought to sort the integers using the algorithm [m]Merge sort[/m].
But how could we use the hint? What is the [m] allocation procedure [/m] about? :confused:

Hey evinda! (Smile)

Merge sort has complexity O(n log n). The exercise is to do it more efficiently.
I believe you're supposed to create a binary tree.
The hint probably means you're to use [m]malloc()[/m] to construct the tree. (Wasntme)
 
I like Serena said:
Hey evinda! (Smile)

Merge sort has complexity O(n log n). The exercise is to do it more efficiently.
I believe you're supposed to create a binary tree.
The hint probably means you're to use [m]malloc()[/m] to construct the tree. (Wasntme)

So could we create a binary tree as follows?
Code:
struct node{
   int data;
   struct node *left;
   struct node *right;
}tree;tree *insert(tree *root, tree *element) {
  if (root == NULL)
     return element;
  else {
     if (element->data > root->data) {
        if (root->right != NULL) root->right = insert(root->right, element);
        else root->right = element;
     }
     else {
        if (root->left != NULL) root->left = insert(root->left, element);
       else root->left = element;
   }
   return root;
 }
}
Code:
struct node *create(int v) {
   struct node *tmp;
   tmp = (struct node*)malloc(sizeof(struct node));
   tmp->data = v;
   tmp->left = NULL;
   tmp->right = NULL;
   return tmp;
}Node;

Code:
int Algorithm(int array[0...n-1]){
    int i;
    tree T;
    Node temp_node;
    for (i=0; i<n; i++){
          temp_node = create(array[i]);
            T = insert(T, temp_node);
        }
}

How could we use a Divide-and-Conquer procedure for the computation of the [m]i[/m] greatest element, taking into consideration the binary tree? (Thinking)
 
Is the following algorithm right?

Code:
Algorithm ith(A,low,high){
   q=partition(A,low,high);
   if (high-i+1==q) return A[q];
   else if (high-i+1<q) ith(A,low,q-1);
   else ith(A,q+1,high);
}

Or don't we consider that [m] partition [/m] is a Divide and Conquer procedure? (Thinking)
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 20 ·
Replies
20
Views
4K
Replies
1
Views
2K
  • · Replies 17 ·
Replies
17
Views
4K
  • · Replies 31 ·
2
Replies
31
Views
5K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 2 ·
Replies
2
Views
4K
Replies
5
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K