Archivo: /home/young/work/cordic/mvr_exhaustive.c Página 1 de 6

Similar documents
Archivo: /home/young/work/cordic/binary_tree_search/search_defs.h Página 1 de 1

File: /media/young/d1 (180713)/Work tive_tree_search/search_defs.h Page 1 of 1

Archivo: /media/young/d1 (180713)/Work /binary_tree_search c Página 1 de 18

File: /media/young/d1 (180713)/Work /binary_tree_search c Page 1 of 19

File: /media/young/d1 (180713)/Work ernary_tree_search c Page 1 of 22

Archivo: /media/young/d1 (180713)/Work ternary_tree_search c Página 1 de 22

Archivo: /media/young/d1 (180713)/Work ternary_tree_search c Página 1 de 23

# bash -x run.sh. fname=ternary_search dname= /Work/CORDIC/2.ternary_tree_search. echo on. cd $dname. make ternary_search N=10.

# bash -x run.sh. fname=quaternary_search dname= /Work/CORDIC/3.quaternary_tree_search. echo on. cd $dname. make quaternary_search N=10 DISP=1.

Queues. A queue is a special type of structure that can be used to maintain data in an organized way.

Solution for Data Structure

Sample Problems for Quiz # 3

Arrays. An array is a collection of several elements of the same type. An array variable is declared as array name[size]

C Data Structures Stacks. Stack. push Adds a new node to the top of the stack

Chapter 9 STACK, QUEUE

CS 241 Data Organization Binary Trees

CS24 Week 8 Lecture 1

Linked List. April 2, 2007 Programming and Data Structure 1

SOFTWARE Ph.D. Qualifying Exam Spring Consider the following C program, which includes three function definitions, including the main function.

ESc101: (Linear, Circular, Doubly) Linked Lists, Stacks, Queues, Trees. Introduction to Linked Lists

Day06 A. Young W. Lim Wed. Young W. Lim Day06 A Wed 1 / 26

Binary Search Tree 1.0. Generated by Doxygen Mon Jun :12:39

Data Structure Advanced

Procedural Programming

Recursion, Trees and Tree Traversal. Module CE System Programming & Computer Control Systems

Singly linked lists in C.

CP2 Revision. theme: dynamic datatypes & data structures

15. Stacks and Queues

Recursion. Data and File Structures Laboratory. DFS Lab (ISI) Recursion 1 / 27

The combination of pointers, structs, and dynamic memory allocation allow for creation of data structures

SOFTWARE Ph.D. Qualifying Exam Spring Consider the following C program which consists of two function definitions including the main function.

File: /home/young/mywork/b.cordic_gmp/print.file Page 1 of 7

ENEE150 Final Exam Review

Programming Language B

S.E. Sem. III [CMPN] Data Structures. Primitive Linear Non Linear

Example 3. Young Won Lim 11/22/17

Assignment 6. Q1. Create a database of students using structures, where in each entry of the database will have the following fields:

COP 3502 Section 2 Exam #2 Version A Spring /23/2017

What is recursion. WAP to find sum of n natural numbers using recursion (5)

Linked Lists. .. and other linked structures. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Lecture 7: Data Structures. EE3490E: Programming S1 2017/2018 Dr. Đào Trung Kiên Hanoi Univ. of Science and Technology

Algorithms Bubble Sort (1B) Young Won Lim 4/5/18

Linked-List Basic Examples. A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links

S.E. Sem. III [INFT] Data Structures & Analysis. Primitive Linear Non Linear

Chapter 20: Binary Trees

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Trees. A tree is a directed graph with the property

Class Information ANNOUCEMENTS

File: /home/young/mywork/5.cordic_vhdl/f.c/lut.src.print Page 1 of 9

Binary Trees. College of Computing & Information Technology King Abdulaziz University. CPCS-204 Data Structures I

Trees and Graphs. CSE 2320 Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington

Search Trees. Data and File Structures Laboratory. DFS Lab (ISI) Search Trees 1 / 17

CS 106X Lecture 18: Trees

Algorithms and Data Structures CS-CO-412

Sample Examination. Family Name:... Other Names:... Signature:... Student Number:...

NET/JRF-COMPUTER SCIENCE & APPLICATIONS. Time: 01 : 00 Hour Date : M.M. : 50

Intermediate Programming

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 4/18/2013

Stacks and Queues. Stack - Abstract Data Type. Stack Applications. Stack - Abstract Data Type - C Interface

Trees CONTENTS. Hours: 8. Marks: 12. Anuradha Bhatia 1

CS61, Fall 2012 Section 2 Notes

COP 3223 Introduction to Programming with C - Study Union - Spring 2018

Data Structures. Outline. Introduction Linked Lists Stacks Queues Trees Deitel & Associates, Inc. All rights reserved.

CS 2301 Exam 3 B-Term 2011

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 2/10/2013

Abstract vs concrete data structures HEAPS AND PRIORITY QUEUES. Abstract vs concrete data structures. Concrete Data Types. Concrete data structures

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS

Heaps in C. CHAN Hou Pong, Ken CSCI2100 Data Structures Tutorial 7

SYSC 2006 CD. Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

Data compression.

Arrays and Pointers. CSE 2031 Fall November 11, 2013

Data Structures and Algorithms for Engineers

Stacks, Queues and Hierarchical Collections

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

Chapter 5. Binary Trees

Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

Binary Trees. Height 1

Binary Trees. Directed, Rooted Tree. Terminology. Trees. Binary Trees. Possible Implementation 4/18/2013

Data Structures Question Bank Multiple Choice

Chapter 4: Trees. 4.2 For node B :

Arrays and Pointers. Arrays. Arrays: Example. Arrays: Definition and Access. Arrays Stored in Memory. Initialization. EECS 2031 Fall 2014.

COMP1917 Computing 1 Written Exam Sample Questions

COP 3502 (Computer Science I) Test #3: Data Structures Date: 11/1/2013 VERSION A

COMP 250 Midterm #2 March 11 th 2013

Data Structures And Algorithms

Stacks, Queues and Hierarchical Collections. 2501ICT Logan

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0)

Trees Algorhyme by Radia Perlman

(Section : Computer Science)

Queue ADT. CMPT 125 Feb. 28

Computer Science Foundation Exam

Day05 A. Young W. Lim Sat. Young W. Lim Day05 A Sat 1 / 14

Trees (part 2) CSE 2320 Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington

ESC101N: Fundamentals of Computing End-sem st semester

Computer Science Foundation Exam

Procedural Programming & Fundamentals of Programming

Answer all questions. Write your answers only in the space provided. Full marks = 50

CSCI212 Computer Science. Binary Trees/Heaps/Binary Search Trees

Advanced Pointer Topics

Transcription:

Archivo: /home/young/work/cordic/mvr_exhaustive.c Página 1 de 6 -------------- Purpose: Explore Full Angles Space (exhaustive MVR CORDIC) Discussion: Licensing: This code is distributed under the GNU LGPL license. Modified: 2018.10.04 Author: Young Won Lim Parameters: -------------- #include <stdio.h> #include <math.h> #include <stdlib.h> #define N 8 #define R (N/2) --------------------------------------------------------- (2R+1)-ary tree node 1st R choices -a(0), -a(1),..., -a(r-1) 2nd R choices +a(0), +a(1),..., +a(r-1) last choice zero --------------------------------------------------------- typedef struct node { double theta; int depth; int branch; int id; struct node * child[2*r+1]; struct node * parent; nodetype; --------------------------------------------------------- queue node type used for breadth first search traversal --------------------------------------------------------- typedef struct qnode { struct node * node; struct qnode * next; qnodetype; conventional cordic input initial angle : angle[0] ouput residue angles : angle[1].. angle[n] void conventional_cordic(double a[], double angle[]) { int k = 0, uk; printf("* conventional cordic... \n"); for (k=0; k<n; ++k) { uk = (angle[k] >= 0)? +1 : -1;

Archivo: /home/young/work/cordic/mvr_exhaustive.c Página 2 de 6 printf("k=%2d angle[%2d]=%10.7f ", k, k, angle[k]); printf("uk=%+d ", uk); angle[k+1] = angle[k] - uk * a[k]; printf("a[%2d]=%10.7f ", k, a[k]); printf("angle[%2d]=%+10.5e \n", k+1, angle[k+1]); create a node for the angle tree nodetype * create_node() { nodetype * p = (nodetype *) malloc (sizeof(nodetype)); if (p == NULL) { perror("node creation error \n"); exit(1); else { for (i=0; i<2r+1; ++i) child[i] = NULL; child[r] = NULL; return p; create a node for the queue in order to BFS the angle tree qnodetype * create_qnode() { qnodetype * q = (qnodetype *) malloc (sizeof(qnodetype)); if (q == NULL) { perror("qnode creation error \n"); exit(1); else { node = NULL; next = NULL; return q; elem of depth array points to a list of nodes at the same depth qnodetype *larr[n]; void insert_level_list(nodetype *np) { int depth = np->depth; q = create_qnode(); q->node = np; q->next = larr[depth]; larr[depth] = q; void print_level_list(int depth) { q = larr[depth]; while (q) { printf(" %d %f\n", (q->node)->id, (q->node)->theta);

Archivo: /home/young/work/cordic/mvr_exhaustive.c Página 3 de 6 q = q->next; printf("\n"); nodetype * level_list_min_node(int depth) { nodetype *p; double minval = 1e100; double residue; q = larr[depth]; while (q) { residue = fabs((q->node)->theta); if (minval > residue) { minval = residue; p = q->node; q = q->next; printf("%f \n", p->theta); return(p); find min path from root to node qnodetype *minpath; void find_minpath(nodetype *p) { minpath = NULL; while (p) { q = create_qnode(); q->next = minpath; q->node = p; minpath = q; p = p->parent; void list_minpath(double a[]) { int u, i; while (q) { printf("depth=%d ", (q->node)->depth); printf("theta=%f ", (q->node)->theta); q = q->next; if (q == NULL) { printf("\n"); break; printf("branch=%d ", (q->node)->branch); if ((q->node)->branch < R) u = +1; else if ((q->node)->branch < 2*R) u = -1; else if ((q->node)->branch == 2*R) u = 0; printf("u=%d ", u); i = (q->node)->branch % R; printf("a[%d]=%f ", i, a[i]); printf("\n");

Archivo: /home/young/work/cordic/mvr_exhaustive.c Página 4 de 6 create (2R+1) children node to the current node pointed by p void expand_node(double a[], nodetype *p) { nodetype *np; int i; double ntheta, theta; static int id = 1; printf("* expanding a node... \n"); theta = p->theta; if (p->depth == 0) insert_level_list(p); if (p->branch < 0) return; for (i=0; i<2*r+1; ++i) { if (i < R) ntheta = theta + 1 * a[i%r]; else if (i < 2*R) ntheta = theta - 1 * a[i%r]; else if (i == 2*R) ntheta = theta + 0 * a[i%r]; printf("%d %f =(%f %f) \n", i, ntheta, theta, a[i%r]); np = create_node (); p->child[i] = np; np->parent = p; np->theta = ntheta; np->depth = p->depth +1; np->branch = i; np->id = id++; insert_level_list(np); if (ntheta > theta) np->branch = -1; BFS tree traversal to expand all (2R+1) nodes qnodetype *head =NULL; qnodetype *tail =NULL; void enqueue(qnodetype *q) { printf("* enqueue... \n"); if (head == NULL && tail == NULL) head = q; if (tail!= NULL) tail->next = q; tail = q; qnodetype * dequeue() { printf("* dequeue... \n"); static int depth = 0; if (head!= NULL) { q = head; if (head!= tail) head = head->next; else head = tail = NULL; if (depth!= (q->node)->depth) { printf("level %d \n", depth); depth = (q->node)->depth;

Archivo: /home/young/work/cordic/mvr_exhaustive.c Página 5 de 6 return q; else { return NULL; void tree_traverse(double a[], nodetype *p) { qnodetype *q, *nq; int i, k =0; printf("* tree traversing... \n"); q = create_qnode(); q->node = p; enqueue(q); while (head!= NULL) { printf("* node %d to be expanded \n", k); q = dequeue(); k++; if ((q->node)->depth >= N) break; if (q!= NULL) expand_node(a, q->node); for (i=0; i<2*r+1; ++i) { if ((q->node)->theta < ((q->node)->child[i])->theta) continue; if (((q->node)->child[i])->branch <0) continue; nq = create_qnode(); nq->node = (q->node)->child[i]; enqueue(nq); int main(void) { double a[n]; double angle[n+1]; double theta = 0.63761; double theta = 0.27623; double theta; = 4*atan(pow(2,-5)); int i, s; nodetype *p; nodetype *leaf; for (i=0; i<n; ++i) { a[i] = atan(1./pow(2, i)); for (s=2; s<3; ++s) { theta = s * atan(pow(2, -5)); angle[0] = theta; printf("theta= %2d * atan(pow(2,-6) = %10g \n", s, theta); conventional_cordic(a, angle); p = create_node(); p->theta = theta; p->depth = 0;

Archivo: /home/young/work/cordic/mvr_exhaustive.c Página 6 de 6 tree_traverse(a, p); for (i=0; i<n; ++i) { printf("level %d\n", i); print_level_list(i); level_list_min_node(i); leaf = level_list_min_node(n-1); find_minpath(leaf); list_minpath(a);